mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-07 17:47:24 +08:00
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:
+11
-4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user