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
130
クオンツ、マネーボール、それとQuantopian
2casa
1
240
PyconJP2018 fin-py ポスターセッション
2casa
0
160
dev.tworks_LT6.pdf
2casa
0
230
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Writing Fast Ruby
sferik
628
61k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.5k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3.1k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
500
Optimising Largest Contentful Paint
csswizardry
33
3k
Making Projects Easy
brettharned
116
6k
Music & Morning Musume
bryan
46
6.3k
How to Ace a Technical Interview
jacobian
276
23k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
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 ʹԠ༻Ͱ͖Δɻݖརམͪͷ৺͕ͳ ͘ɺσʔλऔಘͰ͖ͦ͏ͳͷͰɺͬͪ͜հͨ͠ํ͕࣮༻ੑ͕ߴ ͔ͬͨͷͰʁͱܰ͘ޙչ͍ͯ͠Δ