backtesting.py icon indicating copy to clipboard operation
backtesting.py copied to clipboard

[WIP] Feature: Support for multiple Instruments.

Open AgarwalPragy opened this issue 3 years ago • 6 comments

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.

AgarwalPragy avatar May 09 '22 05:05 AgarwalPragy

A parallel effort for the same feature by Robert: https://github.com/kernc/backtesting.py/pull/639

AgarwalPragy avatar May 09 '22 05:05 AgarwalPragy

@kernc would you be willing to accept this PR (once complete)? If you have a better way in mind, please let me know :)

AgarwalPragy avatar May 09 '22 22:05 AgarwalPragy

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.

tumma72 avatar May 24 '22 13:05 tumma72

How is this coming along? @tumma72 @AgarwalPragy

luketych avatar Aug 02 '22 05:08 luketych

How is this coming along? @tumma72 @AgarwalPragy

luketych avatar Aug 02 '22 05:08 luketych

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.

tumma72 avatar Aug 11 '22 12:08 tumma72

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.

dodid avatar Mar 17 '23 07:03 dodid