Cool stuff for python backtesting package users

I have recently published the free trading strategy template that uses Python backtesting library. It lets you focus on improving your price forecasts and reduces the time and effort spent on auxiliary tasks.

Link - https://github.com/s-kust/python-backtesting-template

Understanding the Benefits of This Repo
Just like with the original Python backtesting package, you can obtain and use stats, trades, and interactive charts in HTML files. In addition, this repository solves many problems that the backtesting library does not solve.

  1. You can easily run backtests of your strategy for several (or several dozen) tickers simultaneously. The results of these backtests are combined and saved in the output.xlsx file. For details, explore files in the strategy folder.

  2. The run_backtest_for_ticker function returns not only stats and trades but also last_day_result dict. It allows you to send notifications if the trading signal is detected. For details, see the utils/strategy_exec/last_day.py file and next function.

  3. The system updates trailing stop-loss daily using the Average True Range (ATR) multiplied by 2.5. If a volatility outbreak (tr_delta high value) is detected, the stop loss is tightened. You can customize this behavior in utils/strategy_exec/stop_loss.py file.

  4. If it's possible to close half of the active position and make the remaining half risk-free, the system will do so. See the file utils/strategy_exec/partial_close.py for details. You can easily change or disable this behavior if you wish.

  5. In addition to partial closures, the system handles many other special situations. For details, see the utils/strategy_exec/special_situations.py file. You are encouraged to modify the list of special situations, change the order of their processing, and add your custom special situations.

  6. You can set the maximum duration for long and short trades. See the process_max_duration function for details.

  7. You can analyze trades in many different ways. The system adds tags to many trades that explain their fate. Each trade can contain several tags. For details, explore the add_tag_to_trades_and_close_position function code and where it is called. See also the functions add_feature_to_trades and get_stat_and_trades_for_ticker.

  8. You can optimize different parameters of your strategy. See the variable strategy_params, its filling in run_strategy_main.py and its usage in the get_desired_current_position_size function.
 
Yeah, there are few performance metrics that are missing:

1. net profit / drawdown ratio. Actually lots of traders use this ratio as performance metric because it tends to pull out strategies with the lowest drawdowns.

2. Standard deviation of returns and cumulative returns. Again, this indicates lower drawdown.
 
Back
Top