Backtest

This document explains quanttrader backtest framework and code structure.

This repository contains examples of some classical strategies and their Sharpe ratios, as well as grid-search based parameter optimization. The backtest is designed to be working together with the pyfolio library.

One distinctive design in backtest is that it fills market order right away instead of filling against tomorrow’s open price. After all, in the daily bar setting, it is better to send out order at 15:59:59 than waiting overnight for next day’ open. If you disagree, simply save the market order similar to limit or stop order in the BacktestBrokerage class and then fill it on next tick.

Currently backtest accepts three data feeds.

  • Daily bar or intraday bar from Yahoo Finance. See here for how to download.
  • Historical intraday bar from Interactive Brokers. Use this script to download.
  • Live tick recorded from live trading session. This video demonstrates how to do it in live session.

It is possible to load your own data source by following the above examples.