From 3ec9853b75426dd1f63247632b7421d2c1fc632e Mon Sep 17 00:00:00 2001 From: fredfortier Date: Tue, 21 Nov 2017 20:42:44 -0500 Subject: [PATCH] BUG: in relation to issue #77, catching the remaining warnings --- catalyst/exchange/asset_finder_exchange.py | 10 +++++----- catalyst/finance/risk/cumulative.py | 4 ++-- catalyst/finance/risk/period.py | 13 +++++++++++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/catalyst/exchange/asset_finder_exchange.py b/catalyst/exchange/asset_finder_exchange.py index 61a0d2c2..ceaa5d38 100644 --- a/catalyst/exchange/asset_finder_exchange.py +++ b/catalyst/exchange/asset_finder_exchange.py @@ -41,11 +41,11 @@ class AssetFinderExchange(object): SidsNotFound When a requested sid is not found and default_none=False. """ - for sid in sids: - if sid in self._asset_cache: - log.debug('got asset from cache: {}'.format(sid)) - else: - log.debug('fetching asset: {}'.format(sid)) + # for sid in sids: + # if sid in self._asset_cache: + # log.debug('got asset from cache: {}'.format(sid)) + # else: + # log.debug('fetching asset: {}'.format(sid)) return list() def lookup_symbol(self, symbol, exchange, as_of_date=None, fuzzy=False): diff --git a/catalyst/finance/risk/cumulative.py b/catalyst/finance/risk/cumulative.py index 20798f30..37bd349b 100644 --- a/catalyst/finance/risk/cumulative.py +++ b/catalyst/finance/risk/cumulative.py @@ -196,8 +196,8 @@ class RiskMetricsCumulative(object): self.benchmark_cumulative_returns[dt_loc] = cum_returns( self.benchmark_returns )[-1] - except Exception as e: - log.debug('cumulative returns error: {}'.format(e)) + except Exception: + self.benchmark_cumulative_returns[dt_loc] = 0 benchmark_cumulative_returns_to_date = \ self.benchmark_cumulative_returns[:dt_loc + 1] diff --git a/catalyst/finance/risk/period.py b/catalyst/finance/risk/period.py index 83d34ba1..283bd3c5 100644 --- a/catalyst/finance/risk/period.py +++ b/catalyst/finance/risk/period.py @@ -14,6 +14,7 @@ # limitations under the License. import functools +import warnings import logbook @@ -78,8 +79,14 @@ class RiskMetricsPeriod(object): self.calculate_metrics() def calculate_metrics(self): - self.benchmark_period_returns = \ - cum_returns(self.benchmark_returns).iloc[-1] + warnings.filterwarnings('error') + + try: + self.benchmark_period_returns = \ + cum_returns(self.benchmark_returns).iloc[-1] + except Exception: + # TODO: why is there an error + self.benchmark_period_returns = 0 self.algorithm_period_returns = \ cum_returns(self.algorithm_returns).iloc[-1] @@ -152,6 +159,8 @@ class RiskMetricsPeriod(object): self.max_drawdown = max_drawdown(self.algorithm_returns.values) self.max_leverage = self.calculate_max_leverage() + warnings.resetwarnings() + def to_dict(self): """ Creates a dictionary representing the state of the risk report.