Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    How to automate the running of backtrader?

    General Discussion
    3
    5
    1546
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      derek2017 last edited by derek2017

      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!

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • D
          derek2017 last edited by

          @backtrader

          Many thanks for the prompt reply! I see what you mean, i will try this out.

          1 Reply Last reply Reply Quote 0
          • Maxim Korobov
            Maxim Korobov last edited by

            Schedule main loop! I prefer APScheduler as it's flexibily for reports running based on schedule.

            1 Reply Last reply Reply Quote 0
            • D
              derek2017 last edited by

              @Maxim Korobov

              Many thanks for the suggestion, i will take a look!

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors