[WIP] Feature: Support for multiple Instruments.
An incomplete attempt to add multiple-instrument backtest, which is mentioned in https://github.com/kernc/backtesting.py/issues/20 and https://github.com/kernc/backtesting.py/discussions/418
Aim: full backwards compatibility
How?
class Backtest will accept data as either a pd.DataFrame or a dictionary containing instrument names (str) and corresponding instrument data (pd.DataFrame). class _Data will follow suit.
class _Data will get a property is_single_instrument which tells us if the single-instrument-mode is enabled.
Internally, all classes will assume that the data is in multi-instrument mode. However, the signatures for methods in the existing API will be extended to return dictionaries instead of single-value if the multi-instrument mode is enabled.
A parallel effort for the same feature by Robert: https://github.com/kernc/backtesting.py/pull/639
@kernc would you be willing to accept this PR (once complete)? If you have a better way in mind, please let me know :)
Wouldn't it be better to have a _Data structure which allow to have multiple _Data with the name of the instrument, within which the _Array will still contain the various Series data. This way the .data.INSTRUMENT.Close will provide the most accurate data for the back testing and you could cycle through the instruments... It seems less complicated to me, and it will incapsulate the complexity.
How is this coming along? @tumma72 @AgarwalPragy
How is this coming along? @tumma72 @AgarwalPragy
To be honest, I gave up trying to bend the beast, and decided to create my own bot, which support backtesting, paper-trading and live-trading using the CCXT Library which works quite well with a number of Exchanges, and it is well maintained.
I made an attempt to support multiple instruments based on kernc's excellent work. See https://github.com/dodid/minitrade The support is quite basic and feedback is welcome on how to make it more useful.