Use opening price for submission check for Market orders when
cheat-on-open is active
Update pnlcomm on all operations and not just profit/loss locking
Correct comment for fillalpha and add baralpha for candlestick opacity
Merge PR 378 (doc typo) PR 378 (rollover for live feeds and tz use
in datetime utilities)
Use internal dict for data feed presence test and update trade observer
I am trying to calculate the covariance matrix of a multiple asset portfolio at every period with N lookback period. My current implementation uses a counter to wait out the lookback period and then runs all calculations in the def next() method.
if (self.counter < self.p.rperiod):
self.counter += 1
# stack the closes together into a numpy array for ease of calculation
closes = np.stack(([d.close.get(0,self.p.rperiod).tolist() for d in self.datas]))
rets = np.diff(np.log(closes))
# covariance matrix. will be shoved somewhere else for records
cov = np.cov(rets)
While it 'works', what is the more backtrader way of doing the same thing?
For example, there's the PctChange indicator for calculating percentage change that is defined at __init__.
rets = [bt.ind.PctChange(d, period=self.p.rperiod) for d in self.datas]
But how do I access the value of N periods of indicators, run calculations, and then construct cross-asset indicators? And would it be possible to have, say, an indicator that contains multidimensional matrices?