How to automate the running of backtrader?
-
Hello @backtrader ,
I'd like to automate the running of backtrader in below scenario, may i know if you have any suggestions on how to achieve this?
Suppose i have a csv file which looks like this, basically the csv file has three stock paris.
Stock0 Stock1 IBM AAPl IBM FB IBM GOOG
- Read the csv file which contains the list of stock pairs,
- Take the first pair (IBM and AAPL), and feed the codes(IBM, AAPL) into my strategy,
- My strategy loads data for IBM and AAPL, runs and finish,
- Take the second pair(IBM and FB), and feed the codes(IBM, FB) into my strategy,
- My strategy loads data for IBM and FB, runs and finish
....
Till all the stock pairs are used to run my strategy.
Currently i am just running several files which has same strategy but different data. However it would be great if this can be achieved because the list of pairs could be very large.
My confusion is how best to construct this loop on top of backtrader.
This article is helpful, but doesn't address this case.Thank!
-
You are looking at automating a use case, but not at automating backtrader itself, which already runs automatically.
- Take the first pair (IBM and AAPL), and feed the codes(IBM, AAPL) into my strategy,
That doesn't seem what you want to do. See
3
- My strategy loads data for IBM and AAPL, runs and finish,
Strategies don't load data feeds. That's something which
Cerebro
does withaddata
You simply need a loop with your csv file and the list of pairs and inside the loop instantiate
cerebro
, addition of data feeds (addata
), addition of the strategy (addstrategy
), any analyzers you have in mind and thenrun
cerebro.Use any of the recent samples available in the blog and wrap it inside your loop.
-
Many thanks for the prompt reply! I see what you mean, i will try this out.
-
Schedule main loop! I prefer APScheduler as it's flexibily for reports running based on schedule.
-
@Maxim Korobov
Many thanks for the suggestion, i will take a look!