vn.py官网
开源量化社区
Member
avatar
加入于:
帖子: 59
声望: 1

Maximum allowed size exceeded
源码如下:# from datetime import datetime

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

class Donachia_Demo11(CtaTemplate):
author = "123qant"

#参数
donchia_in_length: int=20
donchia_out_length: int=8
daliy_length:int = 10
fixd_side=1

#变量
EntryLong_price=0.0
EntryShort_price=0.0
Exit_price=0.0
donchiaout_change_length = 0.0
daliyMA_value=0.0




parameters = ["donchia_in_length","donchia_out_length","daliy_length","fixd_side"]
variables = [ "EntryLong_price","EntryShort_price","Exit_price", "donchiaout_change_length","daliyMA_value"]


def __init__(self, cta_engine, strategy_name, vt_symbol, setting):
    """"""
    super().__init__(cta_engine, strategy_name, vt_symbol, setting)#初始化父类

    self.bg_min = BarGenerator(self.on_bar,window=20,on_window_bar=self.on_20min_bar)#合成器

    self.am_min = ArrayManager(100)#k线池


    #self.bg_daliy = BarGenerator_Daliy(self.on_bar,window=1,on_window_bar=self.on_daliy_bar,interval=Interval.DAILY)#合成器
    #self.am_daliy = ArrayManager(20)#k线池

def on_init(self):
    """
    Callback when strategy is inited.
    """
    self.load_bar(10)#载入历史数据,载入单位天
    self.write_log("策略初始化")#print

    #self.load_tick(10)
def on_start(self):
    """
    Callback when strategy is started.
    """
    self.write_log("策略启动")
    self.put_event()#刷新ui界面数据

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

    self.put_event()#刷新ui界面数据

def on_tick(self, tick: TickData):
    """
    Callback of new tick data update.
    """
    self.bg_min.update_tick(tick)#合成一分钟k线

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

    self.bg_min.update_bar(bar)
    # self.bg_daliy.update_bar(bar)

'''    
def on_daliy_bar(self,bar:BarData):
    self.am_daliy.update_bar(bar)

    if not self.am_daliy.inited:
        return
    self.daliyMA_value =self.am_daliy.sma(self.daliy_length)
    '''

def on_20min_bar(self,bar:BarData):
    self.am_min.update_bar(bar)
    if not self.am_min.inited :
        return
    self.cancel_all()

    self.donchiaout_change_length -=1
    self.donchiaout_change_length = max(self.donchiaout_change_length,self.donchia_out_length)
    up_arry,down_arry = self.am_min.donchian(self.donchia_in_length,True)
    self.EntryLong_price =up_arry[-2]
    self.EntryShort_price =down_arry[-2]
    if self.pos ==0:
        if bar.close_price > self.EntryLong_price :
            self.buy(bar.high_price,1)

        if  bar.close_price < self.EntryLong_price :
            self.short(bar.low_price,1)

    else:
        up_arry_out,down_arry_out = self.am_min.donchian(self.donchiaout_change_length,True)
        if self.pos >0:
            self.Exit_price = down_arry_out[-2]

            if bar.close_price < self.Exit_price:
                self.sell(bar.low_price,abs(self.pos))
            if bar.close_price > self.EntryLong_price :
                self.buy(bar.high_price,1)
        if self.pos < 0:
            self.Exit_price = up_arry_out[-2]

            if bar.close_price > self.Exit_price:
                self.cover(bar.high_price,abs(self.pos))
            if bar.close_price < self.EntryLong_price:
                self.short(bar.low_price,abs(self.pos))
    self.sync_data()#同步数据        

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.
    有成交后调用的函数,先调用on_order
    """

    self.donchiaout_change_length = self.donchia_in_length +1

def on_stop_order(self, stop_order: StopOrder):
    """
    Callback of stop order update.
    """
    pass

是ArrayManager缓存出错了吗?
self.load_bar()是缓存交易天数还是自然日天数
self.inited是缓存交易天数还是自然日天数

Member
avatar
加入于:
帖子: 3027
声望: 174

请贴一下你的报错截图
load_bar是自然日
调用过load_bar函数加载历史数据并完成初始化之后inited会变为True

Member
avatar
加入于:
帖子: 59
声望: 1

报错图片@xiaohe
description

Member
avatar
加入于:
帖子: 3027
声望: 174

数据太多溢出了吧

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

沪公网安备 31011502017034号