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

如题,测试双均线策略的时候,onbar函数的cross over和cross below的时候打印出交易记录。

    if cross_over:
        print(">>> bar cross over.", bar.datetime, bar.close_price, self.fast_ma0, self.fast_ma1, self.slow_ma0, self.slow_ma1)

        if self.pos == 0:
            self.buy(bar.close_price, 1)
        elif self.pos < 0:
            self.cover(bar.close_price, 1)
            self.buy(bar.close_price, 1)

    elif cross_below:
        print(">>> bar cross below.", bar.datetime, bar.close_price, self.fast_ma0, self.fast_ma1, self.slow_ma0, self.slow_ma1)

在回测的时候,发现在上一步骤打印出的交易记录和回测K线图上的交易箭头指示不匹配。

随后我就在class CandleChartDialog(QtWidgets.QDialog)的如下函数打印出来trade记录, 发现和第一步走打印出的交易记录不匹配。这个trade list里面的记录少了一些。请问是怎么回事呢?
def generate_trade_pairs(trades: list) -> list:
""""""
long_trades = []
short_trades = []
trade_pairs = []

idx = 0
for trade in trades:
    trade = copy(trade)
    idx += 1
    print(">>>trade[",idx,"]:", trade)   //加日志打印出trade记录。
Member
avatar
加入于:
帖子: 212
声望: 7

请问用的是哪个版本?

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

这个版本
project = 'vnpy'
copyright = '2019, vn.py Team'
author = 'vn.py Team'

The short X.Y version

version = '2.0.3'

The full version, including alpha/beta/rc tags

release = '2.0.3'

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

昨天在官网下载的版本也不行:
比如这一段是双均线里面打印出来的:

bar cross below. 2020-07-06 21:30:00+08:00 3143.0 3111.4 3106.8 3112.35 3106.7
bar cross over. 2020-07-06 23:00:00+08:00 3152.75 3128.25 3117.3 3121.925 3118.65
bar cross below. 2020-07-07 23:00:00+08:00 3154.0 3150.85 3150.6 3151.475 3150.375
bar cross over. 2020-07-08 03:00:00+08:00 3154.0 3154.0 3151.6 3152.3 3152.175
bar cross below. 2020-07-09 22:00:00+08:00 3111.25 3143.35 3151.9 3147.475 3151.625
bar cross over. 2020-07-10 22:00:00+08:00 3121.75 3120.35 3119.1 3119.45 3122.675
bar cross below. 2020-07-14 21:30:00+08:00 3132.5 3175.3 3188.2 3183.075 3184.225
bar cross over. 2020-07-15 04:30:00+08:00 3163.5 3156.5 3153.1 3152.475 3154.725
bar cross below. 2020-07-16 22:00:00+08:00 3177.5 3190.1 3194.7 3190.5 3193.7
bar cross over. 2020-07-17 21:30:00+08:00 3193.25 3178.65 3176.0 3178.325 3178.85
bar cross below. 2020-07-23 21:30:00+08:00 3258.0 3246.2 3244.1 3246.25 3243.25

这一段是trades list (删除了一些没用的字符串):
orderid='1', tradeid='1', '空'>'开'>, price=3149.5, (2020, 7, 6, 22, 0, ))
orderid='2', tradeid='2', '多''平'>, price=3152.75, (2020, 7, 7, 0, 0, ))
orderid='3', tradeid='3', '多'>'开'>, price=3152.75, (2020, 7, 7, 0, 0, ))
orderid='4', tradeid='4', '空''平'>, price=3154.0, (2020, 7, 8, 0, 0, ))
orderid='5', tradeid='5', '空'>'开'>, price=3154.0, (2020, 7, 8, 0, 0, ))
orderid='6', tradeid='6', '多''平'>, price=3154.0, (2020, 7, 8, 4, 0, ))
orderid='7', tradeid='7', '多'>'开'>, price=3154.0, (2020, 7, 8, 4, 0, ))
orderid='8', tradeid='8', '空''平'>, price=3111.25, (2020, 7, 9, 23, 0, ))
orderid='9', tradeid='9', '空'>'开'>, price=3111.25, (2020, 7, 9, 23, 0, ))
orderid='10', tradeid='10', '多''平'>, price=3121.75, (2020, 7, 10, 23, 0, ))
orderid='11', tradeid='11', '多'>'开'>, price=3121.75, (2020, 7, 10, 23, 0, ))
orderid='12', tradeid='12', '空''平'>, price=3132.5, (2020, 7, 14, 23, 0, ))
orderid='13', tradeid='13', '空'>'开'>, price=3132.5, (2020, 7, 14, 23, 0, ))
orderid='16', tradeid='14', '多''平'>, price=3183.5, (2020, 7, 17, 22, 0, ))
orderid='17', tradeid='15', '多'>'开'>, price=3183.5, (2020, 7, 17, 22, 0, ))

可以看到7月16日bar cross below的交易在trades list里面没有

Member
avatar
加入于:
帖子: 2102
声望: 139

请升级至最新版再试试看

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

用的就是最新的版本

Member
avatar
加入于:
帖子: 2102
声望: 139

K线图表不针对合成的N分钟的K线的回测

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

明白了

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

沪公网安备 31011502017034号