The backtesting tool base on backtrader framework.
python download_data.py -s "SPY" -o "./datas"
-s (default = "SPY") stock / index symbol
-o (default = "./datas") output folder path
-l (default = "DEBUG") log level
python main_martingale.py -t -1 -d "./datas/SPY.csv"
-d (default = "./datas/SPY.csv") test data path
-o (default = "./result.json") output data path
-from (default = "1999-01-01") backtesting data start date
-to (default = "2021-12-31") backtesting data end date
-plot (default = "1") plot the backtesting grpah ("1": enable; other: disable)
-t (default = "1") strategy type ("1": Martingale; "-1": Anti-Martingale)
-p (default = "252") the period of highest / lowest for strategy threshold
-s (default = "0.05") position size per trade
-e (default = "0.05") position error for stragtegy threshold (sensitivity)
-mpl (default = {built-in}) martingale strategy threshold line list ({threshold},{position},{color}; e.g. "0,0.2,#29b6f6;0.05,0.4,#03a9f4")
-l (default = "INFO") log level
| Symbol-Strategy | Cumulative Return | Draw Down | Sharp Ratio |
|---|---|---|---|
| SPY-All-In | 395.28% | 54.73% | 0.455 |
| SPY-Martingale | 125.86% | 48.81% | 0.290 |
| SPY-AntiMartingale | 343.10% | 37.79% | 0.475 |
| QQQ-All-In | 318.64% | 82.17% | 0.344 |
| QQQ-Martingale | 49.53% | 79.59% | 0.153 |
| QQQ-AntiMartingale | 312.82% | 73.30% | 0.346 |
| INTC-All-In | 87.74% | 81.54% | 0.206 |
| INTC-Martingale | 130.36% | 74.90% | 0.233 |
| INTC-AntiMartingale | 3.79% | 81.76% | 0.111 |
| C-All-In | -75.55% | 97.90% | 0.009 |
| C-Martingale | -67.67% | 97.49% | 0.005 |
| C-AntiMartingale | -64.99% | 95.15% | 0.005 |
- go to /Lib/site-packages/backtrader/plot/locator.py
- replace code as follows
to
from matplotlib.dates import (HOURS_PER_DAY, MIN_PER_HOUR, SEC_PER_MIN, MONTHS_PER_YEAR, DAYS_PER_WEEK, SEC_PER_HOUR, SEC_PER_DAY, num2date, rrulewrapper, YearLocator, MicrosecondLocator, warnings)from matplotlib.dates import (HOURS_PER_DAY, MIN_PER_HOUR, SEC_PER_MIN, MONTHS_PER_YEAR, DAYS_PER_WEEK, SEC_PER_HOUR, SEC_PER_DAY, num2date, rrulewrapper, YearLocator, MicrosecondLocator) import warnings
This project is licensed under the terms of the MIT license.

