Skip to content

abhi1010/backtrader-strategies-compendium

Repository files navigation

backtrader

Backtesting program

How to use it?

python backtest.py -s golden_cross > logs/golden_cross.log
python backtest.py -s buy_hold > logs/buy_hold.log
python backtest.py -s buy_dip > logs/buy_dip.log
python backtest.py -s ichimoku > logs/ichimoku.log
python backtest.py -s bbands > logs/bbands.log
python backtest.py -s mean_reversion > logs/mean_reversion.log
                    # Gap Up/Down check below

# Full command
python backtest.py --strategy gap --symbol ^NSEI --report --analysis

Special params

NSE Gap Up Down Strategy

python backtest.py -s gap --symbol ^NSEI --cheat-on-open -i 1m

Help


optional arguments:
  -h, --help            show this help message and exit
  --fromyear FROMYEAR, -f FROMYEAR
                        Starting date in YYYY format
  --toyear TOYEAR, -t TOYEAR
                        Starting date in YYYY format
  --analysis, -a        Print nice analysis summary
  --writercsv, -wcsv    Tell the writer to produce a csv stream
  --report, -r          Produce a yaml report
  --cash CASH           Starting Cash
  --comm COMM           Commission for operation
  --plot, -p            Plot the read data
  --transactions, -tx   All transactions
  -sym SYMBOLS [SYMBOLS ...], --symbols SYMBOLS [SYMBOLS ...]
                        <Required> Set flag
  -s STRATEGY, --strategy STRATEGY
                        which strategy to run

Download data?

Everything goes into data_yahoo dir.

# a single symbol, defaults
# Saves daily and monthly by default
python api-yahoo.py -s AAPL -i 1d

# multiple symbols
python api-yahoo.py -s AAPL TSLA

# Change the interval to 1m
# Many a times only last 7-8 days data is available. So need to run cron jobs regularly
python api-yahoo.py -s AAPL ^NSEI -i 1m

Reference Repositories

Next Level

bt - Flexible Backtesting for Python — bt 0.2.9 documentation: Taking quant to the next level after backtrader

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published