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

Traceback (most recent call last):
File "c:\vnstudio\lib\site-packages\vnpy\app\cta_backtester\ui\widget.py", line 290, in process_backtesting_finished_event
self.chart.set_data(df)
File "c:\vnstudio\lib\site-packages\vnpy\app\cta_backtester\ui\widget.py", line 807, in set_data
hist, x = np.histogram(df["net_pnl"], bins="auto")
File "<__array_function__ internals>", line 6, in histogram
File "c:\vnstudio\lib\site-packages\numpy\lib\histograms.py", line 792, in histogram
bin_edges, uniform_bins = _get_bin_edges(a, bins, range, weights)
File "c:\vnstudio\lib\site-packages\numpy\lib\histograms.py", line 448, in _get_bin_edges
endpoint=True, dtype=bin_type)
File "<__array_function__ internals>", line 6, in linspace
File "c:\vnstudio\lib\site-packages\numpy\core\function_base.py", line 128, in linspace
y = _nx.arange(0, num, dtype=dt).reshape((-1,) + (1,) * ndim(delta))
ValueError: Maximum allowed size exceeded

Administrator
avatar
加入于:
帖子: 4749
声望: 278

数据太大导致超过了numpy数据容器的上限,缩短点回测范围吧

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

您是指的回测时间的范围么?还是指标的范围,我都试过了还是溢出报错。麻烦您谤满看下应该把哪个值改小
from sys import call_tracing
from numpy.core.numeric import cross
from vnpy.app.cta_strategy import (
CtaTemplate,
StopOrder,
TickData,
BarData,
TradeData,
OrderData,
BarGenerator,
ArrayManager,
)
import numpy as np

class EmaMacciStrategy523(CtaTemplate):
author = "用cci ema单线价格"

ema_slow_window = 60
cci_window = 30
fixsize =  3


slow_ema0 = 0.0
cci_0 = 0.0
cci_1 = 0.0

parameters = [ "ema_slow_window",
                "cci_window",  
                "fixsize"
                ]

variables = [   "slow_ema0",
                "cci_0",
                "cci_1"
            ]


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()

def on_init(self):
    """
    Callback when strategy is inited.
    """
    self.write_log("策略初始化")
    self.load_bar(1)

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)
    if not am.inited:
        return


    cci_value = am.cci(self.cci_window,array=True)
    self.cci_0 = cci_value[-1]
    self.cci_1 = cci_value[-2]

    slow_ema0 = am.ema(self.ema_slow_window, array=True)
    self.slow_ema0 = slow_ema0[-1]


    keep_over = bar.close_price > self.slow_ema0 
    keep_below = bar.close_price < self.slow_ema0


    if keep_over :
        if self.pos == 0:
            if self.cci_0 >= 99 :
                self.buy(bar.close_price, self.fixsize)
                if self.cci_1 - self.cci_0 >= 20  or self.cci_0 <=99 :
                    self.sell(bar.close_price, abs(self.pos), stop=True)

        elif self.pos >0:
            if self.cci_0 < 99 or  keep_below:
                self.sell(bar.close_price, abs(self.pos), stop=True)

        elif self.pos < 0:
            self.cover(bar.close_price, abs(self.pos), stop=True)


    if keep_below:
        if self.pos == 0:
            if self.cci_0 <= -99 :
                self.short(bar.close_price,self.fixsize)
                if self.cci_1 - self.cci_0 >= 20  or self.cci_0 >= -99 :
                    self.cover(bar.close_price, abs(self.pos), stop=True)

        elif self.pos < 0:
            if self.cci_0 > -99 or  keep_over:
                self.sell(bar.close_price, abs(self.pos), stop=True)

        elif self.pos > 0:
            self.sell(bar.close_price,abs(self.pos),stop=True)


扩展了两个持续指标 keep_over keep_below

    self.put_event()

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
加入于:
帖子: 2357
声望: 148

回测的时间范围

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

xiaohe wrote:

回测的时间范围
我调整到回测5天,还是报错溢出

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

沪公网安备 31011502017034号