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

我的BarGenerator是这样的

description
数据的日期是从20年1月16号开始的

description
结果输出的时候只有20年6月16号的数据,加载了少了半年才能合成第一根Bar
description
我换了好几台电脑都是这样,卸了重装还是一样 每次都是在BarGenerator下面加载了这段合成日线的代码
我以为我的原始数据有问题,但是我把Interval类型改为1分钟,1月16号的数据都可以每根都输出来
实在没办法了,下面是代码,大哥们帮我看下,谢谢!

from vnpy.app.cta_strategy import (
    CtaTemplate,
    StopOrder,
    TickData,
    BarData,
    TradeData,
    OrderData,
    BarGenerator,
    ArrayManager,
)
from vnpy.trader.constant import Interval

class DoubleMaStrategy(CtaTemplate):
    author = "用Python的交易员"

    fast_window = 10
    slow_window = 20

    fast_ma0 = 0.0
    fast_ma1 = 0.0

    slow_ma0 = 0.0
    slow_ma1 = 0.0

    parameters = ["fast_window", "slow_window"]
    variables = ["fast_ma0", "fast_ma1", "slow_ma0", "slow_ma1"]

    def __init__(self, cta_engine, strategy_name, vt_symbol, setting):
        """"""
        super().__init__(cta_engine, strategy_name, vt_symbol, setting)

        self.bg = BarGenerator(self.on_bar)
        self.am = ArrayManager()

        self.bg_x=BarGenerator(self.on_bar,1,self.on_x_bar,interval=Interval.DAILY)
        self.am_x = ArrayManager()
    def on_init(self):
        """
        Callback when strategy is inited.
        """
        self.write_log("策略初始化")
        self.load_bar(40)

    def on_start(self):
        """
        Callback when strategy is started.
        """
        self.write_log("策略启动")
        self.put_event()

    def on_stop(self):
        """
        Callback when strategy is stopped.
        """
        self.write_log("策略停止")

        self.put_event()

    def on_tick(self, tick: TickData):
        """
        Callback of new tick data update.
        """
        self.bg.update_tick(tick)

    def on_bar(self, bar: BarData):
        """
        Callback of new bar data update.
        """

        am = self.am
        am.update_bar(bar)
        self.bg_x.update_bar(bar)
        if not am.inited:
            return
        pass

    def on_x_bar(self,bar):
        am = self.am_x
        am.update_bar(bar)
        if not am.inited:
            return       
        pass
        self.put_event()
        print("on_day",bar.datetime)
    def on_order(self, order: OrderData):
        """
        Callback of new order data update.
        """
        pass

    def on_trade(self, trade: TradeData):
        """
        Callback of new trade data update.
        """
        self.put_event()

    def on_stop_order(self, stop_order: StopOrder):
        """
        Callback of stop order update.
        """
        pass
Member
avatar
加入于:
帖子: 6
声望: 0

我知道了,因为ArrayManager没填满才没有输出,为什么要半年才能填满,分钟线不会这样的啊

Member
avatar
加入于:
帖子: 1987
声望: 131

因为你在am初始化之后print,这样初始化完成前都会return。am的默认size是100,那么就要100根日线才能完成初始化,而分钟线初始化只要100分钟,从日期上来看才差别那么大

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

沪公网安备 31011502017034号