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/

    Multiple strategies on single data

    Indicators/Strategies/Analyzers
    3
    7
    1108
    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.
    • Yury Tsar
      Yury Tsar last edited by

      Hi,
      does anyone have idea how to implement different strategies on single data feed ?
      For example if I want to do backtesting with different stop loss % and get results through analyzers.

      B 1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        If your strategies are completely different you may just add all of them to cerebro - each one will be given the same data feed upon start, also each strategy's next method will be called once for each update in the data feed.
        Alternatively you may use a more advanced technique described here: (https://www.backtrader.com/blog/posts/2016-10-29-strategy-selection/strategy-selection/) and here: (https://www.backtrader.com/blog/posts/2017-05-16-stsel-revisited/stsel-revisited/)

        In case the only difference between your strategies is in a single parameter (% stop loss) you may set it as a parameter of the same strategy like:

        class MyStrategy(bt.Strategy):
            params = (
                ('stop_loss_percent', 0.96),
            )
        

        and use the cerebro.optstrategy instead of using cerebro.addstrategy. The 'optstrategy' method accepts a range for each strategy's parameter and will instantiate the same strategy for each value of the parameter in the above range. See more info here: (https://www.backtrader.com/docu/cerebro/)

        Yury Tsar 2 Replies Last reply Reply Quote 2
        • Yury Tsar
          Yury Tsar @vladisld last edited by

          @vladisld
          It doesn't really work.
          Strategies exactly same, just with different stop loss.
          In case as you described, Cerebro will share same position across multiple strategies.

          B 1 Reply Last reply Reply Quote 0
          • Yury Tsar
            Yury Tsar @vladisld last edited by

            @vladisld
            question was how to run them simultaneously, not using iteration 1 after another.
            If you are working with very big dataset of OHLC you want to avoid candles iteration as much as possible, if only stop loss pct is different.

            vladisld 1 Reply Last reply Reply Quote 0
            • vladisld
              vladisld @Yury Tsar last edited by

              @Yury-Tsar said in Multiple strategies on single data:

              @vladisld
              question was how to run them simultaneously, not using iteration 1 after another.

              This wasn't clear from the original question:

              @Yury-Tsar said in Multiple strategies on single data:

              how to implement different strategies on single data feed

              In case you would like to backtest the same strategy with a different parameters, where each run of the strategy will have its own position, and all of them will be run simultaneously, but still having the same "big OHLC" data loaded just once - this is exactly were the cerebro.optstrategy comes to rescue. Cerebro engine could be setup to preload the data feed (so that it will be read just once) and each strategy instance will run in its own process - all of them running simultaneously as you wished.

              Am I still getting your question wrong ?

              1 Reply Last reply Reply Quote 2
              • B
                backtrader administrators @Yury Tsar last edited by

                @Yury-Tsar said in Multiple strategies on single data:

                For example if I want to do backtesting with different stop loss % and get results through analyzers

                You obviously want to optimize.

                • https://www.backtrader.com/docu/quickstart/quickstart/#lets-optimize

                The data (if pre-loadable) is only loaded once and shared across the strategies, which will in turn use all your cores unless you explicitly disable that behavior.

                The data has to be iterated because there is ML (Magic Logic) or AI (Awesome Implementation) which can do it otherwise.

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

                  @Yury-Tsar said in Multiple strategies on single data:

                  In case as you described, Cerebro will share same position across multiple strategies.

                  What @vladisld pointed you to won't share the same position across multiple strategies. You may want to read the articles in detail. It doesn't in case apply to your single stop-loss optimization goal.

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
                  $(document).ready(function () { app.coldLoad(); }); }