BUG: Fix change of type of period.sharpe

The factoring out of the Sharpe calculation changed behavior
so that both period and cumulative return nans when there is
no volatility; however before that change period returned 0.0.

This breaks existing consumers which expected a non-nan value
for period results.

Smooth out that change by checking the value after the sharpe
has been calculated and reset nan's to 0.0
This commit is contained in:
Eddie Hebert
2014-04-14 18:45:33 -04:00
parent 7cc24cec1f
commit 101baad0f8
+9
View File
@@ -112,6 +112,15 @@ class RiskMetricsPeriod(object):
self.end_date
)
self.sharpe = self.calculate_sharpe()
# The consumer currently expects a 0.0 value for sharpe in period,
# this differs from cumulative which was np.nan.
# When factoring out the sharpe_ratio, the different return types
# were collapsed into `np.nan`.
# TODO: Either fix consumer to accept `np.nan` or make the
# `sharpe_ratio` return type configurable.
# In the meantime, convert nan values to 0.0
if pd.isnull(self.sharpe):
self.sharpe = 0.0
self.sortino = self.calculate_sortino()
self.information = self.calculate_information()
self.beta, self.algorithm_covariance, self.benchmark_variance, \