Last week, we shipped a new feature where you can easily jump into a detailed tear sheet analysis of your backtest. On the backtest results page, you'll see a new button available:
For those already familiar with tear sheets, you can now make one at the click of a button. No more copy-pasting code or hunting around for backtest IDs! For those wondering 'what the heck is a tear sheet?', read on.
Creating a Tear Sheet
Clicking the button above will bring you to a notebook with the following cell pre-populated. The code below is all you need to get started with analyzing your backtest. It gets the ID of your backtest, loads your positions, transactions and other exhaust into an object, and then runs a series of analyses on your backtest.
Click the cell, and then press Shift + Enter to run it. Running it will emit several tables and graphs that give you insight into your backtest's performance (in Quantopian parlance, these tables and graphs are known as a 'tear sheet').
The tear sheet code is all part of pyfolio, our open source performance analysis library. Head over here if you'd like to see the code for create_full_tear_sheet
in particular. (Some changes in pyfolio haven't yet made it to the Quantopian platform, so there may be a few analyses there that aren't yet in your notebook).
Reading a Tear Sheet
The tear sheet is a great way to learn things about your backtest beyond the details available on the backtest results page. For example, my backtest had an in-sample average Sharpe of 1.44, but when I look at its rolling Sharpe in the tear sheet, I can see that my Sharpe jumped around all the way between 4 and -2:
Beta, by contrast, is much more stable:
The tear sheet provides a whole host of other metrics in addition to the ones shown above. For example, you could:
- Find out your Fama-French factor exposure
- View your most concentrated long and short positions of all time
- Track your net dollar exposure, to verify you remain hedged over the duration of the backtest
- Plot your turnover to see how actively the backtest trades
The BacktestResult
object (i.e the output of get_backtest
) also allows you to programmatically access attributes of the backtest, so you can create your own analyses outside of those that create_full_tear_sheet
provides. For example, with the code cell above, you could run bt.positions
to get a pandas DataFrame of your positions over time. The full list of attributes you can access is available here. You can also run individual analyses, if you don't want to get the entire tear sheet in one go - check out the pyfolio docs for more details, or take a look at this notebook for even more things you can do with pyfolio.
One thing that is important to note is that all the metrics provided in the tear sheet are in-sample. It's good to look at them, but be careful of over-optimizing! Overfit backtests can have disappointing out-of-sample results, which can hurt an algorithm's chances of winning the contest or getting an allocation.