zipline のカスタムデータバンドルを自作する
by
2casa
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
zipline ͷΧελϜ σʔλόϯυϧΛࣗ࡞͢Δ 2017/12/17 (Sun) Fin-py Fintech LTେձ & ձ
Slide 2
Slide 2 text
ࣗݾհ connpass/github: 2casa Twitter : @moscow_II ʻຊ৬ʼ ূ݊ձ͚ࣾσΟʔϦϯάγεςϜͷ։ൃɾاը Quantopian ͱແؔͰ͕͢ɺࣄฑڵຯ͋Γ
Slide 3
Slide 3 text
ຊͷςʔϚ • ຊגͰziplineʢQuantopianͷΦʔϓϯιʔε ൛ʣͷΧελϜσʔλόϯυϧΛ࡞ͯ͠Έ͕ͨɺ མͱ͕͍͔݀ͭ͋͘͠Γ·ͨ͠ • ͕࣌ؒগͳ͍ͷͰɺߏஙͷ֓ཁͱఔ͝ͱͷϙΠ ϯτΛ͔͍ͭ·ΜͰ͓͠·͢ • ίʔυΑΓৄࡉͳղઆޙ·ͱΊͯެ։͢Δ ༧ఆͰ͢
Slide 4
Slide 4 text
Quantopian ถࠃQuantopianࣾʹΑΔΫϥυϕʔεͷΞϧΰϦζϜτϨʔσΟϯάʢʹࣗಈചങʣڥ ΞϧΰϦζϜͷهड़ݴޠpythonɻ ڵຯ͕͋ΔํɿTokyo Quantopian User Group (connpass)
Slide 5
Slide 5 text
Quantopian ͷಛ •PROS •IDE͕͋Γɺૢ࡞ੑ͕ྑ͍ •גՁใΛແྉͰར༻Ͱ͖Δ(ͨͩ͠DLෆՄ) •CONS •ถࠃגࣜݶఆ •ݱঢ়Python2 ͷΈ
Slide 6
Slide 6 text
zipline ͬͯʁ •Quantopian ͷΦʔϓϯιʔε൛ •python3 ରԠʢਖ਼֬ʹ3.5ʣ •QuantopianͷΑ͏ͳIDEͳ͍͕ɺjupyter notebook্ Ͱಈ͔͢͜ͱͰ͖Δɻ •גՁσʔλϕʔεʢʹσʔλόϯυϧʣΛಠࣗʹߏங͢ Δ͜ͱ͕Ͱ͖Δ ຊגσʔλͰΧελϜσʔλόϯυϧΛ࡞ͬͯΈΑ͏ʂ ڥɿpython3.5 + zipline 1.1.1 (pip install -e ) ʢmacos + conda ʹΑΔԾڥʣ
Slide 7
Slide 7 text
ͬ͘͟Γߏஙखॱ 1. גՁσʔλͷௐୡͱOHLCVσʔλ࡞ 2. औҾॴใΛఆٛ 3. σʔλόϯυϧͷσʔλͷऔΓࠐΈ 4. όοΫςετΛΒͤΔ
Slide 8
Slide 8 text
1. גՁσʔλͷௐୡͱOHLCVσʔλ࡞ 2. औҾॴใΛఆٛ 3. σʔλόϯυϧͷσʔλͷऔΓࠐΈ 4. όοΫςετΛΒͤΔ OHLCVɿ̐ຊʢOpen / High / Low / Closeʣʴग़དྷߴʢVolumeʣ
Slide 9
Slide 9 text
גՁσʔλͷௐୡ JPX Data Cloud Ͱߪೖͷ߹ ౦ূגࣜશఆσʔλɿ̍ϲ݄ 1,404ԁ (ݸਓར༻) ؒɿ1,404ԁ * 12ϲ݄ = 16,848 ԁ
Slide 10
Slide 10 text
OHLCVϑΝΠϧ࡞࣌ͷ ͭ·͖ͮϙΠϯτ open, high, low, close, volume ͷϔομ໊Ͱ࡞͢Δඞཁ͕͋Δɻ ̐ຊͷج४࣌ࠁΛɺJST ͔Β UTC ʹมߋ͢Δɻมߋ͠ͳ͍ͱσʔλऔΓࠐΈ࣌ʹࣦഊ͢Δɻ Before After ݩͱͳΔλΠϜκʔϯ มઌλΠϜκʔϯ
Slide 11
Slide 11 text
1. גՁσʔλͷௐୡͱOHLCVσʔλ࡞ 2. औҾॴใΛఆٛ 3. σʔλόϯυϧͷσʔλͷऔΓࠐΈ 4. όοΫςετΛΒͤΔ
Slide 12
Slide 12 text
औҾॴใͷߏங ΧελϜΧϨϯμʔΛ৽ن࡞͢Δɻ • औҾॴجຊΫϥε • औҾॴ໊ • λΠϜκʔϯ • ཱձ͍։࢝࣌ࠁ • ཱձ͍ऴྃ࣌ࠁ • ٳใ • Ҏ֎ͷٳΛఆٛ exchange_calendar_tse.py ൈਮ
Slide 13
Slide 13 text
ٳΧϨϯμʔߏங࣌ͷ ϙΠϯτ japandas ʹ౦ূٳΧϨϯμʔ͕͋Δɻ͜ΕΛ׆༻͢Δ͜ͱͰख͕ؒল͚·͢ɻ tse_holidays.py ൈਮ japandasͷTSEHolidayCalendar ʹ ɺ1970 ʔ2030ͷ౦ূٳ ʢॕʴ࢝ʣ͕༻ҙ͞Ε͍ͯΔ
Slide 14
Slide 14 text
1. גՁσʔλͷௐୡͱOHLCVσʔλ࡞ 2. औҾॴใΛఆٛ 3. σʔλόϯυϧͷσʔλͷऔΓࠐΈ 4. όοΫςετΛΒͤΔ
Slide 15
Slide 15 text
σʔλόϯυϧͷऔΓࠐΈ “csvdir” ͱ͍͏ΧελϜσʔλόϯυϧΛ࡞͢Δπʔϧ͕༻ҙ͞Ε͍ͯΔɻ σʔλόϯυϧͷऔΓࠐΈεΫϦϓτΛɺ~/.zipline/extension.py ʹهࡌ͢Δ ΧελϜσʔλόϯυϧ࡞ πʔϧ”csvdir” Λݺͼग़͢ઃ ఆ ౦ূ༻ΧελϜΧϨϯμʔΛ ༧ΊziplineʹՃొ
Slide 16
Slide 16 text
σʔλऔΓࠐΈͷҙࣄ߲ “csvdir”ɺʢ”daily”ʣ͓Αͼʢ”minute”ʣσʔλΛΧελϜσʔλόϯυϧͱͯ͠ొ͢Δ ͜ͱ͕Ͱ͖Δ͕ɺಉ࣌ʹొ͠Α͏ͱ͢ΔͱฑͷೋॏొʹΑΔϢχʔΫΩʔ੍ҧ͕ग़Δόά ͕͋Δʢ2017/12ݱࡏʣɻ zipline ingest [-b bundle-name] Ͱ csvϑΝΠϧΛσʔλόϯυϧʹొ csvdir.py ൈਮ
Slide 17
Slide 17 text
1. גՁσʔλͷௐୡͱOHLCVσʔλ࡞ 2. औҾॴใΛఆٛ 3. σʔλόϯυϧͷσʔλͷऔΓࠐΈ 4. όοΫςετΛΒͤΔ
Slide 18
Slide 18 text
όοΫςετ(on jupyter) [όοΫςετظؒ] 2017/01/01 - 2017/01/11 [σʔλͷස] minute() 00:00 ͔ΒͰஈ͕औಘͰ͖͍ͯΔ ʢJST = UTC + 9ʣ ॕ੍ޚͷ͓͔͛Ͱ ਖ਼݄ࡾ͕ʢॕͰͳ͍͕ٳʣ ਓͷʢॕʣ ΛεΩοϓͰ͖͍ͯΔ
Slide 19
Slide 19 text
jupyter notebook্Ͱ όοΫςετ͢Δࡍͷҙ “%load_ext zipline” ͱɺ“%%zipline —start= …” ηϧΛ͚ͳ͍ͱਖ਼͘͠ಈ࡞͠ͳ͍ —trading-calendar=TSE ͷࢦఆΛΕΔͱɺΧϨϯμʔ͕NYSEʢถࠃגࣜࢢʣͱͯ͠Ξϧΰ͕ಈ ͨ͘ΊגՁσʔλ͕र͑ͳ͍ɻ ηϧΛ͚Δ —trading-calendarͷࢦఆΛΕͳ͍ όοΫςετظؒࢦఆ όοΫςετ࣌ؒ࣠ʢσϑΥϧτɿdailyʣ
Slide 20
Slide 20 text
࠷ޙʹ • ࣮ࡍʹόοΫςετΛ͢ΔͨΊʹɺ࣮͜ΕͰෆे • גׂࣜࢧ͍ͳͲͷʮݖརམͪʯʹΑΔגՁमਖ਼͕ඞཁ • csvdir ʹิਖ਼ػೳ͍͍ͭͯΔ͕ɺσʔλΛ༻ҙ͠ͳ͍ͱ͍͚ͳ͍ • खܰʹຊגͰΞϧΰϦζϜτϨʔυΛࢼ͍ͨ͠ͷͰ͋Εɺ SmartTrade ͷ QuantX ͱ͍͏αʔϏε͕͋Δʢͨͩ͠ݱঢ়ͷ Έʣɻ • ࠓճհͨ͠खॱbitcoin ʹԠ༻Ͱ͖Δɻݖརམͪͷ৺͕ͳ ͘ɺσʔλऔಘͰ͖ͦ͏ͳͷͰɺͬͪ͜հͨ͠ํ͕࣮༻ੑ͕ߴ ͔ͬͨͷͰʁͱܰ͘ޙչ͍ͯ͠Δ