mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-12 11:50:11 +08:00
MAINT: Also return nan when simulation is shorter than 2 days
This commit is contained in:
@@ -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, []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user