From 803b58c8aafb5c8a8f327305db6b0fa36ca6776d Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Fri, 21 Mar 2014 17:22:10 -0400 Subject: [PATCH] MAINT: More precise extraction of returns from returns container. Use slice to date, `[:dt]` instead of `pd.Series.valid` to extract from returns containers. Using `valid` lead to some confusion when debugging tests, because it papers over missing data. The use of `.valid` was based on the assumption that all values from the zeroth date to the current algo date are populated, with no trailing values. `[:dt]` extracts the same data, but in a hopefully more precise and explicit fashion. --- zipline/finance/risk/cumulative.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zipline/finance/risk/cumulative.py b/zipline/finance/risk/cumulative.py index 9761cac7..66e9bb60 100644 --- a/zipline/finance/risk/cumulative.py +++ b/zipline/finance/risk/cumulative.py @@ -229,7 +229,7 @@ class RiskMetricsCumulative(object): self.latest_dt = dt self.algorithm_returns_cont[dt] = algorithm_returns - self.algorithm_returns = self.algorithm_returns_cont.valid() + self.algorithm_returns = self.algorithm_returns_cont[:dt] if self.create_first_day_stats: if len(self.algorithm_returns) == 1: @@ -243,7 +243,7 @@ class RiskMetricsCumulative(object): self.annualized_mean_returns = self.mean_returns * 252 self.benchmark_returns_cont[dt] = benchmark_returns - self.benchmark_returns = self.benchmark_returns_cont.valid() + self.benchmark_returns = self.benchmark_returns_cont[:dt] self.mean_benchmark_returns = pd.rolling_mean( self.benchmark_returns, @@ -340,7 +340,7 @@ algorithm_returns ({algo_count}) in range {start} : {end} on {dt}" dt = self.latest_dt period_label = dt.strftime("%Y-%m") rval = { - 'trading_days': len(self.algorithm_returns.valid()), + 'trading_days': len(self.algorithm_returns), 'benchmark_volatility': self.metrics.benchmark_volatility[dt], 'algo_volatility':