PERF: Risk-adjust returns series once before calling empyrical

This prevents empyrical from having to subtract
the risk-free rate from the returns in each
individual method.
This commit is contained in:
John Ricklefs
2016-08-26 16:16:19 -04:00
parent 85e68f0162
commit 53e5c4e113
2 changed files with 9 additions and 10 deletions
+6 -6
View File
@@ -257,6 +257,9 @@ algorithm_returns ({algo_count}) in range {start} : {end} on {dt}"
self.excess_returns[dt_loc] = (
self.algorithm_cumulative_returns[dt_loc] -
self.treasury_period_return)
risk_adj_returns = algorithm_returns_series - benchmark_returns_series
self.beta[dt_loc] = beta(
algorithm_returns_series,
benchmark_returns_series
@@ -267,16 +270,13 @@ algorithm_returns ({algo_count}) in range {start} : {end} on {dt}"
_beta=self.beta[dt_loc]
)
self.sharpe[dt_loc] = sharpe_ratio(
algorithm_returns_series,
benchmark_returns_series
risk_adj_returns
)
self.downside_risk[dt_loc] = downside_risk(
algorithm_returns_series,
benchmark_returns_series
risk_adj_returns
)
self.sortino[dt_loc] = sortino_ratio(
algorithm_returns_series,
benchmark_returns_series,
risk_adj_returns,
_downside_risk=self.downside_risk[dt_loc]
)
self.information[dt_loc] = information_ratio(
+3 -4
View File
@@ -123,13 +123,12 @@ class RiskMetricsPeriod(object):
# In the meantime, convert nan values to 0.0
if pd.isnull(self.sharpe):
self.sharpe = 0.0
risk_adj_returns = self.algorithm_returns - self.benchmark_returns
self.downside_risk = downside_risk(
self.algorithm_returns,
self.benchmark_returns
risk_adj_returns
)
self.sortino = sortino_ratio(
self.algorithm_returns,
self.benchmark_returns,
risk_adj_returns,
_downside_risk=self.downside_risk
)
self.information = information_ratio(