To compare the target weights of the algo with the real weights of the positions in the portfolio,
I used my old "All-weather trio", switched it to daily trading 5 minutes before close,
added record_vars on market close, and wrote a simple code similar to the one that Thomas Wiecki used
in recent challenges to find EOD portfolio positions.
def record_vars(context, data):
pos_wt = pd.Series()
for sec in context.portfolio.positions.values():
pos_wt.loc[sec.sid] = sec.amount
pos_wt /= pos_wt.abs().sum()
print("------- pos_wt --------")
print(pos_wt)
You can see the results are significantly different.
2007-06-01 12:55 PRINT ------- target_wt --------
2007-06-01 12:55 PRINT {'QQQ': 0.5}
2007-06-01 12:55 PRINT {'TLT': 0.4}
2007-06-01 12:55 PRINT {'EFA': -0.1}
2007-06-01 12:59 PRINT ------- pos_wt --------
2007-06-01 12:59 PRINT
Equity(19920 [QQQ]) 0.641291
Equity(23921 [TLT]) 0.284409
Equity(22972 [EFA]) -0.074300
dtype: float64
2007-06-04 12:55 PRINT ------- target_wt --------
2007-06-04 12:55 PRINT {'QQQ': 0.5}
2007-06-04 12:55 PRINT {'TLT': 0.4}
2007-06-04 12:55 PRINT {'EFA': -0.1}
2007-06-04 12:59 PRINT ------- pos_wt --------
2007-06-04 12:59 PRINT
Equity(19920 [QQQ]) 0.641291
Equity(23921 [TLT]) 0.284409
Equity(22972 [EFA]) -0.074300
Please correct me if I am wrong, otherwise correct the error.
BTW I have not published this post yet and Algo has already been cloned 124 times, how can this be?