From b53da8d4b3c78bd07bafc2752a2e78982335d5ca Mon Sep 17 00:00:00 2001 From: fawce Date: Tue, 7 May 2013 18:45:35 -0400 Subject: [PATCH] MAINT: Refactor check_entry method to also look at np.inf Also, make the method a module function. --- zipline/finance/risk.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/zipline/finance/risk.py b/zipline/finance/risk.py index 048c7547..355ac845 100644 --- a/zipline/finance/risk.py +++ b/zipline/finance/risk.py @@ -78,6 +78,15 @@ TREASURY_DURATIONS = [ ] +# check if a field in rval is nan, and replace it with +# None. +def check_entry(key, value): + if key != 'period_label': + return np.isnan(value) or np.isinf(value) + else: + return False + + ############################ # Risk Metric Calculations # ############################ @@ -378,14 +387,6 @@ class RiskMetricsBase(object): 'period_label': period_label } - # check if a field in rval is nan, and replace it with - # None. - def check_entry(key, value): - if key != 'period_label': - return np.isnan(value) - else: - return False - return {k: None if check_entry(k, v) else v for k, v in rval.iteritems()} @@ -703,14 +704,6 @@ algorithm_returns ({algo_count}) in range {start} : {end} on {dt}" rval['sortino'] = 0.0 rval['information'] = 0.0 - # check if a field in rval is nan, and replace it with - # None. - def check_entry(key, value): - if key != 'period_label': - return np.isnan(value) - else: - return False - return {k: None if check_entry(k, v) else v for k, v in rval.iteritems()}