Dynamic Asset Allocation Weights Indicator
Ronny Li last edited by
Has anyone here implemented an indicator that returns weights for assets in a portfolio? Here is the Strategy version:
class WeighInverseVol(bt.Strategy): def __init__(self): rs = [bt.ind.PctChange(d.close, period=1) for d in self.datas] vs = [bt.ind.StdDev(ret, period=30) for ret in rs] inv = [bt.DivByZero(bt.LineNum(1), v) for v in vs] invsum = bt.LineNum(0) for inv_ in inv: invsum += inv_ # self.weights is an array of asset allocation weights # one weight per asset in self.datas self.weights = [inv_ / invsum for inv_ in inv]
WeighInverseVolto be an Indicator so I can use it within other strategies but I don't know how to return a dynamic number of lines within an indicator. Any advice?