MAINT: Refactor check_entry method to also look at np.inf

Also, make the method a module function.
This commit is contained in:
fawce
2013-05-07 18:45:35 -04:00
committed by Eddie Hebert
parent 5c883659b5
commit b53da8d4b3
+9 -16
View File
@@ -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()}