Portfolio rebalancing with bandwidth method in python

后端 未结 4 1822
走了就别回头了
走了就别回头了 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:45

    You can use this code to calulate your portfolio at each point in time.

    i = df.index[0]
    df['ibm_prop'] = 0.5/df.ibm.ix[i]
    df['ford_prop'] = 0.5/df.ford.ix[i]
    
    while i:
       try:
          i =  df[abs(1-(df.ibm_prop*df.ibm + df.ford_prop*df.ford)) > tol].index[0]
       except IndexError:
          break
       df['ibm_prop'].ix[i:] = 0.5/df.ibm.ix[i]
       df['ford_prop'].ix[i:] = 0.5/df.ford.ix[i]
    

提交回复
热议问题