Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
zipline のカスタムデータバンドルを自作する
Search
2casa
December 17, 2017
3
1.5k
zipline のカスタムデータバンドルを自作する
Quantopianが主導して開発しているpythonベースのアルゴリズムトレーディングライブラリであるziplineに、日本株の株価データを取り込む際の工程とポイントをかいつまんで紹介。
2casa
December 17, 2017
Tweet
Share
More Decks by 2casa
See All by 2casa
20191024_LT.pdf
2casa
0
120
クオンツ、マネーボール、それとQuantopian
2casa
1
230
PyconJP2018 fin-py ポスターセッション
2casa
0
160
dev.tworks_LT6.pdf
2casa
0
230
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
What's in a price? How to price your products and services
michaelherold
243
12k
Done Done
chrislema
181
16k
Site-Speed That Sticks
csswizardry
0
28
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Why Our Code Smells
bkeepers
PRO
334
57k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
How STYLIGHT went responsive
nonsquared
95
5.2k
The Invisible Side of Design
smashingmag
298
50k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Making Projects Easy
brettharned
115
5.9k
Transcript
zipline ͷΧελϜ σʔλόϯυϧΛࣗ࡞͢Δ 2017/12/17 (Sun) Fin-py Fintech LTେձ & ձ
ࣗݾհ connpass/github: 2casa Twitter : @moscow_II ʻຊ৬ʼ ূ݊ձ͚ࣾσΟʔϦϯάγεςϜͷ։ൃɾاը Quantopian ͱແؔͰ͕͢ɺࣄฑڵຯ͋Γ
ຊͷςʔϚ • ຊגͰziplineʢQuantopianͷΦʔϓϯιʔε ൛ʣͷΧελϜσʔλόϯυϧΛ࡞ͯ͠Έ͕ͨɺ མͱ͕͍͔݀ͭ͋͘͠Γ·ͨ͠ • ͕࣌ؒগͳ͍ͷͰɺߏஙͷ֓ཁͱఔ͝ͱͷϙΠ ϯτΛ͔͍ͭ·ΜͰ͓͠·͢ • ίʔυΑΓৄࡉͳղઆޙ·ͱΊͯެ։͢Δ
༧ఆͰ͢
Quantopian ถࠃQuantopianࣾʹΑΔΫϥυϕʔεͷΞϧΰϦζϜτϨʔσΟϯάʢʹࣗಈചങʣڥ ΞϧΰϦζϜͷهड़ݴޠpythonɻ ڵຯ͕͋ΔํɿTokyo Quantopian User Group (connpass)
Quantopian ͷಛ •PROS •IDE͕͋Γɺૢ࡞ੑ͕ྑ͍ •גՁใΛແྉͰར༻Ͱ͖Δ(ͨͩ͠DLෆՄ) •CONS •ถࠃגࣜݶఆ •ݱঢ়Python2 ͷΈ
zipline ͬͯʁ •Quantopian ͷΦʔϓϯιʔε൛ •python3 ରԠʢਖ਼֬ʹ3.5ʣ •QuantopianͷΑ͏ͳIDEͳ͍͕ɺjupyter notebook্ Ͱಈ͔͢͜ͱͰ͖Δɻ •גՁσʔλϕʔεʢʹσʔλόϯυϧʣΛಠࣗʹߏங͢
Δ͜ͱ͕Ͱ͖Δ ຊגσʔλͰΧελϜσʔλόϯυϧΛ࡞ͬͯΈΑ͏ʂ ڥɿpython3.5 + zipline 1.1.1 (pip install -e <path>) ʢmacos + conda ʹΑΔԾڥʣ
ͬ͘͟Γߏஙखॱ 1. גՁσʔλͷௐୡͱOHLCVσʔλ࡞ 2. औҾॴใΛఆٛ 3. σʔλόϯυϧͷσʔλͷऔΓࠐΈ 4. όοΫςετΛΒͤΔ
1. גՁσʔλͷௐୡͱOHLCVσʔλ࡞ 2. औҾॴใΛఆٛ 3. σʔλόϯυϧͷσʔλͷऔΓࠐΈ 4. όοΫςετΛΒͤΔ OHLCVɿ̐ຊʢOpen /
High / Low / Closeʣʴग़དྷߴʢVolumeʣ
גՁσʔλͷௐୡ JPX Data Cloud Ͱߪೖͷ߹ ౦ূגࣜશఆσʔλɿ̍ϲ݄ 1,404ԁ (ݸਓར༻) ؒɿ1,404ԁ *
12ϲ݄ = 16,848 ԁ
OHLCVϑΝΠϧ࡞࣌ͷ ͭ·͖ͮϙΠϯτ open, high, low, close, volume ͷϔομ໊Ͱ࡞͢Δඞཁ͕͋Δɻ ̐ຊͷج४࣌ࠁΛɺJST ͔Β
UTC ʹมߋ͢Δɻมߋ͠ͳ͍ͱσʔλऔΓࠐΈ࣌ʹࣦഊ͢Δɻ Before After ݩͱͳΔλΠϜκʔϯ มઌλΠϜκʔϯ
1. גՁσʔλͷௐୡͱOHLCVσʔλ࡞ 2. औҾॴใΛఆٛ 3. σʔλόϯυϧͷσʔλͷऔΓࠐΈ 4. όοΫςετΛΒͤΔ
औҾॴใͷߏங ΧελϜΧϨϯμʔΛ৽ن࡞͢Δɻ • औҾॴجຊΫϥε • औҾॴ໊ • λΠϜκʔϯ • ཱձ͍։࢝࣌ࠁ
• ཱձ͍ऴྃ࣌ࠁ • ٳใ • Ҏ֎ͷٳΛఆٛ exchange_calendar_tse.py ൈਮ
ٳΧϨϯμʔߏங࣌ͷ ϙΠϯτ japandas ʹ౦ূٳΧϨϯμʔ͕͋Δɻ͜ΕΛ׆༻͢Δ͜ͱͰख͕ؒল͚·͢ɻ tse_holidays.py ൈਮ japandasͷTSEHolidayCalendar ʹ ɺ1970 ʔ2030ͷ౦ূٳ
ʢॕʴ࢝ʣ͕༻ҙ͞Ε͍ͯΔ
1. גՁσʔλͷௐୡͱOHLCVσʔλ࡞ 2. औҾॴใΛఆٛ 3. σʔλόϯυϧͷσʔλͷऔΓࠐΈ 4. όοΫςετΛΒͤΔ
σʔλόϯυϧͷऔΓࠐΈ “csvdir” ͱ͍͏ΧελϜσʔλόϯυϧΛ࡞͢Δπʔϧ͕༻ҙ͞Ε͍ͯΔɻ σʔλόϯυϧͷऔΓࠐΈεΫϦϓτΛɺ~/.zipline/extension.py ʹهࡌ͢Δ ΧελϜσʔλόϯυϧ࡞ πʔϧ”csvdir” Λݺͼग़͢ઃ ఆ ౦ূ༻ΧελϜΧϨϯμʔΛ
༧ΊziplineʹՃొ
σʔλऔΓࠐΈͷҙࣄ߲ “csvdir”ɺʢ”daily”ʣ͓Αͼʢ”minute”ʣσʔλΛΧελϜσʔλόϯυϧͱͯ͠ొ͢Δ ͜ͱ͕Ͱ͖Δ͕ɺಉ࣌ʹొ͠Α͏ͱ͢ΔͱฑͷೋॏొʹΑΔϢχʔΫΩʔ੍ҧ͕ग़Δόά ͕͋Δʢ2017/12ݱࡏʣɻ zipline ingest [-b bundle-name] Ͱ csvϑΝΠϧΛσʔλόϯυϧʹొ
csvdir.py ൈਮ
1. גՁσʔλͷௐୡͱOHLCVσʔλ࡞ 2. औҾॴใΛఆٛ 3. σʔλόϯυϧͷσʔλͷऔΓࠐΈ 4. όοΫςετΛΒͤΔ
όοΫςετ(on jupyter) [όοΫςετظؒ] 2017/01/01 - 2017/01/11 [σʔλͷස] minute() 00:00 ͔ΒͰஈ͕औಘͰ͖͍ͯΔ
ʢJST = UTC + 9ʣ ॕ੍ޚͷ͓͔͛Ͱ ਖ਼݄ࡾ͕ʢॕͰͳ͍͕ٳʣ ਓͷʢॕʣ ΛεΩοϓͰ͖͍ͯΔ
jupyter notebook্Ͱ όοΫςετ͢Δࡍͷҙ “%load_ext zipline” ͱɺ“%%zipline —start= …” ηϧΛ͚ͳ͍ͱਖ਼͘͠ಈ࡞͠ͳ͍ —trading-calendar=TSE
ͷࢦఆΛΕΔͱɺΧϨϯμʔ͕NYSEʢถࠃגࣜࢢʣͱͯ͠Ξϧΰ͕ಈ ͨ͘ΊגՁσʔλ͕र͑ͳ͍ɻ ηϧΛ͚Δ —trading-calendarͷࢦఆΛΕͳ͍ όοΫςετظؒࢦఆ όοΫςετ࣌ؒ࣠ʢσϑΥϧτɿdailyʣ
࠷ޙʹ • ࣮ࡍʹόοΫςετΛ͢ΔͨΊʹɺ࣮͜ΕͰෆे • גׂࣜࢧ͍ͳͲͷʮݖརམͪʯʹΑΔגՁमਖ਼͕ඞཁ • csvdir ʹิਖ਼ػೳ͍͍ͭͯΔ͕ɺσʔλΛ༻ҙ͠ͳ͍ͱ͍͚ͳ͍ • खܰʹຊגͰΞϧΰϦζϜτϨʔυΛࢼ͍ͨ͠ͷͰ͋Εɺ
SmartTrade ͷ QuantX ͱ͍͏αʔϏε͕͋Δʢͨͩ͠ݱঢ়ͷ Έʣɻ • ࠓճհͨ͠खॱbitcoin ʹԠ༻Ͱ͖Δɻݖརམͪͷ৺͕ͳ ͘ɺσʔλऔಘͰ͖ͦ͏ͳͷͰɺͬͪ͜հͨ͠ํ͕࣮༻ੑ͕ߴ ͔ͬͨͷͰʁͱܰ͘ޙչ͍ͯ͠Δ