Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增算法单: TVWPOrder 和 VWAPOrder #793

Merged
merged 3 commits into from
May 30, 2023
Merged

新增算法单: TVWPOrder 和 VWAPOrder #793

merged 3 commits into from
May 30, 2023

Conversation

Zhou-JiaJun
Copy link
Contributor

No description provided.

"""
指定股数的买/卖单,最常见的落单方式之一。如有需要落单类型当做一个参量传入,如果忽略掉落单类型,那么默认是市价单(market order)。

:param id_or_ins: 下单标的物
:param amount: 下单量, 正数代表买入,负数代表卖出。将会根据一手xx股来向下调整到一手的倍数,比如中国A股就是调整成100股的倍数。
:param price: 下单价格,默认为None,表示 :class:`~MarketOrder`, 此参数主要用于简化 `style` 参数。
:param style: 下单类型, 默认是市价单。目前支持的订单类型有 :class:`~LimitOrder` 和 :class:`~MarketOrder`
:param price_or_style: 原参数price和style的整合
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个参数还是详细写写是怎么用的

@@ -151,11 +167,11 @@ def order_percent(id_or_ins, percent, price=None, style=None):
)
@apply_rules(
verify_that('cash_amount').is_number(),
verify_that('style').is_instance_of((MarketOrder, LimitOrder, type(None)))
*common_rules
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里 price_or_style 还应支持 tuple 类型,似乎没在参数检查中体现。

@@ -38,6 +38,9 @@ def start_up(self, env, mod_config):

mod_config.matching_type = self.parse_matching_type(mod_config.matching_type, env.config.base.frequency)

if mod_config.matching_type == MATCHING_TYPE.VWAP:
user_system_log.warning("matching_type: vwap is deprecated")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我想了一下是不是先不废弃 vwap 比较好,我们只在日回测中引入了新的 OrderStyle,分钟回测下 vwap 撮合类型仍然是有意义的。

@@ -445,6 +445,10 @@ def is_st_stock(self, order_book_id, dates):
# type: (str, Sequence[DateLike]) -> Sequence[bool]
raise NotImplementedError

def get_algo_bar(self, id_or_ins, start_min, end_min, dt):
# type: (Union[str, Instrument], int, int, datetime) -> Optional[numpy.ndarray]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里加一些注释吧,说明返回的是个啥样的 ndarray

if id_or_ins is None:
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TYPE 不是 OrderStyle 基类的属性,此处至少要用 type hint 限制一下 order_style 的类型

@@ -61,7 +61,8 @@ def _submit_order(id_or_ins, amount, side, position_effect, style):
raise RQInvalidArgument(_(u"Index Future contracts[99] are not supported in paper trading."))

price = env.get_last_price(order_book_id)
if not is_valid_price(price):
algo_price = env.data_proxy.get_algo_bar(instrument, style, env.calendar_dt)[0] if isinstance(style, ALGO_ORDER_STYLES) else 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里我觉得可以沿用老的判断,有 last_price 即认为有行情,不需要提前计算 algo_price

price = env.data_proxy.get_last_price(ins.order_book_id)
if not is_valid_price(price):
algo_price = env.data_proxy.get_algo_bar(ins, style, env.calendar_dt)[0] if isinstance(style, ALGO_ORDER_STYLES) else 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

和期货那边类似,可以简化处理,只看 last_price 来判断是否有行情

_(u"Order Creation Failed: [{order_book_id}] No market data").format(order_book_id=ins.order_book_id)
)
return
price = _get_order_style_price(ins.order_book_id, style)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此处计算数量我也觉得用 last_price 更合理一些,直接用 vwap 或者 twap 加个计算数量用了太多的未来数据

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vwap twap 也都加一些测试用例

@coveralls
Copy link

coveralls commented May 30, 2023

Coverage Status

Coverage: 63.831% (+0.1%) from 63.702% when pulling 25260b7 on dev-rqsdk-631 into 8718fa2 on develop.

@Cuizi7 Cuizi7 merged commit 8dde3db into develop May 30, 2023
14 checks passed
@Zhou-JiaJun Zhou-JiaJun deleted the dev-rqsdk-631 branch May 31, 2023 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants