A股吸收合并特殊业务,当天总资产减少
提 ISSUE 须知
请先阅读文档 rqalpha文档
如果仍有问题的话请在 issue列表 中寻找是否有相关问题的解决方案
如果没有的话 麻烦开一个issue 描述以下问题:
1. RQAlpha的版本
5.6.2
2. Python的版本
3.12
3. 是Windows/Linux/MacOS or others?
Windows 11
4. 您出现问题对应的源码/或者能复现问题的简易代码 以及对应的配置
4.1 问题现象:调仓中有一个海通债券的成分,在20250303时发生了吸收合并事件,转化为了海通证券,查看回测的结果发现转换前后持仓市值没变,但是账户的总资产变少了,且现金为负数,我这边验算了一下,似乎当前处理的方案是:吸收合并事件,先按照持仓成本价计算扣除金额进行逻辑买入,然后再按照最新收盘价计算被吸收股票返回账户的钱。前后依据价钱不一致,核算下来刚好是总资产变动的金额。前后计算价钱不使用同一个是由特殊的场景考虑吗
4.2 回测策略如下:
from rqalpha.apis import *
HAITONG_OLD = "600837.XSHG" HAITONG_NEW = "601211.XSHG"
config = { "base": { "data_bundle_path": "D:/code/project/test/rqalpha/.rqalpha/bundle", "start_date": "2025-01-02", "end_date": "2026-05-11", "frequency": "1d", "accounts": { "stock": 1000000.0, }, }, "extra": { "log_level": "info", }, "mod": { "sys_simulation": { "slippage": 0.0, }, "sys_transaction_cost": { "stock_commission_multiplier": 0.0, "stock_min_commission": 0.0, }, "sys_analyser": { "benchmark": "000300.XSHG", }, }, }
def init(context): context.old_stock = HAITONG_OLD context.new_stock = HAITONG_NEW context.bought = False update_universe([context.old_stock, context.new_stock]) logger.info("verify share transformation: 600837.XSHG -> 601211.XSHG, ratio=0.62")
def before_trading(context): pass
def open_auction(context, bar_dict): pass
def handle_bar(context, bar_dict): if context.bought: return
if not _has_price(context.old_stock, bar_dict):
logger.warning(f"{context.old_stock} has no current market data, skip initial buy")
return
order_target_percent(context.old_stock, 1.0)
context.bought = True
logger.info(f"initial buy submitted for {context.old_stock}")def after_trading(context): positions = [ p for p in get_positions() if getattr(p, "quantity", 0) > 0 ] if not positions: logger.info(f"{context.now.date()} positions: empty") return
summary = ", ".join(
f"{p.order_book_id}:{p.quantity}" for p in positions
)
logger.info(f"{context.now.date()} positions: {summary}")def _has_price(stock, bar_dict): try: bar = bar_dict[stock] price = getattr(bar, "open", None) if price is None or price != price or price <= 0: price = getattr(bar, "close", None) return price is not None and price == price and price > 0 except Exception: return False
4.3 具体回测结果如下
5. 您出现的错误堆栈日志信息
Source: ricequant/rqalpha