Im extract a tickers from binance and made a dataframe
Then I used talib to add different indicators to my df.
But when I try to do a backtesting it gave me this error.
enter code here
klines = client.get_historical_klines("BNBUSDT", Client.KLINE_INTERVAL_1DAY, "1 jul, 2021")
df=pd.DataFrame(klines)
df.rename(columns={df.columns[0]: 'open time', df.columns[1]: 'open',df.columns[2]: 'high',df.columns[3]: 'low',df.columns[4]: 'close',df.columns[5]: 'volume'},inplace=True)
import bt
# Define the strategy
bt_strategy = bt.Strategy('AboveSMA',
[bt.algos.SelectWhere(df["close"]> df["MA30"]),
bt.algos.WeighEqually(),
bt.algos.Rebalance()])
# Create the backtest and run it
bt_backtest = bt.Backtest(bt_strategy, df["close"])
bt_result = bt.run(bt_backtest)
# Plot the backtest result
bt_result.plot(title='Backtest result')
plt.show()
Here is a possible solution:
Step 1: Get data from Binance and perform TA calculations.
pandas.DataFrame
talib
operation (here:SMA
)Output, Step 1:
Step 2: Use backtesting from bt
df
object.Output
display()
:Output
plot()
: