问答交流

多个模型的结果加在一起出错

由xuliang创建,最终由small_q 被浏览 57 用户

                                            


def MyJoin(data1, data2, onKey =  ["instrument", "date"], how = "left"):
    name1 = list(data1.columns)
    name2 = list(data2.columns)

    nameDiff = list(set(name2) - set(name1))
    
    ##print(nameDiff)
    
    nameDiff.append("instrument")
    nameDiff.append("date")
    
    data3 = data2[nameDiff]
    
    ##data4 = data1.join(data3, on =["instrument", "date"] ,how = "left")  ## join 
    data4 = pd.merge(data1, data3, on = onKey, how = how)
    
    return(data4)


def MyHash(s:str)->int:
    return int(hash(s))

def FilterTrueIndex(arr:list)->list:
    
    ret = []
    for i in range(0, len(arr)):
        if arr[i] == True:
            ret.append(i)
    return(ret)

def Sample10Pct(data1):
    arr1 = zip(list(data1["instrument"]), list(data1["date"]))
    arr2 = list(map(lambda x: True if MyHash(str(x)) % 10 ==1 else False , arr1))
    arr3 = FilterTrueIndex(arr2)
    data2 = data1.iloc[arr3]
    return(data2)




# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
def bigquant_run(input_1, input_2, input_3):
    # 示例代码如下。在这里编写您的代码
    df1 = input_1.read()
    df2 = input_2.read()
    df3 = input_3.read()
    
    nRow = df1.shape[0]
    df1["r"] = range(0, nRow)
    
    df1["pred_label1"] = df1["pred_label"]
    df2["pred_label2"] = df2["pred_label"]
    df3["pred_label3"] = df3["pred_label"]
    
    df20 = MyJoin(df1, df2)
    df30 = MyJoin(df20, df3)
    df30["pred_label"] = (df30["pred_label1"] + df30["pred_label2"] + df30["pred_label3"]) /3 
    df30.sort_values("r", inplace=True)
    
    del df30["pred_label1"]
    del df30["pred_label2"]
    del df30["pred_label3"]
    del df30["r"]
    
    output = DataSource.write_pickle(df30)
    return Outputs(data_1=output, data_2=None, data_3=None)

回测模块报错》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》

》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》


[2022-12-13 21:17:48.642399] ERROR: moduleinvoker: module name: backtest, module version: v8, trackeback: tables.exceptions.HDF5ExtError: HDF5 error back trace

File "H5F.c", line 509, in H5Fopen unable to open file File "H5Fint.c", line 1400, in H5F__open unable to open file File "H5Fint.c", line 1700, in H5F_open unable to read superblock File "H5Fsuper.c", line 411, in H5F__super_read file signature not found

End of HDF5 error back trace

Unable to open/create file '/tmp/data.h5'

During handling of the above exception, another exception occurred:

IndexError: tuple index out of range [2022-12-13 21:17:48.650986] ERROR: moduleinvoker: module name: trade, module version: v4, trackeback: tables.exceptions.HDF5ExtError: HDF5 error back trace

File "H5F.c", line 509, in H5Fopen unable to open file File "H5Fint.c", line 1400, in H5F__open unable to open file File "H5Fint.c", line 1700, in H5F_open unable to read superblock File "H5Fsuper.c", line 411, in H5F__super_read file signature not found

End of HDF5 error back trace

Unable to open/create file '/tmp/data.h5'

During handling of the above exception, another exception occurred:

IndexError: tuple index out of range


\

评论
  • 你好,您这边分享的是网站网址,分享策略点击右上角分享按钮获取链接 ![{w:100}](/wiki/api/attachments.redirect?id=b7ed5762-0714-456a-87dd-51946247bf16)
  • 你好,这个策略里面的random forest模型我没有复现不了这个策略,你这边可以把DataSource.write_pickle(df30)返回的结果发给我一下吗?会有一串字符。 ![{w:100}](/wiki/api/attachments.redirect?id=c0e222e0-7c10-4f6a-b8e6-5e21d1a5a5b3)
  • DataSource(9bf20323795f44cda099536434eeb5bdT)
  • 您看下,是这个不?
  • haode , xiexie
{link}