0

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:

[data_bt looks like1

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?

  • Maybe worth mentioning that you're using a rather exotic backtesting package v 0.2.9 without even specifiying what it is supposed to do. As soon as you are able to properly formulate your problem, you will also be able to solve it yourself without bothering others with nebulous posts, Herr Feierabend. – Peter May 15 '21 at 15:41
  • 1
    Sorry Peter, but it's my second question. Let me get some experience. And what backtesting package would you recommend? – Herr Feierabend May 15 '21 at 17:20

0 Answers0