BUG: fixed issue #77, a sortino warning prevents analyze() from completing

This commit is contained in:
fredfortier
2017-11-21 15:55:56 -05:00
parent 02dc4d6a30
commit c1d140a831
3 changed files with 22 additions and 12 deletions
+5 -3
View File
@@ -274,12 +274,14 @@ algorithm_returns ({algo_count}) in range {start} : {end} on {dt}"
)
try:
risk = self.downside_risk[dt_loc]
self.sortino[dt_loc] = sortino_ratio(
self.algorithm_returns,
_downside_risk=self.downside_risk[dt_loc]
_downside_risk=risk
)
except Exception as e:
log.debug('sortino ratio error: {}'.format(e))
except Exception:
# TODO: what causes it to error out?
self.sortino[dt_loc] = 0
self.information[dt_loc] = information_ratio(
self.algorithm_returns,
+14 -7
View File
@@ -23,7 +23,7 @@ import numpy as np
import pandas as pd
from . import risk
from . risk import check_entry
from .risk import check_entry
from empyrical import (
alpha_beta_aligned,
@@ -85,7 +85,7 @@ class RiskMetricsPeriod(object):
cum_returns(self.algorithm_returns).iloc[-1]
if not self.algorithm_returns.index.equals(
self.benchmark_returns.index
self.benchmark_returns.index
):
message = "Mismatch between benchmark_returns ({bm_count}) and \
algorithm_returns ({algo_count}) in range {start} : {end}"
@@ -128,10 +128,17 @@ class RiskMetricsPeriod(object):
self.downside_risk = downside_risk(
self.algorithm_returns.values
)
self.sortino = sortino_ratio(
self.algorithm_returns.values,
_downside_risk=self.downside_risk,
)
try:
risk = self.downside_risk
self.sortino = sortino_ratio(
self.algorithm_returns.values,
_downside_risk=risk,
)
except Exception:
# TODO: what causes it to error out?
self.sortino = 0
self.information = information_ratio(
self.algorithm_returns.values,
self.benchmark_returns.values,
@@ -141,7 +148,7 @@ class RiskMetricsPeriod(object):
self.benchmark_returns.values,
)
self.excess_return = self.algorithm_period_returns - \
self.treasury_period_return
self.treasury_period_return
self.max_drawdown = max_drawdown(self.algorithm_returns.values)
self.max_leverage = self.calculate_max_leverage()
+3 -2
View File
@@ -451,7 +451,8 @@ def run_algorithm(initialize,
exchange_name=None,
base_currency=None,
algo_namespace=None,
live_graph=False):
live_graph=False,
output=os.devnull):
"""Run a trading algorithm.
Parameters
@@ -564,7 +565,7 @@ def run_algorithm(initialize,
bundle_timestamp=bundle_timestamp,
start=start,
end=end,
output=os.devnull,
output=output,
print_algo=False,
local_namespace=False,
environ=environ,