I am trying to backtest some trading data using the bt module. When I run the script, it says "unhashable type: Series".
This is my data: Trading Data
This is my code:
data5 = pd.read_csv("export.csv", index_col="Date", parse_dates=True)
data5["SMA_long"] = talib.SMA(data5["Close"], timeperiod=50)
data5["SMA_short"] = talib.SMA(data5["Close"], timeperiod=20)
signal = data5["SMA_long"].copy()
signal[data5["SMA_long"] > data5["SMA_short"]] = 1
signal[data5["SMA_long"] < data5["SMA_short"]] = -1
bt_strategy = bt.Strategy(
'EMA_crossover', [bt.algos.WeighTarget(signal), bt.algos.Rebalance()])
bt_backtest = bt.Backtest(bt_strategy, data5, "test", 1000)
bt_result = bt.run(bt_backtest)
the issue is related to the
signal
variable inside your code that is a pandas series and it is unhashable butWeightTarget
requires a hashable input so hope it helps: