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
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]