mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-03 10:34:22 +08:00
BUG: fixed issue #77, a sortino warning prevents analyze() from completing
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user