Implementing strategy entirely from external files



  • Backtrader newbie here. Does anyone have any examples of feeding in strategies from an external file?

    I am primarily interested in historical backtesting in batch. I currently have a complicated modeling process that runs in other software and it would be difficult to execute in line with backtrader, as I've seen in the tutorial examples.

    It is driven on the same data feed that I would use in backtrader. So the first solution that comes to mind is to write the indicators in my custom software in a form that could be directly consumed by backtrader. Then, I'd just read them from the file/join them in as the "strategy."

    Any guidance on this appreciated!

    Thanks,

    Chris



  • There are two posts about that:

    But since you say:

    @kctrader said in Implementing strategy entirely from external files:

    So the first solution that comes to mind is to write the indicators in my custom software in a form that could be directly consumed by backtrader. Then, I'd just read them from the file/join them in as the "strategy."

    You may actually be looking at having an indicator that delivers signals (or simply values) at given moments in time, I guess the approach would be:

    • Load the data for the indicator in __init__ from the external source. It will contain timestamped values.
    • When the next of your indicator is called, check the timestamp of the data and if it maches the timestamp of your external data source ... deliver the value

    If your external data source delivers data with gaps (for example several bars without a value), you should consider if you want that to remain as NaN or you want to deliver something like a no-op in those occasions (0 for example)


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.