Skip to content

Commit

Permalink
modify logic of annulization
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuizi7 committed Nov 12, 2018
1 parent 0a34912 commit 39995e3
Show file tree
Hide file tree
Showing 16 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion rqalpha/mod/rqalpha_mod_sys_analyser/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def tear_down(self, code, exception=None):
data_proxy.get_risk_free_rate(
self._env.config.base.start_date, self._env.config.base.end_date
),
(self._env.config.base.end_date - self._env.config.base.start_date).days + 1
self._env.data_proxy.count_trading_dates(self._env.config.base.start_date, self._env.config.base.end_date)
)
summary.update({
'alpha': self._safe_convert(risk.alpha, 3),
Expand Down
7 changes: 4 additions & 3 deletions rqalpha/model/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ def annualized_returns(self):
"""
if self.unit_net_value <= 0:
return -1
current_date = Environment.get_instance().trading_dt.date()
start_date = Environment.get_instance().config.base.start_date
return self.unit_net_value ** (DAYS_CNT.TRADING_DAYS_A_YEAR / float((current_date - start_date).days + 1)) - 1

env = Environment.get_instance()
date_count = float(env.data_proxy.count_trading_dates(env.config.base.start_date, env.trading_dt.date()))
return self.unit_net_value ** (DAYS_CNT.TRADING_DAYS_A_YEAR / date_count) - 1

@property
def total_value(self):
Expand Down
2 changes: 1 addition & 1 deletion rqalpha/utils/risk.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self, daily_returns, benchmark_daily_returns, risk_free_rate, days,
self._return = np.expm1(np.log1p(self._portfolio).sum())
self._annual_return = (1 + self._return) ** (252 / days) - 1
self._benchmark_return = np.expm1(np.log1p(self._benchmark).sum())
self._benchmark_annual_return = (1 + self._benchmark_return) ** (365 / days) - 1
self._benchmark_annual_return = (1 + self._benchmark_return) ** (252 / days) - 1
self._max_drawdown = None
self._volatility = None
self._annual_volatility = None
Expand Down
Binary file modified tests/outs/test_f_buy_and_hold.pkl
Binary file not shown.
Binary file modified tests/outs/test_f_macd.pkl
Binary file not shown.
Binary file modified tests/outs/test_f_macd_signal.pkl
Binary file not shown.
Binary file modified tests/outs/test_f_mean_reverting.pkl
Binary file not shown.
Binary file modified tests/outs/test_s_buy_and_hold.pkl
Binary file not shown.
Binary file modified tests/outs/test_s_dma.pkl
Binary file not shown.
Binary file modified tests/outs/test_s_dual_thrust.pkl
Binary file not shown.
Binary file modified tests/outs/test_s_golden_cross.pkl
Binary file not shown.
Binary file modified tests/outs/test_s_scheduler.pkl
Binary file not shown.
Binary file modified tests/outs/test_s_tick_size.pkl
Binary file not shown.
Binary file modified tests/outs/test_s_turtle.pkl
Binary file not shown.
Binary file modified tests/outs/test_s_turtle_signal.pkl
Binary file not shown.
Binary file modified tests/outs/test_sf_buy_and_hold.pkl
Binary file not shown.

0 comments on commit 39995e3

Please sign in to comment.