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.
This commit is contained in:
Eddie Hebert
2014-03-21 17:22:10 -04:00
parent 7ce971fa17
commit 803b58c8aa
+3 -3
View File
@@ -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':