To execute a rebalance backtesting I've setup the following codes. The aim is to get a backtesting on two stratgies (bonds and equities), where the rebalancing is executed quarterly. Rebalancing means bring the alloction back to 20% Bonds and 80% Equity.
import pandas as pd
import numpy as np
import datetime as datetime
import statsmodels.api as sm
from scipy import stats
import matplotlib.pyplot as plt
import matplotlib
import seaborn as sn
!pip install bt
import bt as bt
data_bt=pd.read_excel("/content/drive/MyDrive/CFDS/Projekt/Daten/SAAbacktest.xlsx")
data_bt["date"]=pd.to_datetime(data_bt["date"])
data_bt=data_bt.set_index("date")
weights=data_bt.copy()
weights["Bonds"]=0.2
weights["Equities"]=0.8
data_bt
data_bt looks like:
[1
s=bt.Strategy("s1",[bt.algos.SelectAll(),
bt.algos.RunQuarterly,
bt.algos.WeighTarget(weights),
bt.algos.Rebalance()])
test=bt.Backtest(s,data_bt)
res=bt.run(test)
After running "res=bt.run(test) I get: KeyError: "Cannot get right slice bound for non-unique label: Timestamp('2020-12-31 00:00:00')"
What do I have to change in my dataFrame?