MAINT: Also return nan when simulation is shorter than 2 days

This commit is contained in:
Richard Frank
2015-11-19 09:36:56 -05:00
parent f4cf30dd19
commit 34a842c052
+4 -2
View File
@@ -252,14 +252,16 @@ class RiskMetricsPeriod(object):
http://en.wikipedia.org/wiki/Beta_(finance)
"""
# it doesn't make much sense to calculate beta for less than two days,
# so return none.
# so return nan.
if len(self.algorithm_returns) < 2:
return 0.0, 0.0, 0.0, 0.0, []
return np.nan, np.nan, np.nan, np.nan, []
returns_matrix = np.vstack([self.algorithm_returns,
self.benchmark_returns])
C = np.cov(returns_matrix, ddof=1)
# If there are missing benchmark values, then we can't calculate the
# beta.
if not np.isfinite(C).all():
return np.nan, np.nan, np.nan, np.nan, []