Portfolio rebalancing with bandwidth method in python

后端 未结 4 1832
走了就别回头了
走了就别回头了 2020-12-16 03:03

We need to calculate a continuously rebalanced portfolio of 2 stocks. Lets call them A and B. They shall both have an equal part of the portfolio. So if I have 100$ in my po

4条回答
  •  感情败类
    2020-12-16 03:34

    What about this:

    df["d"]= [0,0,0,0,0,0,0,0,0,0]
    df["t"]= np.arange(len(df))
    tol = 0.05
    
    def flex_relative(x):
        if df.ibm/df.ibm.iloc[df.d].values < df.ford/df.ford.iloc[df.d].values * (1+tol):
            return  df.iloc[df.index.get_loc(x.name) - 1]['d'] == df.t
        elif df.ibm/df.ibm.iloc[df.d].values > df.ford/df.ford.iloc[df.d].values * (1+tol):
            return df.iloc[df.index.get_loc(x.name) - 1]['d'] == df.t
    

提交回复
热议问题