获取错误语法错误:无效语法>记录目录2[“上限”]。追加(交易目录[“上限”])

2024-03-28 12:03:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我得到一个错误:

SyntaxError: invalid syntax --> record_dict2["upper_band"].append(trade_dict["upper_band"])

我不明白错误在哪里。我试图做的是将数据附加到一个键入record_dict2的列表中

record_dict2 = {"date":[],
                "spread":[],
                "rolling_mean":[],
                "rolling_std":[],
                "upper_band":[],
                "upper_band2":[],
                "upper_band3":[],
                "lower_band":[],
                "lower_band2":[],
                "lower_band3":[],
                "short_con_1":[],
                "short_con_2":[],
                "long_con_1":[],
                "long_con_2":[],
                "trade_exit_time":[],
                "pnl":[]}


trade_dict = backtesting(df,model,window,start,current_date,rolling_window,deviations)
trade_exit_date_time = record_dict["trade_exit_time"]

# append all the info 
record_dict2["date"].append(trade_dict["date"]) 
record_dict2["spread"].append(trade_dict["spread"])
record_dict2["rolling_mean"].append(trade_dict["rolling_mean"])
record_dict2["rolling_std"].append(trade_dict["rolling_std"]
record_dict2["upper_band"].append(trade_dict["upper_band"])