VeighNa量化社区
你的开源社区量化交易平台
yuanhuei's Avatar
Member
离线
84 帖子
声望: 2

我用的Wing,这个和编辑器有关系啊

self.boll_up, self.boll_down = am.boll(self.boll_window, self.boll_dev)
这个就不是计算吗

on_trade是交易所告诉你你的单子成交了,on_bar只是VNPY里面合成了一个bar之后的回调函数。send_order之后不是说就能成交,要等on_trade被调用才知道的

engine = BacktestingEngine()
engine.set_parameters(
vt_symbol="j99.DCE",

#橡胶ru99.CFFEX,焦炭j99.DCE,螺纹钢rb888.SHFE,铜cu888.SHFE,鸡蛋jd99.DCE,铁矿石i99.DCE,豆粕$9.CFFEX,玉米c99.DCE
#郑醇ma99.CZCE,pp99.DCE,pvc99.DCE,pta99.CZCE,al99.SHFE,zn99.SHFE
interval="1m",
start=datetime(2010, 1, 16),
end=datetime(2014, 5, 16),
rate=0.3/10000,
slippage=1,
size=10,
pricetick=0.2,
capital=1_000_000,

)
engine.add_strategy(RBreakStrategy, {})

%%

engine.load_data()
engine.run_backtesting()
df = engine.calculate_result()
engine.calculate_statistics()
engine.show_chart()、

description

好的,谢谢

CtaEngine中下面这个OffsetConverter是干嘛的,没有注释,只能靠猜。是不是开平标识,有些不一致,需要转换。能否解释一下。
self.offset_converter = OffsetConverter(self.main_engine)

群主写代码,一点注释的习惯都没有,其实只要写几个字,就不用猜来猜去了。有些自己写代码,过久了,没有注释,自己想都挺费劲的。

这个本地停止单已经实现了吧,看看下面这段代码,.这个是ctaengine处理tick的代码,check_stop_order(tick)就是来检查是否已经触发停止单的,在tick就处理了,不用等到bar

def process_tick_event(self, event: Event):
    """"""
    tick = event.data

    strategies = self.symbol_strategy_map[tick.vt_symbol]
    if not strategies:
        return

    self.check_stop_order(tick)

    for strategy in strategies:
        if strategy.inited:
            self.call_strategy_func(strategy, strategy.on_tick, tick)

是我没看清,还是VNPY就是这么处理的。

隔夜策略,单子的止损单,在收盘后交易所没有了,我看了下VNPY也没有保存下来下次开盘的时候再发。这样会导致一个问题,下次开盘的时候,单子是没有止损的。
需要等到on_window_bar函数触发之后,计算后重新发出。例如15分钟的策略,需要等到9:15触发的时候才能计算,并重新发止损。

这开盘到15分钟满,是没有止损设置的。这是算是一个bug吗,我看文档里面都没写需要在策略里面自己处理这一部分。

1.第一个疑问,下面是update_tick函数中把tick更新到bar数据中的部分,最高价和最低价,为什么不是直接比较当前bar的最高最低价和tick最高最低价的比较,而是
还要比较上一个tick

 self.bar.high_price = max(self.bar.high_price, tick.last_price)
        if tick.high_price > self.last_tick.high_price:
            self.bar.high_price = max(self.bar.high_price, tick.high_price)

        self.bar.low_price = min(self.bar.low_price, tick.last_price)
        if tick.low_price < self.last_tick.low_price:
            self.bar.low_price = min(self.bar.low_price, tick.low_price)

2.还是这个函数,在更新bar的成交量时候,为什么不是直接累加上新tick的成交量,还要和上一次做差值,再和0比较取最大的加上去
double volume_change = tickData->volume - m_lastTick->volume;
m_Bar->volume= m_Bar->volume+std::max(volume_change, 0.0);

用IDE, 都有调试功能。我用的wing

请问“多合约组合策略模块”和这个有什么区别啊?

应该是在这里重新指向和赋值的 ,不过感觉有点问题,如果有加仓的话,开平仓不相邻,形成的交易对好像有问题
if trade.direction == Direction.LONG:
same_direction = long_trades
opposite_direction = short_trades
else:
same_direction = short_trades
opposite_direction = long_trades

这个opposite_direction一直没有查到有赋值的地方,opposite_direction = short_trades或者opposite_direction = long_trades,short_trades,long_trades也是空集合啊,后面怎么基于它来操作的,没看明白

下面这个generate_trade_pairs应该是生成交易对的,没完全看明白,程序是怎么判断两个交易是一对的。如果有加仓,开和平仓并不是相邻的,显示会不会有BUG。

因为我编写的策略有加仓,感觉显示出来的交易对有问题

\vnpy\app\cta_backtester\ui\widget.py

def generate_trade_pairs(trades: list) -> list:
""""""
long_trades = []
short_trades = []
trade_pairs = []

for trade in trades:
    trade = copy(trade)

    if trade.direction == Direction.LONG:
        same_direction = long_trades
        opposite_direction = short_trades
    else:
        same_direction = short_trades
        opposite_direction = long_trades

    while trade.volume and opposite_direction:
        open_trade = opposite_direction[0]

        close_volume = min(open_trade.volume, trade.volume)
        d = {
            "open_dt": open_trade.datetime,
            "open_price": open_trade.price,
            "close_dt": trade.datetime,
            "close_price": trade.price,
            "direction": open_trade.direction,
            "volume": close_volume,
        }
        trade_pairs.append(d)

        open_trade.volume -= close_volume
        if not open_trade.volume:
            opposite_direction.pop(0)

        trade.volume -= close_volume

    if trade.volume:
        same_direction.append(trade)

return trade_pairs

可以了,多谢

最大分辨率只能到1366*768

我的笔记本电脑屏幕不大,回测结果有一部分看不到,这个界面可以手工调节大小吗。
在这个类里面
class StatisticsMonitor(QtWidgets.QTableWidget):

description

调试程序,如下,
orderList=self.buy(self.bollUpDay+self.priceTick, volume, True)
发送的开仓价格是4186 ,
执行上面那条语句后,查看self.active_stop_orders挂单的价格是4190,怎么这么奇怪?就是这个原因导致该成交单子没有成交。
后面会有更改吗

可以了,我是用IDE wing来调试的,要把C:\Users\yuanhui\strategies加到工程里面,这个里面设置断点,不在是vnpy\app\cta_strategy里面了

© 2015-2022 微信 18391752892
备案服务号:沪ICP备18006526号

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】