Implementing strategy entirely from external files
kctrader last edited by
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!
Paska Houso last edited by
There are two posts about that:
But since you say:
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
nextof 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
NaNor you want to deliver something like a no-op in those occasions (