ðªšããã¯ãã¹ããšã¯
ãã¬ãŒãã«ããããšããžããããã©ãããæ€èšŒããðã·ãã¥ã¬ãŒã·ã§ã³ã§ã®ä»®èª¬æ€èšŒ.
ããã¯ãã¹ã (Back Test) ãšã¯, ã·ã¹ãã ãã¬ãŒããªã©ãå©çšããå Žåã«ããã°ã©ã ãªã©ãå©çšããŠåœè©²ã¹ãã©ããžãŒãéå»ã®çºæ¿ã¬ãŒããæ ªäŸ¡ãªã©ã«åœãŠã¯ããå Žåã«ã©ã®ãããªåããããã®ãããã§ãã¯ãããã¹ãã®ããš.
ããã¯ãã¹ãã«ã¯2çš®é¡ãã.
- éå»ã®ãã¹ããªã«ã«ããŒã¿ã®ã·ãã¥ã¬ãŒã·ã§ã³.
- éå»ã«çºçããªãã£ãäºè±¡ã®ã·ãã¥ã¬ãŒã·ã§ã³.
ðãŠã©ãŒã¯ãã©ã¯ãŒãæ³
ãŠã©ãŒã¯ãã©ã¯ãŒã(Warl-Forward, WF)æ³.
æè³æŠç¥ãéå»ã«ã©ã®ããã«æ¯ãèã£ãããã·ãã¥ã¬ãŒãããæ¹æ³. ããã¯ãã¹ããšãããšäžè¬çã«ãããæãããšãå€ã.
ðãã©ã¯ãŒããã¹ã
ãã¬ãŒãã«ããããšããžããããã©ãããæ€èšŒãã, æ¬çªç°å¢ã§ã®ä»®èª¬æ€èšŒ.
ããŒããŒãã¹ã(Paper Trading), ããã³ãã©ã³ãšããã.
ããã¯ãã¹ãçš®å¥
ãã¯ãã«åããã¯ãã¹ããšã€ãã³ãããŒã¹ããã¯ãã¹ãããã.
ðãã¯ãã«åããã¯ãã¹ã
Vectorised Backtest. çŽå®å±¥æŽçãé åïŒãã¯ãã«ïŒã«å ¥ããŠäžæ¬åŠçãã. ã€ã¡ãŒãžãšããŠã¯è¡šã®åãè¿œå ããŠããæã. ããŒã¿ãµã€ãšã³ã¹çã«ããŒã¿ãã¬ãŒã ãåŠçããŠãã.
pros
- ã€ã³ã¿ã©ã¯ãã£ãã§æ¢çŽ¢çãªæŠç¥ã®æ€èšŒ.
- èšç®ãéã(!=é次èšç®).
- å¯èŠåããããã.
cons
ã³ã³ããã¹ããä¿æããã®ãé£ãã. ããããšãããš, éäžèšç®ããã©ã°ãåã§è¿œå ãã. ãã ã, ããã¯åçŽãªããžãã¯ãªãã°ããããã©ãè€éãªããžãã¯ã«ãªããšé£ãã.
ãããã€ãã³ãããŒã¹ããã¯ãã¹ãã«ãªããš, loopãåããªããç¶æ ãæŽæ°ãããããªåŠçã§ã§ãã.
ãã¯ãã«æŒç®ã掻çšãã
ãã¯ãã«å, èšãæãããšðDataframeã©ã€ãã©ãªã掻çšããããšã«ããå©ç¹ã¯, ãã¯ãã«æŒç®ã«ãã. åºæ¬çã«å(Series)ã§æŒç®ãããããããšããããã€ã³ã. ããã¯æ £ããå¿ èŠ.
ããã«ã¯åæŒç®ã®ããã®Utilã掻çšãã. èªåå®è£ ã¯ãã€ãâŠ
- shift: æ°åãããã.
- cumsum, cumprod: 环ç©èšç®.
- èªåã§ãããšaccumulatorã®ãããªãã®ã§èšç®çµæãä¿æãã€ã€èšç®ããå¿ èŠããã.
- èãæ¹ãšããŠã¯, cumsumãcumprodãšãã©ã°å¶åŸ¡(ture/falseãšã0, 1, -1)ãé§äœ¿ããŠèšç®çšã®åã掻çšããŠã€ã€åŠçãã.
References
ðã€ãã³ãããŒã¹ããã¯ãã¹ã
Event-Based, Event-Driven Backtesting.
ã€ãã³ããé次åŠçãã. ã«ãŒããåããŠé次çã«çµæãè©äŸ¡ããã€ã¡ãŒãž.
ã€ã³ããããšããŠã®ðããŒ(Bar)ãã©ãããããšããããšãèŠæ¥µã. barãšã¯ããæç¹ã§ãµã³ããªã³ã°ããããŒã¿ã»ãã.
stepé¢æ°ãåŒã°ããé¡ã®ãã®ã¯ã€ãã³ãããŒã¹ããã¯ãã¹ãã®ãã©ãã€ã äžã«ãã.
Resources
- ð§backtesting.py
- ðTradingView
- Event-Driven Backtesting with Python - Part I | QuantStart
- æãåºæ·±ãèšäº. OANDAã®ã·ã¹ãã ãã¬ãŒããPythonã§ããããšãããšã, ãã®è±èªã®èšäºãããããåèã«ãªãæ å ±æºããªãã£ãã®ã§èªã¿èŸŒãã .
- https://github.com/tobiasbrodd/backtester
ããã¯ãã¹ãææš
ããã¯ãã¹ãã§æ±ãçµ±èšé.
Cumulative returns
环ç©ãªã¿ãŒã³.
Sharpe ratio
Refs
ããŒã«
ð§backtesting.py
ãšãŠãæåãªPythonã©ã€ãã©ãª.
https://kernc.github.io/backtesting.py/
ããã¯ãã¹ãæ€èšŒãµãŒãã¹
Topics
ð¡ããã¯ãã¹ãã§ã®ããããµã€ãºã®æ±ºå®
Insights
ð€ãã¯ãã«åããã¯ãã¹ãã¯ã³ã³ããã¹ãã䌎ãæŠç¥ã®å®è£ ãé£ãã
ããæå»ã«ãããæ¡ä»¶ã§æè³å€æããããªãã°ãã¯ãã«åããã¯ãã¹ãã¯å®¹æ. è¡ãèŠãã°ããã ããªã®ã§.
åé¡ã¯éå»ã®ããæç¹ã®æ¡ä»¶ãããšã«çŸåšã®æè³å€æãããå Žå. ããšãã°ã·ã°ãã«Xãç«ã£ãããšã«ã·ã°ãã«Yã§ãšã³ããªã¿ãããª. ããžã·ã§ã³ç®¡çãåã. ããæç¹ã§ã®ããžã·ã§ã³ãåèã«æ¬¡ã決ããã¿ãããª.
ã€ãã³ãããŒã¹ããã¯ãã¹ããªãã°èšç®çµæãç¶æ ä¿æããªããé次èšç®. ãã¯ãã«åããã¯ãã¹ããå¿ èŠãªåã ãé次èšç®ããããšã«ãªã. loopãåããreducerã䜿ãã, ãããã«ããèšç®çµæã®accumulateãããçµæã®ãªã¹ããã¢ãŠããããã®åã«ãªã.