Skip to content

Commit

Permalink
fix and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhou-JiaJun committed Oct 11, 2022
1 parent 9528187 commit e3f9f94
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
3 changes: 1 addition & 2 deletions rqalpha/mod/rqalpha_mod_sys_analyser/plot/utils.py
Expand Up @@ -74,8 +74,7 @@ def max_ddd(arr: array, index: DatetimeIndex) -> IndexRange:


def weekly_returns(portfolio: DataFrame) -> Series:
return portfolio.unit_net_value.reset_index().resample(
"W", on="date").last().set_index("date").unit_net_value.dropna() - 1
return portfolio.unit_net_value.resample("W").last().dropna() - 1


def trading_dates_index(trades: DataFrame, position_effect, index: DatetimeIndex):
Expand Down
2 changes: 1 addition & 1 deletion rqalpha/portfolio/__init__.py
Expand Up @@ -279,7 +279,7 @@ def deposit_withdraw(self, account_type, amount, receiving_days=0):
unit_net_value = self.unit_net_value
self._accounts[account_type].deposit_withdraw(amount, receiving_days)
_units = self.total_value / unit_net_value
user_log.info(_("Cash add {}. units {} become to {}".format(amount, self._units ,_units)))
user_log.info(_("Cash add {}. units {} become to {}".format(amount, self._units, _units)))
self._units = _units

def finance_repay(self, amount, account_type):
Expand Down
3 changes: 1 addition & 2 deletions rqalpha/portfolio/account.py
Expand Up @@ -19,7 +19,6 @@
from datetime import date
from typing import Callable, Dict, Iterable, List, Optional, Union, Tuple

import rqdatac
import six
from rqalpha.const import POSITION_DIRECTION, POSITION_EFFECT, DEFAULT_ACCOUNT_TYPE, DAYS_CNT
from rqalpha.environment import Environment
Expand Down Expand Up @@ -490,7 +489,7 @@ def deposit_withdraw(self, amount: float, receiving_days: int = 0):
if (amount < 0) and (self.cash < amount * -1):
raise ValueError(_('insufficient cash, current {}, target withdrawal {}').format(self._total_cash, amount))
if receiving_days >= 1:
receiving_date = rqdatac.get_next_trading_date(self._env.trading_dt.date(), n=receiving_days)
receiving_date = self._env.data_proxy.get_next_trading_date(self._env.trading_dt.date(), n=receiving_days)
self._pending_deposit_withdraw.append((receiving_date, amount))
self._pending_deposit_withdraw.sort(key=lambda i: i[0])
else:
Expand Down
6 changes: 6 additions & 0 deletions tests/api_tests/test_api_base.py
Expand Up @@ -482,4 +482,10 @@ def handle_bar(context, bar_dict):
else:
assert False, "未报出当前账户可取出金额不足异常"

deposit("STOCK", 10000, 3)
context.cash = context.portfolio.accounts["STOCK"].cash

elif context.counter == 9:
assert int(context.portfolio.accounts["STOCK"].cash) == int(context.cash) + 10000

return locals()

0 comments on commit e3f9f94

Please sign in to comment.