我正在尝试将买入信号的负收盘价作为代码的一部分。通常,当我将列添加到DF时,我会执行df [“ ColName”] = buyList,它可以根据我的需要完美运行。但是,由于某种原因,希望您可以帮助我编写此代码,从而产生以下结果。
不是将单个值放在单元格中,而是整个列表。但这不是针对信号列表执行的操作 谁能为我阐明一下? 如何将清单buyList变成df中的一列
signalList = []
buyList = []
sellList = []
for x,i in enumerate(df["Crossover"]):
if i == True:
if df['EMA ' + str(emaShort)].iloc[x] > df['EMA ' + str(emaLong)].iloc[x]:
signal = "Buy"
signalList.append(signal)
buy = -df["Close"]
buyList.append(buy)
sell = 0
sellList.append(sell)
elif df['EMA ' + str(emaShort)].iloc[x] < df['EMA ' + str(emaLong)].iloc[x]:
signal = "Sell"
signalList.append(signal)
buy = 0
buyList.append(buy)
sell = df["Close"]
sellList.append(sell)
elif df['EMA ' + str(emaShort)].iloc[x] == df['EMA ' + str(emaLong)].iloc[x]:
print(df.iloc[x])
print(x)
print("******^^^^^^")
elif i != True:
signal = "None"
signalList.append(signal)
buy = 0
buyList.append(buy)
sell = 0
sellList.append(sell)
df["Signal"] = signalList
df["Long Position"] = buyList