掘金社区

策略时间与回测时间不一致Pinned highlighted

158789***933 发表在问题反馈 2020-06-26 21:14:22

问题反馈
265
3
0

编写策略时要求的时间是2019-01-01至2020-01-01,但是策略回测后的时间却是2016至2017年,这是什么问题?

评论: 3
  • 策略代码是这样的,有什么问题吗?
    from gm.api import *
    import numpy as np
    import talib

    def init(context):
    schedule(schedule_func=algo, date_rule="1d", time_rule="09:35:00")
    context.symbol = "SZSE.000164"
    context.frequency = "1d"
    context.fields = "open,high,low,close"
    context.volume = 200

    def algo(context):
    now = context.now
    last_day = get_previous_trading_date("SZSE", now)
    data = history_n(symbol=context.symbol, frequency=context.frequency, count=35,
    end_time=last_day, fields=context.fields, fill_missing="last", adjust=ADJUST_PREV, df=True)

    close = np.asarray((data["close"].values))
    macd, _, _ = talib.MACD(close)
    macd = macd[-1]
    

    #open = np.asarray((data["open"].values))
    #high = np.asarray((data["high"].values))
    #low = np.asarray((data["low"].values))

    if macd > 0:
       order_volume(symbol=context.symbol, volume=context.volume, side=PositionSide_Long,
                 order_type=OrderType_Market, position_effect=PositionEffect_Open)
       print("买入")
    elif macd < 0:
        print("卖出")
        order_volume(symbol=context.symbol, volume=context.volume, side=PositionSide_Short,
                 order_type=OrderType_Market, position_effect=PositionEffect_Close)
    

    if name == 'main':
    run(strategy_id='47616ad0-6375-11ea-b578-54e1adce4f54',
    filename='main1.py',
    mode=MODE_BACKTEST,
    token='16604f9de9e27e7c7287f83672c66c8711b6afb8',
    backtest_start_time='2019-01-01 13:00:00',
    backtest_end_time='2020-01-01 15:00:00',
    backtest_initial_cash=1000000,
    backtest_adjust=ADJUST_PREV)

    2020-06-26 21:16:12
  • 是在终端里点击运行回测按钮的吧, 检查下回测参数是否使用已有回测参数, 再检查下run()的 strategy_id是否和终端里的一致

    2020-06-28 17:24:12
  • @技术支持1 谢谢,回测时间问题已解决

    2020-07-01 12:07:18

Looks like your connection to 掘金量化社区 - 量化交易者的策略交流学习社区 was lost, please wait while we try to reconnect.