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
230
PyconJP2018 fin-py ポスターセッション
2casa
0
160
dev.tworks_LT6.pdf
2casa
0
230
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Scaling GitHub
holman
458
140k
Fireside Chat
paigeccino
34
3.1k
Automating Front-end Workflow
addyosmani
1366
200k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
520
Designing for humans not robots
tammielis
250
25k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Thoughts on Productivity
jonyablonski
67
4.4k
A Tale of Four Properties
chriscoyier
157
23k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
4 Signs Your Business is Dying
shpigford
181
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 ʹԠ༻Ͱ͖Δɻݖརམͪͷ৺͕ͳ ͘ɺσʔλऔಘͰ͖ͦ͏ͳͷͰɺͬͪ͜հͨ͠ํ͕࣮༻ੑ͕ߴ ͔ͬͨͷͰʁͱܰ͘ޙչ͍ͯ͠Δ