diff --git a/zipline/finance/risk/cumulative.py b/zipline/finance/risk/cumulative.py index c2703379..943ba4a9 100644 --- a/zipline/finance/risk/cumulative.py +++ b/zipline/finance/risk/cumulative.py @@ -194,7 +194,7 @@ class RiskMetricsCumulative(object): # Create container for all minutes on first iteration trading_minutes = minutes_for_day else: - trading_minutes = trading_minutes + minutes_for_day + trading_minutes = trading_minutes.union(minutes_for_day) return trading_minutes def get_daily_index(self): @@ -462,16 +462,17 @@ algorithm_returns ({algo_count}) in range {start} : {end} on {dt}" http://en.wikipedia.org/wiki/Beta_(finance) """ - # it doesn't make much sense to calculate beta for less than two days, - # so return none. - if len(self.annualized_mean_returns) < 2: - return 0.0 # Drop nans if there are gaps in the data algorithm_returns = self.algorithm_returns.dropna() benchmark_returns = \ self.benchmark_returns.loc[algorithm_returns.index] + # it doesn't make much sense to calculate beta for less than two days, + # so return none. + if len(algorithm_returns) < 2: + return 0.0 + returns_matrix = np.vstack([algorithm_returns, benchmark_returns]) C = np.cov(returns_matrix, ddof=1) diff --git a/zipline/history/history_container.py b/zipline/history/history_container.py index 35860d23..8fc19b62 100644 --- a/zipline/history/history_container.py +++ b/zipline/history/history_container.py @@ -535,7 +535,7 @@ class HistoryContainer(object): Add new sids to the container. """ self.sids = pd.Index( - sorted(self.sids + _ensure_index(to_add)), + sorted(self.sids.union(_ensure_index(to_add))), ) self._realign_sids() @@ -544,7 +544,7 @@ class HistoryContainer(object): Remove sids from the container. """ self.sids = pd.Index( - sorted(self.sids - _ensure_index(to_drop)), + sorted(self.sids.difference(_ensure_index(to_drop))), ) self._realign_sids()