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
    
    1. Read the csv file which contains the list of stock pairs,
    2. Take the first pair (IBM and AAPL), and feed the codes(IBM, AAPL) into my strategy,
    3. My strategy loads data for IBM and AAPL, runs and finish,
    4. Take the second pair(IBM and FB), and feed the codes(IBM, FB) into my strategy,
    5. 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!


  • administrators

    You are looking at automating a use case, but not at automating backtrader itself, which already runs automatically.

    1. 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

    1. My strategy loads data for IBM and AAPL, runs and finish,

    Strategies don't load data feeds. That's something which Cerebro does with addata

    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 then run cerebro.

    Use any of the recent samples available in the blog and wrap it inside your loop.



  • @backtrader

    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!


Log in to reply
 

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