Performance Attribution¶
The module empyrical.perf_attrib
facilitates the attribution of performance to various risk factors.

empyrical.perf_attrib.
compute_exposures
(positions, factor_loadings)¶ Compute daily risk factor exposures.
 Parameters
 positions: pd.Series
A series of holdings as percentages indexed by date and ticker.  Examples:
dt ticker 20170101 AAPL 0.417582
TLT 0.010989 XOM 0.571429
 20170102 AAPL 0.202381
TLT 0.535714 XOM 0.261905
 factor_loadingspd.DataFrame
Factor loadings for all days in the date range, with date and ticker as index, and factors as columns.  Example:
momentum reversal
dt ticker 20170101 AAPL 1.592914 0.852830
TLT 0.184864 0.895534 XOM 0.993160 1.149353
 20170102 AAPL 0.140009 0.524952
TLT 1.066978 0.185435 XOM 1.798401 0.761549
 Returns
 risk_exposures_portfoliopd.DataFrame
df indexed by datetime, with factors as columns  Example:
momentum reversal
dt 20170101 0.238655 0.077123 20170102 0.821872 1.520515

empyrical.perf_attrib.
perf_attrib
(returns, positions, factor_returns, factor_loadings)¶ Attributes the performance of a returns stream to a set of risk factors.
Performance attribution determines how much each risk factor, e.g., momentum, the technology sector, etc., contributed to total returns, as well as the daily exposure to each of the risk factors. The returns that can be attributed to one of the given risk factors are the common_returns, and the returns that _cannot_ be attributed to a risk factor are the specific_returns. The common_returns and specific_returns summed together will always equal the total returns.
 Parameters
 returnspd.Series
Returns for each day in the date range.  Example:
20170101 0.017098 20170102 0.002683 20170103 0.008669
 positions: pd.Series
Daily holdings in percentages, indexed by date.  Examples:
dt ticker 20170101 AAPL 0.417582
TLT 0.010989 XOM 0.571429
 20170102 AAPL 0.202381
TLT 0.535714 XOM 0.261905
 factor_returnspd.DataFrame
Returns by factor, with date as index and factors as columns  Example:
momentum reversal
20170101 0.002779 0.005453 20170102 0.001096 0.010290
 factor_loadingspd.DataFrame
Factor loadings for all days in the date range, with date and ticker as index, and factors as columns.  Example:
momentum reversal
dt ticker 20170101 AAPL 1.592914 0.852830
TLT 0.184864 0.895534 XOM 0.993160 1.149353
 20170102 AAPL 0.140009 0.524952
TLT 1.066978 0.185435 XOM 1.798401 0.761549
 Returns
 tuple of (risk_exposures_portfolio, perf_attribution)
 risk_exposures_portfoliopd.DataFrame
df indexed by datetime, with factors as columns  Example:
momentum reversal
dt 20170101 0.238655 0.077123 20170102 0.821872 1.520515
 perf_attributionpd.DataFrame
df with factors, common returns, and specific returns as columns, and datetimes as index  Example:
momentum reversal common_returns specific_returns
dt 20170101 0.249087 0.935925 1.185012 1.185012 20170102 0.003194 0.400786 0.403980 0.403980