Skip to content

Commit

Permalink
Merge pull request ricequant#813 from ricequant/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Zhou-JiaJun authored Sep 15, 2023
2 parents 09ef170 + 59f94b7 commit 0fd8f89
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
CHANGELOG
==================

5.2.1
==================
- 修复期货分钟回测open_auction拿到的最新价有误
- 修复当日无成交量时算法单有误

5.2.0
==================
- report年度指标新增超额夏普比率
Expand Down
4 changes: 4 additions & 0 deletions rqalpha/data/data_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ def get_algo_bar(self, id_or_ins, order_style, dt):
id_or_ins = self.instrument(id_or_ins)
if id_or_ins is None:
return np.nan, 0
# 存在一些有日线没分钟线的情况,如果不是缺了,通常都是因为volume为0,用日线先判断确认下
day_bar = self.get_bar(order_book_id=id_or_ins.order_book_id, dt=dt, frequency="1d")
if day_bar.volume == 0:
return np.nan, 0
bar = self._data_source.get_algo_bar(id_or_ins, order_style.start_min, order_style.end_min, dt)
return (bar[order_style.TYPE], bar["volume"]) if bar else (np.nan, 0)

Expand Down
4 changes: 2 additions & 2 deletions rqalpha/mod/rqalpha_mod_sys_simulation/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ def _vwap_decider(self, order_book_id, _):
return 0

def _open_auction_deal_price_decider(self, order_book_id, _):
return self._env.data_proxy.get_open_auction_bar(order_book_id, self._env.calendar_dt).open
return self._env.data_proxy.get_open_auction_bar(order_book_id, self._env.trading_dt).open

SUPPORT_POSITION_EFFECTS = (POSITION_EFFECT.OPEN, POSITION_EFFECT.CLOSE, POSITION_EFFECT.CLOSE_TODAY)
SUPPORT_SIDES = (SIDE.BUY, SIDE.SELL)

def _get_bar_volume(self, order, open_auction=False):
if open_auction:
volume = self._env.data_proxy.get_open_auction_bar(order.order_book_id, self._env.calendar_dt).volume
volume = self._env.data_proxy.get_open_auction_bar(order.order_book_id, self._env.trading_dt).volume
else:
if isinstance(order.style, ALGO_ORDER_STYLES):
_, volume = self._env.data_proxy.get_algo_bar(order.order_book_id, order.style, self._env.calendar_dt)
Expand Down
3 changes: 2 additions & 1 deletion rqalpha/model/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ def __getitem__(self, key):
if not self._dt:
return BarObject(instrument, NANDict, self._dt)
if ExecutionContext.phase() == EXECUTION_PHASE.OPEN_AUCTION:
bar = self._data_proxy.get_open_auction_bar(order_book_id, self._dt)
trading_date = self._dt if self._frequency == "1d" else self._data_proxy.get_trading_dt(self._dt).date()
bar = self._data_proxy.get_open_auction_bar(order_book_id, trading_date)
else:
bar = self._data_proxy.get_bar(order_book_id, self._dt, self._frequency)
except PermissionError:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[metadata]
name = rqalpha
version = 5.2.0
version = 5.2.1

[versioneer]
VCS = git
Expand Down
45 changes: 45 additions & 0 deletions tests/api_tests/mod/sys_simulation/test_simulation_event_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,48 @@ def handle_bar(context, bar_dict):
assert context.open_auction_prices == (bar.open, bar.limit_up, bar.limit_down, bar.prev_close)

return locals()


def test_open_auction_1m():
""" 测试分钟回测下的open_auction """

try:
import rqalpha_plus
except ImportError:
print("非本地不执行分钟频率测试")
return {}

__config__ = {
"base": {
"start_date": "2023-03-17",
"end_date": "2023-03-17",
"frequency": "1m",
"accounts": {
"stock": 100000,
"future": 1000000,
}
},
"mod": {
"ricequant_data": {
"enabled": True,
}
}
}

def init(context):
subscribe("AU2306")
subscribe("000001.XSHE")

def open_auction(context, bar_dict):
buy_open("AU2306", 1)
order_shares("000001.XSHE", 100)
assert bar_dict["AU2306"].last == 432.58, "期货分钟频率open_auction价格有误"
assert bar_dict["000001.XSHE"].last == 12.99, "股票分钟频率open_auction价格有误"

def handle_bar(context, bar_dict):
pos = get_position("AU2306")
assert pos.avg_price == 432.58, "期货分钟频率open_auction价格有误"
pos = get_position("000001.XSHE")
assert pos.avg_price == 12.99, "股票分钟频率open_auction价格有误"

return locals()

0 comments on commit 0fd8f89

Please sign in to comment.