Here's an algo for comment/criticism. It allocates the portfolio by minimizing the variance using the square of the return, times its sign:
prices = history(252,'1d','price').as_matrix(context.stocks)
ret = np.diff(prices,axis=0) # daily returns
ret = np.multiply(np.sign(ret),np.square(ret))
It seems to do pretty good job, given that the securities are:
context.stocks = [ sid(19662), # XLY Consumer Discrectionary SPDR Fund
sid(19656), # XLF Financial SPDR Fund
sid(19658), # XLK Technology SPDR Fund
sid(19655), # XLE Energy SPDR Fund
sid(19661), # XLV Health Care SPRD Fund
sid(19657), # XLI Industrial SPDR Fund
sid(19659), # XLP Consumer Staples SPDR Fund
sid(19654), # XLB Materials SPDR Fund
sid(19660)] # XLU Utilities SPRD Fund
There are a number of ways the algo could be improved, including comments, readability, use of the new function scheduler, use of Pandas (?), etc. No time now...feel free to re-factor as you see fit.
Grant