From 7f724a969678a239e60b0c4f36bbd93b07ed3595 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 26 Feb 2014 20:46:58 -0500 Subject: [PATCH] ENH: Provide all drawdowns and max drawdowns in cumulative risk. The values are not part of the risk report, but can be useful for examining the behavior of the drawdown calculations. --- zipline/finance/risk/cumulative.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/zipline/finance/risk/cumulative.py b/zipline/finance/risk/cumulative.py index 4c832543..576db84c 100644 --- a/zipline/finance/risk/cumulative.py +++ b/zipline/finance/risk/cumulative.py @@ -200,6 +200,8 @@ class RiskMetricsCumulative(object): self.metrics = pd.DataFrame(index=cont_index, columns=self.METRIC_NAMES) + self.drawdowns = pd.Series(index=cont_index) + self.max_drawdowns = pd.Series(index=cont_index) self.max_drawdown = 0 self.current_max = -np.inf self.daily_treasury = pd.Series(index=self.trading_days) @@ -318,6 +320,7 @@ algorithm_returns ({algo_count}) in range {start} : {end} on {dt}" self.metrics.sortino[dt] = self.calculate_sortino() self.metrics.information[dt] = self.calculate_information() self.max_drawdown = self.calculate_max_drawdown() + self.max_drawdowns[dt] = self.max_drawdown if self.create_first_day_stats: # Remove placeholder 0 return @@ -410,6 +413,8 @@ algorithm_returns ({algo_count}) in range {start} : {end} on {dt}" self.compounded_log_returns[self.latest_dt] - self.current_max) + self.drawdowns[self.latest_dt] = cur_drawdown + if self.max_drawdown < cur_drawdown: return cur_drawdown else: