Notebook

Performance Attribution

With the release of Quantopian's Risk Model you can analyze your algorithm's performance in more depth. Pyfolio now includes a performance attribution tear sheet that breaks down your algorithm's returns into common and specific returns.

Let's load a backtest to look at an example:

In [2]:
bt = get_backtest('5a03c44d141dad41a8f991a2')
100% Time: 0:00:01|###########################################################|
In [3]:
bt.create_perf_attrib_tear_sheet()
Summary Statistics
Annualized Specific Return 0.039745
Annualized Common Return 0.091558
Annualized Total Return 0.137705
Specific Sharpe Ratio 0.471219
Exposures Summary Average Risk Factor Exposure Annualized Return Cumulative Return
basic_materials 0.000000 0.000000 0.000000
consumer_cyclical 0.000000 0.000000 0.000000
financial_services 0.000000 0.000000 0.000000
real_estate 0.000000 0.000000 0.000000
consumer_defensive 0.000000 0.000000 0.000000
health_care 0.000000 0.000000 0.000000
utilities 0.000000 0.000000 0.000000
communication_services 0.000000 0.000000 0.000000
energy 0.500077 0.031306 0.064243
industrials 0.000000 0.000000 0.000000
technology 0.578399 0.128113 0.275686
momentum -0.034355 0.010379 0.021075
size 1.915217 -0.070097 -0.136526
value -0.278693 0.000477 0.000964
short_term_reversal -0.130549 0.000284 0.000574
volatility -0.321833 0.000078 0.000158

This is how the tear sheet is broken down:

Summary Statistics - This table provides the annualized returns breakdown over the entire backtest, as well as a Sharpe ratio derived from the specific returns of the backtest.

Exposures Summary - This table gives us the average exposure of our algorithm to each risk factor. It also gives us the annualized and cumulative returns that are explained by each one of these risk factors.

Time Series of Cumulative Returns - This plot breaks down the results of our backtest into cumulative specific and common returns. Common returns are the portion of our backtest's returns that are attributed to common risk factors. Specific returns are the residual, and is what we commonly refer to as alpha.

Daily Returns Attribution - This plot attributes the daily returns to each of the common risk factors. It also includes daily specific returns.

Daily Risk Factor Exposures - This plot shows the daily exposures to each common risk factor.

Exposure to Individual Risk Factors

We can also get our returns' exposure to individual risk factors and plot them as follows:

In [3]:
bt.factor_exposures['short_term_reversal'].plot()
Out[3]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f8d27bb3190>

... and the corresponding returns attributed to a given risk factor:

In [4]:
bt.attributed_factor_returns['short_term_reversal'].plot()
Out[4]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f8d1dd02790>

If you’d like to learn more about risk models and how to use them in your research and portfolio construction, check out our Risk Constrained Portfolio Optimization lecture.