Backtest from pre-specified portfolios
Hi, I'm new to backtrader.
If I have (from external analysis) monthly portfolios (i.e. tables with three columns - one with date, second with ticker, and the third with weights, adding up to 1 within each 'date') and I want to look at monthly returns -- is there a way to do this in backtrader?
Sure you can do this in
bt. Depending on how your
external analysisdata is structured you may need to write an indicator to read that data, or read that data during strategy
__init()__and then process it in
next(). Having only monthly bars can probably simplify your strategy. Using
Returnsanalyzer with the monthly period you will get your monthly returns. One caveat - prices for all stocks used in your portfolios need to be loaded into
btat the beginning of the backtest. Which is logical approach, but somehow missed.