@cnimativ said in More Backtrader way to calculate covariance matrix:

My current implementation uses a counter to wait out the lookback period and then runs all calculations in the def next() method.

You should be using the addminperiod API or subclassing from the indicator PeriodN.

@cnimativ said in More Backtrader way to calculate covariance matrix:

While it 'works', what is the more backtrader way of doing the same thing?

You calculate something in next using numpy. What would you be looking for?

@cnimativ said in More Backtrader way to calculate covariance matrix:

But how do I access the value of N periods of indicators, run calculations, and then construct cross-asset indicators?

You are already using get

@cnimativ said in More Backtrader way to calculate covariance matrix:

And would it be possible to have, say, an indicator that contains multidimensional matrices?

Not a clue what you mean. Indicator have lines. You may of course store anything in a member attribute.