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 [1]:
bt = get_backtest('5a02a8b4fddf10449d6abf54')
100% Time: 0:00:06|###########################################################|
In [2]:
bt.create_perf_attrib_tear_sheet()
Summary Statistics
Annualized Specific Return 0.052736
Annualized Common Return 0.003112
Annualized Total Return 0.055911
Specific Sharpe Ratio 1.484037
Exposures Summary Average Risk Factor Exposure Annualized Return Cumulative Return
basic_materials 0.011623 0.004950 0.009153
consumer_cyclical -0.004177 -0.003743 -0.006897
financial_services -0.029057 -0.007752 -0.014258
real_estate -0.015384 0.011401 0.021139
consumer_defensive 0.006084 0.001133 0.002093
health_care 0.012720 0.001467 0.002709
utilities 0.001305 0.000162 0.000298
communication_services -0.000274 0.000617 0.001140
energy 0.010920 0.002102 0.003883
industrials -0.019299 0.000297 0.000548
technology 0.004676 -0.005175 -0.009528
momentum 0.062396 0.002424 0.004477
size 0.082051 -0.001733 -0.003195
value -0.030914 0.000555 0.001024
short_term_reversal -0.133818 -0.007193 -0.013232
volatility 0.065209 0.003791 0.007006

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>