请问SystemError: PyEval_EvalFrameEx returned NULL without setting an error是什么意思?

策略分享
标签: #<Tag:0x00007fcf71cb8cc8>

(xiaoxiao2017) #1
克隆策略
In [2]:
# 1. 策略基本参数

start_date = '2017-05-01'
end_date = '2017-08-01'
benchmark = '000300.INDX'
#instruments=['600000.SHA']
#instruments=['600000.SHA','600519.SHA']
#instruments=['200725.SZA']
#instruments=['600000.SHA','600519.SHA','200017.SZA']
instruments=D.instruments(start_date,end_date)
capital_base = 100000

# 2. 策略主体函数
# 初始化虚拟账户状态,只在第一个交易日运行
def initialize(context):
    # 设置手续费,买入时万3,卖出是千分之1.3,不足5元以5元计
    context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))
    context.tr_all=list() #记录每天振幅
    context.tr_num=20 # 要几天的TR均值
    context.day_n=0 #数天数
    context.N=0.0
    context.stoped=list() #记录当日止*了什么
    context.in_price=dict()#在一个股票的版本里,用数值就够了,这里要变成字典

# 策略交易逻辑,每个交易日运行一次
def handle_data(context, data):
    context.day_n=context.day_n+1
    in_days_num=20 # 55日进,20日出
    out_days_num=5
    for i in instruments:
        sid=context.symbol(i)
        try:
            last_in_price=context.in_price[i]#每次覆盖
        except KeyError:
            last_in_price=0
        cur_position=context.portfolio.positions[sid].amount#为啥这里的sid用[]?因为 是dict?
        price=data.current(sid,"price")
#=============================以下计算N============================================
        if context.day_n>=2:
            n_days=np.maximum(context.day_n,20)
            base_data=data.history(sid,['high','low','close'],int(n_days+1),'1d')
            context.tr_all=[]#清空
            for d in range(1,(n_days+1)):  
                price_h=base_data['high'][-d]#每次覆盖
                price_l=base_data['low'][-d]
                price_c2=base_data['close'][-d-1]
                h_l=np.array(price_h-price_l)
                P_l=np.array(price_c2-price_l)
                h_p=np.array(price_h-price_c2)
                temp=np.maximum(h_l,P_l,h_p)
                context.tr_all.append(temp)
            context.N=np.mean(np.array(context.tr_all))
   
  #==============================以下是止损模块============================================  
            context.stoped=[]#每天清空一下
            buy_stop_loss_price=last_in_price-(2*context.N)
           
            if price<buy_stop_loss_price and cur_position > 0 and data.can_trade(sid):
                context.order_target_percent(sid,0)
                context.stoped.append(i)
                del context.in_price[i]#去除键组
            
 
  #=========================以下是开仓/加仓/退出 模块======================================  
            in_days_high=data.history(sid,'close',in_days_num,'1d').max()
            out_days_low=data.history(sid,'close',out_days_num,'1d').min()
      
    #先多开后空平
            if price > in_days_high and cur_position==0 and data.can_trade(sid):#开仓
                context.order(sid,100)
                context.in_price[i]=price
         
            if price > last_in_price+0.5*context.N  and cur_position>0 and data.can_trade(sid):#加仓
                context.order(sid,100)
                context.in_price[i]=price

            elif price < out_days_low and cur_position>0 and data.can_trade(sid) and i not in context.stoped:#退出
                context.order_target_percent(sid,0)
                del context.in_price[i]#去除键组

#============================开仓模块结束========================================== 
 
    #for instrument in instruments:
 
# 3. 启动回测

# 策略回测接口: https://bigquant.com/docs/module_trade.html
m = M.trade.v2(
    instruments=instruments,
    start_date=start_date,
    end_date=end_date,
    initialize=initialize,
    handle_data=handle_data,
    # 买入订单以开盘价成交
    order_price_field_buy='open',
    # 卖出订单以开盘价成交
    order_price_field_sell='open',
    capital_base=capital_base,
    benchmark=benchmark,
)
[2017-11-22 12:50:03.249735] INFO: bigquant: backtest.v7 开始运行..
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-2-e6ad785b088f> in <module>()
     97     order_price_field_sell='open',
     98     capital_base=capital_base,
---> 99     benchmark=benchmark,
    100 )

<ipython-input-2-e6ad785b088f> in handle_data(context, data)
     64   #=========================以下是开仓/加仓/退出 模块======================================
     65             in_days_high=data.history(sid,'close',in_days_num,'1d').max()
---> 66             out_days_low=data.history(sid,'close',out_days_num,'1d').min()
     67 
     68     #先多开后空平

KeyboardInterrupt: 
In [1]:
# 1. 策略基本参数

start_date = '2017-06-01'
end_date = '2017-11-01'
benchmark = '000300.INDX'
#instruments=['600000.SHA']
#instruments=['600000.SHA','600519.SHA']
#instruments=['200725.SZA']
#instruments=['600000.SHA','600519.SHA','200017.SZA']
instruments=D.instruments(start_date,end_date)
capital_base = 1000000

# 2. 策略主体函数
# 初始化虚拟账户状态,只在第一个交易日运行
def initialize(context):
    # 设置手续费,买入时万3,卖出是千分之1.3,不足5元以5元计
    context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))
    context.tr_all=list() #记录每天振幅
    context.tr_num=20 # 要几天的TR均值
    context.day_n=0 #数天数
    context.N=0.0
    context.stoped=list() #记录当日止*了什么
    context.in_price=dict()#在一个股票的版本里,用数值就够了,这里要变成字典

# 策略交易逻辑,每个交易日运行一次
def handle_data(context, data):
    context.day_n=context.day_n+1
    in_days_num=20 # 55日进,20日出
    out_days_num=5
    for i in instruments:
        sid=context.symbol(i)
        try:
            last_in_price=context.in_price[i]#每次覆盖
        except KeyError:
            last_in_price=0
        cur_position=context.portfolio.positions[sid].amount#为啥这里的sid用[]?因为 是dict?
        price=data.current(sid,"price")
#=============================以下计算N============================================
        if context.day_n>=2:
            n_days=np.maximum(context.day_n,20)
            base_data=data.history(sid,['high','low','close'],int(n_days+1),'1d')
            context.tr_all=[]#清空
            for d in range(1,(n_days+1)):  
                price_h=base_data['high'][-d]#每次覆盖
                price_l=base_data['low'][-d]
                price_c2=base_data['close'][-d-1]
                h_l=np.array(price_h-price_l)
                P_l=np.array(price_c2-price_l)
                h_p=np.array(price_h-price_c2)
                temp=np.maximum(h_l,P_l,h_p)
                context.tr_all.append(temp)
            context.N=np.mean(np.array(context.tr_all))
   
  #==============================以下是止损模块============================================  
            context.stoped=[]#每天清空一下
            buy_stop_loss_price=last_in_price-(2*context.N)
           
            if price<buy_stop_loss_price and cur_position > 0 and data.can_trade(sid):
                context.order_target_percent(sid,0)
                context.stoped.append(i)
                del context.in_price[i]#去除键组
            
 
  #=========================以下是开仓/加仓/退出 模块======================================  
            in_days_high=data.history(sid,'close',in_days_num,'1d').max()
            out_days_low=data.history(sid,'close',out_days_num,'1d').min()
      
    #先多开后空平
            if price > in_days_high and cur_position==0 and data.can_trade(sid):#开仓
                context.order(sid,100)
                context.in_price[i]=price
         
            if price > last_in_price+0.5*context.N  and cur_position>0 and data.can_trade(sid):#加仓
                context.order(sid,100)
                context.in_price[i]=price

            elif price < out_days_low and cur_position>0 and data.can_trade(sid) and i not in context.stoped:#退出
                context.order_target_percent(sid,0)
                del context.in_price[i]#去除键组

#============================开仓模块结束========================================== 
 
    #for instrument in instruments:
 
# 3. 启动回测

# 策略回测接口: https://bigquant.com/docs/module_trade.html
m = M.trade.v2(
    instruments=instruments,
    start_date=start_date,
    end_date=end_date,
    initialize=initialize,
    handle_data=handle_data,
    # 买入订单以开盘价成交
    order_price_field_buy='open',
    # 卖出订单以开盘价成交
    order_price_field_sell='open',
    capital_base=capital_base,
    benchmark=benchmark,
)
[2017-11-22 12:19:01.818378] INFO: bigquant: backtest.v7 开始运行..
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-1-621e12b308a6> in <module>()
     97     order_price_field_sell='open',
     98     capital_base=capital_base,
---> 99     benchmark=benchmark,
    100 )

<ipython-input-1-621e12b308a6> in handle_data(context, data)
     77             elif price < out_days_low and cur_position>0 and data.can_trade(sid) and i not in context.stoped:#退出
     78                 context.order_target_percent(sid,0)
---> 79                 del context.in_price[i]#去除键组
     80 
     81 #============================开仓模块结束==========================================

KeyError: '002134.SZA'

(小Q) #2

因为是这样的context.in_price是字典,但是sid的类型是equity,不能作为键名。建议修改为context.in_price[sid.symbol]

克隆策略
In [58]:
# 1. 策略基本参数

start_date = '2017-01-01'
end_date = '2017-10-01'
benchmark = '000300.INDX'
instruments=['000002.SZA']
capital_base = 100000

 
def initialize(context):
    print('debug initialize')
    context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))
    context.tr_all=list() #记录每天振幅
    context.tr_num=20 # 要几天的TR均值
    context.day_n=0 #数天数
    context.N=0.0
    context.stoped=list() #记录当日止*了什么
    context.in_price=dict()#在一个股票的版本里,用数值就够了,这里要变成字典

# 策略交易逻辑,每个交易日运行一次
def handle_data(context, data):
    print(data.current_dt)
    context.day_n=context.day_n+1
    in_days_num=20 # 55日进,20日出
    out_days_num = 55
    for i in instruments:
        
        sid=context.symbol(i)
        cur_position=context.portfolio.positions[sid].amount#为啥这里的sid用[]?因为 是dict?
        price=data.current(sid,"price")
#=============================以下计算N============================================
        if context.day_n>=2:
           
            n_days=np.maximum(context.day_n,20)
            base_data=data.history(sid,['high','low','close'],int(n_days+1),'1d')
            
            for d in range(1,(n_days+1)): 
                
                price_h=base_data['high'][-d]#每次覆盖
               
                price_l=base_data['low'][-d]
                price_c2=base_data['close'][-d-1]
                h_l=np.array(price_h-price_l)
                P_l=np.array(price_c2-price_l)
                h_p=np.array(price_h-price_c2)
                temp=np.maximum(h_l,P_l,h_p)
                context.tr_all.append(temp)
          
   
  #==============================以下是止损模块============================================ 
           
            context.stoped = [] #每天清空一下
            
            try:  # 建议了解python的容错处理机制
                buy_stop_loss_price=context.in_price[sid.symbol]-(2*context.N)
            except KeyError:
                buy_stop_loss_price = 0
            if price<buy_stop_loss_price and cur_position > 0 and data.can_trade(sid):
                
                context.order_target_percent(sid,0)
                context.stoped.append(sid.symbol)
                del context.in_price[sid.symbol]#去除键组
            
 
  #=========================以下是开仓/加仓/退出 模块======================================  
            in_days_high=data.history(sid,'close',in_days_num,'1d').max()
            out_days_low=data.history(sid,'close',out_days_num,'1d').min()
           
            try:
      
    #先多开后空平
                if price > in_days_high and cur_position==0 and data.can_trade(sid):#开仓
                    context.order(sid,100)
                    context.in_price[sid.symbol]=price
         
                elif price > context.in_price[sid.symbol]+0.5*context.N  and cur_position>0 and data.can_trade(sid):#加仓
                    context.order(sid,100)
                    context.in_price[sid.symbol]=price
                
            
                elif price < out_days_low and cur_position>0 and data.can_trade(sid) and sid.symbol not in context.stoped:
                    
                    context.order_target_percent(sid,0)
                    del context.in_price[sid.symbol]#去除键组
            except:
                pass

 

 
m = M.trade.v3(
    instruments=instruments,
    start_date=start_date,
    end_date=end_date,
    initialize=initialize,
    handle_data=handle_data,
    order_price_field_buy='open',
    order_price_field_sell='open',
    capital_base=capital_base,
)
[2017-11-18 15:45:32.534952] INFO: bigquant: backtest.v7 开始运行..
debug initialize
2017-01-03 20:00:00+00:00
2017-01-04 20:00:00+00:00
debug here
2017-01-05 20:00:00+00:00
debug here
2017-01-06 20:00:00+00:00
debug here
2017-01-09 20:00:00+00:00
debug here
2017-01-10 20:00:00+00:00
debug here
2017-01-11 20:00:00+00:00
debug here
2017-01-12 20:00:00+00:00
debug here
2017-01-13 20:00:00+00:00
debug here
2017-01-16 20:00:00+00:00
debug here
2017-01-17 20:00:00+00:00
debug here
2017-01-18 20:00:00+00:00
debug here
2017-01-19 20:00:00+00:00
debug here
/var/app/enabled/pandas/tseries/index.py:817: PerformanceWarning: Non-vectorized DateOffset being applied to Series or DatetimeIndex
  "or DatetimeIndex", PerformanceWarning)
/var/app/enabled/empyrical/stats.py:534: RuntimeWarning: invalid value encountered in double_scalars
  sortino = mu / dsr
2017-01-20 20:00:00+00:00
debug here
2017-01-23 20:00:00+00:00
debug here
2017-01-24 20:00:00+00:00
debug here
2017-01-25 20:00:00+00:00
debug here
2017-01-26 20:00:00+00:00
debug here
2017-02-03 20:00:00+00:00
debug here
2017-02-06 20:00:00+00:00
debug here
2017-02-07 20:00:00+00:00
debug here
2017-02-08 20:00:00+00:00
debug here
2017-02-09 20:00:00+00:00
debug here
2017-02-10 20:00:00+00:00
debug here
2017-02-13 20:00:00+00:00
debug here
2017-02-14 20:00:00+00:00
debug here
2017-02-15 20:00:00+00:00
debug here
2017-02-16 20:00:00+00:00
debug here
2017-02-17 20:00:00+00:00
debug here
2017-02-20 20:00:00+00:00
debug here
2017-02-21 20:00:00+00:00
debug here
2017-02-22 20:00:00+00:00
debug here
2017-02-23 20:00:00+00:00
debug here
2017-02-24 20:00:00+00:00
debug here
2017-02-27 20:00:00+00:00
debug here
2017-02-28 20:00:00+00:00
debug here
2017-03-01 20:00:00+00:00
debug here
2017-03-02 20:00:00+00:00
debug here
2017-03-03 20:00:00+00:00
debug here
2017-03-06 20:00:00+00:00
debug here
2017-03-07 20:00:00+00:00
debug here
2017-03-08 20:00:00+00:00
debug here
2017-03-09 20:00:00+00:00
debug here
2017-03-10 20:00:00+00:00
debug here
2017-03-13 19:00:00+00:00
debug here
2017-03-14 19:00:00+00:00
debug here
2017-03-15 19:00:00+00:00
debug here
2017-03-16 19:00:00+00:00
debug here
2017-03-17 19:00:00+00:00
debug here
2017-03-20 19:00:00+00:00
debug here
2017-03-21 19:00:00+00:00
debug here
2017-03-22 19:00:00+00:00
debug here
2017-03-23 19:00:00+00:00
debug here
2017-03-24 19:00:00+00:00
debug here
2017-03-27 19:00:00+00:00
debug here
2017-03-28 19:00:00+00:00
debug here
2017-03-29 19:00:00+00:00
debug here
2017-03-30 19:00:00+00:00
debug here
2017-03-31 19:00:00+00:00
debug here
2017-04-05 19:00:00+00:00
debug here
2017-04-06 19:00:00+00:00
debug here
2017-04-07 19:00:00+00:00
debug here
2017-04-10 19:00:00+00:00
debug here
2017-04-11 19:00:00+00:00
debug here
2017-04-12 19:00:00+00:00
debug here
2017-04-13 19:00:00+00:00
debug here
2017-04-14 19:00:00+00:00
debug here
2017-04-17 19:00:00+00:00
debug here
2017-04-18 19:00:00+00:00
debug here
2017-04-19 19:00:00+00:00
debug here
2017-04-20 19:00:00+00:00
debug here
2017-04-21 19:00:00+00:00
debug here
2017-04-24 19:00:00+00:00
debug here
2017-04-25 19:00:00+00:00
debug here
2017-04-26 19:00:00+00:00
debug here
2017-04-27 19:00:00+00:00
debug here
2017-04-28 19:00:00+00:00
debug here
2017-05-02 19:00:00+00:00
debug here
2017-05-03 19:00:00+00:00
debug here
2017-05-04 19:00:00+00:00
debug here
2017-05-05 19:00:00+00:00
debug here
2017-05-08 19:00:00+00:00
debug here
2017-05-09 19:00:00+00:00
debug here
2017-05-10 19:00:00+00:00
debug here
2017-05-11 19:00:00+00:00
debug here
2017-05-12 19:00:00+00:00
debug here
2017-05-15 19:00:00+00:00
debug here
2017-05-16 19:00:00+00:00
debug here
2017-05-17 19:00:00+00:00
debug here
2017-05-18 19:00:00+00:00
debug here
2017-05-19 19:00:00+00:00
debug here
2017-05-22 19:00:00+00:00
debug here
2017-05-23 19:00:00+00:00
debug here
2017-05-24 19:00:00+00:00
debug here
2017-05-25 19:00:00+00:00
debug here
2017-05-26 19:00:00+00:00
debug here
2017-05-31 19:00:00+00:00
debug here
2017-06-01 19:00:00+00:00
debug here
2017-06-02 19:00:00+00:00
debug here
2017-06-05 19:00:00+00:00
debug here
2017-06-06 19:00:00+00:00
debug here
2017-06-07 19:00:00+00:00
debug here
2017-06-08 19:00:00+00:00
debug here
2017-06-09 19:00:00+00:00
debug here
2017-06-12 19:00:00+00:00
debug here
2017-06-13 19:00:00+00:00
debug here
2017-06-14 19:00:00+00:00
debug here
2017-06-15 19:00:00+00:00
debug here
2017-06-16 19:00:00+00:00
debug here
2017-06-19 19:00:00+00:00
debug here
2017-06-20 19:00:00+00:00
debug here
2017-06-21 19:00:00+00:00
debug here
2017-06-22 19:00:00+00:00
debug here
2017-06-23 19:00:00+00:00
debug here
2017-06-26 19:00:00+00:00
debug here
2017-06-27 19:00:00+00:00
debug here
2017-06-28 19:00:00+00:00
debug here
2017-06-29 19:00:00+00:00
debug here
2017-06-30 19:00:00+00:00
debug here
2017-07-03 19:00:00+00:00
debug here
2017-07-04 19:00:00+00:00
debug here
2017-07-05 19:00:00+00:00
debug here
2017-07-06 19:00:00+00:00
debug here
2017-07-07 19:00:00+00:00
debug here
2017-07-10 19:00:00+00:00
debug here
2017-07-11 19:00:00+00:00
debug here
2017-07-12 19:00:00+00:00
debug here
2017-07-13 19:00:00+00:00
debug here
2017-07-14 19:00:00+00:00
debug here
2017-07-17 19:00:00+00:00
debug here
2017-07-18 19:00:00+00:00
debug here
2017-07-19 19:00:00+00:00
debug here
2017-07-20 19:00:00+00:00
debug here
2017-07-21 19:00:00+00:00
debug here
2017-07-24 19:00:00+00:00
debug here
2017-07-25 19:00:00+00:00
debug here
2017-07-26 19:00:00+00:00
debug here
2017-07-27 19:00:00+00:00
debug here
2017-07-28 19:00:00+00:00
debug here
2017-07-31 19:00:00+00:00
debug here
2017-08-01 19:00:00+00:00
debug here
2017-08-02 19:00:00+00:00
debug here
2017-08-03 19:00:00+00:00
debug here
2017-08-04 19:00:00+00:00
debug here
2017-08-07 19:00:00+00:00
debug here
2017-08-08 19:00:00+00:00
debug here
2017-08-09 19:00:00+00:00
debug here
2017-08-10 19:00:00+00:00
debug here
2017-08-11 19:00:00+00:00
debug here
2017-08-14 19:00:00+00:00
debug here
2017-08-15 19:00:00+00:00
debug here
2017-08-16 19:00:00+00:00
debug here
2017-08-17 19:00:00+00:00
debug here
2017-08-18 19:00:00+00:00
debug here
2017-08-21 19:00:00+00:00
debug here
2017-08-22 19:00:00+00:00
debug here
2017-08-23 19:00:00+00:00
debug here
2017-08-24 19:00:00+00:00
debug here
2017-08-25 19:00:00+00:00
debug here
2017-08-28 19:00:00+00:00
debug here
2017-08-29 19:00:00+00:00
debug here
2017-08-30 19:00:00+00:00
debug here
2017-08-31 19:00:00+00:00
debug here
2017-09-01 19:00:00+00:00
debug here
2017-09-04 19:00:00+00:00
debug here
2017-09-05 19:00:00+00:00
debug here
2017-09-06 19:00:00+00:00
debug here
2017-09-07 19:00:00+00:00
debug here
2017-09-08 19:00:00+00:00
debug here
2017-09-11 19:00:00+00:00
debug here
2017-09-12 19:00:00+00:00
debug here
2017-09-13 19:00:00+00:00
debug here
2017-09-14 19:00:00+00:00
debug here
2017-09-15 19:00:00+00:00
debug here
2017-09-18 19:00:00+00:00
debug here
2017-09-19 19:00:00+00:00
debug here
2017-09-20 19:00:00+00:00
debug here
2017-09-21 19:00:00+00:00
debug here
2017-09-22 19:00:00+00:00
debug here
2017-09-25 19:00:00+00:00
debug here
2017-09-26 19:00:00+00:00
debug here
2017-09-27 19:00:00+00:00
debug here
2017-09-28 19:00:00+00:00
debug here
2017-09-29 19:00:00+00:00
debug here
[2017-11-18 15:45:37.024346] INFO: Performance: Simulated 184 trading days out of 184.
[2017-11-18 15:45:37.025238] INFO: Performance: first open: 2017-01-03 14:30:00+00:00
[2017-11-18 15:45:37.026052] INFO: Performance: last close: 2017-09-29 19:00:00+00:00
/var/app/enabled/pandas/core/generic.py:1138: PerformanceWarning: 
your performance may suffer as PyTables will pickle object types that it cannot
map directly to c-types [inferred_type->mixed,key->block4_values] [items->['LOG', 'POS_FAC', 'TRA_FAC', 'orders', 'period_label', 'positions', 'transactions']]

  return pytables.to_hdf(path_or_buf, key, self, **kwargs)
/var/app/enabled/pandas/core/indexing.py:141: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  self._setitem_with_indexer(indexer, value)
  • 收益率22.75%
  • 年化收益率32.41%
  • 基准收益率15.9%
  • 阿尔法0.38
  • 贝塔-0.57
  • 夏普比率0.31
  • 收益波动率90.4%
  • 信息比率0.11
  • 最大回撤20.74%
[2017-11-18 15:45:37.605470] INFO: bigquant: backtest.v7 运行完成[5.070502s].

(iQuant) #3

建议把策略整理下,重新帮你写个策略代码。你的这个版本问题较多。


(xiaoxiao2017) #4

嗯,我正在学习如何写策略,是有比较多的问题。请问怎么改进,提升?谢谢。


(xiaoxiao2017) #5

谢谢。如果我去掉try-except字段,就会显示:KeyError: ‘000002.SZA’,这是为什么?


(xiaoxiao2017) #6

您好,我是想执行这样的策略:
所有沪深股票都判断一遍,
在cash>0的情况下,如果有符合规则的就执行。
N=20日振幅的均值
振幅:max(昨日最高-昨日最低,昨日最高-前日收盘价,前日收盘价-昨日最低)

先买入,再卖出的逻辑:
入场点:当前价格>55日内的最高值(做多一份)
加仓点:当前价格>上一次执行价格+0.5N
出场点:当前价格<20日内最低值
止损点:当前价格<上一次执行价格-2N

每份量:capital_base*0.01/N,取整
最多持有4份

以后还希望加上:
先卖出,再买入的逻辑:
入场点:当前价格<55日内的最低值(做空一份)
加仓点:当前价格<上一次执行价格-0.5N
出场点:当前价格>20日最高值
止损点:当前价格>上一次执行价格+2N

请问怎么能实现?谢谢。


(copen) #7

因为你的字典没有这个键名啊


(xiaoxiao2017) #8

我在开仓和加仓的模块里有写这个…我以为的是已经造了dict的键名和值…


(xiaoxiao2017) #9

我知道了,第一次运行的时候是没有这个键名,所以要用try-except跳过去,谢谢~


(xiaoxiao2017) #10

这个问题解决啦~谢谢:)