Accounts for negative values when creating compounded returns.

Sets the value sent to log to a value that doesn't crash out because
of negative value.
Setting the value to 0 instead.
This commit is contained in:
Eddie Hebert
2012-10-17 23:49:06 -04:00
parent b976c1252b
commit 05bb179aba
+11 -4
View File
@@ -492,13 +492,20 @@ class RiskMetricsIterative(RiskMetricsBase):
def update_compounded_log_returns(self):
if len(self.algorithm_returns) == 0:
return
elif len(self.compounded_log_returns) == 0:
self.compounded_log_returns.append(
math.log(1 + self.algorithm_returns[-1]))
try:
compound = math.log(1 + self.algorithm_returns[-1])
except ValueError:
compound = 0.0
# BUG? Shouldn't this be set to log(1.0 + 0) ?
if len(self.compounded_log_returns) == 0:
self.compounded_log_returns.append(compound)
else:
self.compounded_log_returns.append(
self.compounded_log_returns[-1] +
math.log(1 + self.algorithm_returns[-1]))
compound
)
def calculate_period_returns(self, returns):
period_returns = 1.0