vn.py量化社区
By Traders, For Traders.
Member
avatar
加入于:
帖子: 100
声望: 17

spread_trading最大的问题是回测手续费不准确,这个要解决挺麻烦的,略过。
😁关于spread_trading的代码可以一起讨论啊
2019-11-29更新:调整断腿代码位置
2020-01-05更新:增加定时处理平仓断腿,开仓断腿真的不好处理......
链接:https://pan.baidu.com/s/1405VTIQL_GaEX695nkzcaA
提取码:a2lb

Member
avatar
加入于:
帖子: 100
声望: 17

spreadt_trading的函数传递还是比较复杂的。举个例子策略里面的self.stop_all_algos()调用了SpreadStrategyTemplate的stop_algo,stop_algo又调用了SpreadEngine里面的self.algo_engine.stop_algo,最后调用的是SpreadAlgoTemplate里面的stop,当时可把我找蒙了......

Member
avatar
加入于:
帖子: 100
声望: 17

😓还有算法下单策略里面的on_order,on_trade是没有回报的

Member
avatar
加入于:
帖子: 7
声望: 0

学习了,感恩群主与月总无私的开源精神

Member
avatar
加入于:
帖子: 7
声望: 0

月总,spread_trading中def load_tick_data(spread: SpreadData, start: datetime, end: datetime):
"""
合成价差tick数据
"""
"""spread_tick数据redis序列化存取"""
filename = f"{spread.name}{start.date()}_{end.date()}_tick"
redis_data = REDIS_CLIENT.hget(file_name, file_name)
if redis_data:
spread_ticks = pickle.loads(zlib.decompress(redis_data))
return spread_ticks
leg_ticks: Dict[str, Dict] = {}
min_volume = spread.min_volume
for vt_symbol in spread.legs.keys():
symbol, exchange = extract_vt_symbol(vt_symbol)

    tick_data: List[TickData] = database_manager.load_tick_data(
        symbol, exchange,start, end)

    ticks: Dict[datetime, TickData] = {tick.datetime: tick for tick in tick_data}
    leg_ticks[vt_symbol] = ticks

# Calculate spread tick data
spread_ticks: List[TickData] = []

for dt in ticks.keys():
    spread_bid_price = 0
    spread_bid_volume = 0
    spread_ask_price = 0
    spread_ask_volume = 0
    spread_volume = 0
    spread_last_price = 0
    spread_available = True

    for leg in spread.legs.values():
        leg_tick = leg_ticks[leg.vt_symbol].get(dt, None)

        if leg_tick:
            price_multiplier = spread.price_multipliers[leg.vt_symbol]
            trading_multiplier = spread.trading_multipliers[leg.vt_symbol]
            spread_bid_price += price_multiplier * leg_tick.bid_price_1
            spread_ask_price += price_multiplier * leg_tick.ask_price_1
            spread_last_price = (spread_bid_price + spread_ask_price) / 2

这里的 spread_bid_price += price_multiplier leg_tick.bid_price_1
spread_ask_price += price_multiplier
leg_tick.ask_price_1
和下方的
spread_bid_volume = min(spread_bid_volume, adjusted_bid_volume)
spread_ask_volume = min(spread_ask_volume, adjusted_ask_volume)
spread_volume = min(spread_volume, adjusted_volume)
貌似逻辑错误,
按个人理解,价差ask=主动腿的 ask-被动腿的 bid 价差bid=主动腿的 bid-被动腿的ask 才算完成对冲
你的写法是,价差ask=主动腿的 ask-被动腿的 ask 价差bid=主动腿的 bid-被动腿的bid

Member
avatar
加入于:
帖子: 7
声望: 0

查看 大佳老师以及网上资料 ,多是

            # 叫卖价差=leg1.askPrice1 - leg2.bidPrice1,volume为两者最小
            arbTick.askPrice1 = leg1AskPrice1 - leg2Tick.bidPrice1
            arbTick.askVolume1 = min(leg1AskVolume1, leg2Tick.bidVolume1)

            # 叫买价差=leg1.bidPrice1 - leg2.askPrice1,volume为两者最小
            arbTick.bidPrice1 = leg1BidPrice1 - leg2Tick.askPrice1
            arbTick.bidVolume1 = min(leg1BidVolume1, leg2Tick.askVolume1)
Member
avatar
加入于:
帖子: 100
声望: 17

@cfzvzv 这里都是抄spread tick合成的代码,抄漏了一段......

Member
avatar
加入于:
帖子: 7
声望: 0

嗯嗯,漏了对乘数正负的判断

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3