For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Purpose of adding multiple Strategies



  • I am aware this is probably a stupid question but still:
    What is the (main) purpose of adding multiple strategies to the mix?

    Is the purpose to have relations between strategies? E. g. strategy A only opens a position if strategy B has no positions currently?

    Or is it just for performance reasons? I could imagine that it is faster for backtrader to process multiple strategies using the same data once it has preloaded the data once anyway?
    So in the end it would be (semantically) the same as running the strategies one after the other in that case.


  • administrators

    It's not stupid. It's simply you haven't come across a use case that fits your profile. A potential use case would be a Strategy that only operates when a bullish condition is detected. The second one can act when a bearish condition is detected. In many cases they won't operate simultaneously, but there can be overlapping periods.

    Fully separating the filters that decide what's bullish and what's bearish and the associated logic for each one can help and will also let you assess the performance of each on a separate basis.



  • Thank you, that helped!

    Also I played around with it yesterday and found out (it's probably obvious to you guys) that multiple strategies can influence each other when running in parallel through the broker. When strategies are using the same broker (which is standard, I think), then broker related conditions (like current position) can influence the strategies.


  • administrators

    It is a single account broker!



  • @backtrader said in Purpose of adding multiple Strategies:

    A potential use case would be a Strategy that only operates when a bullish condition is detected. The second one can act when a bearish condition is detected. In many cases they won't operate simultaneously, but there can be overlapping periods.

    I would really like to assimilate this type of architecture in my project. but i'm not sure what is the best approach. I want to have different strategies for different market conditions, so i can analyze each one separately.

    • Backtrader doesn't support sub-strategies so how do we manage which strategy is getting executed on each given condition? (or do we just let each strategy check it's own condition regardless of other strategies, which sound really messy and inefficient)
    • how do we manage buy/sell orders when strategies does overlap? how do we notify the right strategy on any given change? how to prevent conflicting orders or duplicates?

  • administrators

    @jacob said in Purpose of adding multiple Strategies:

    • Backtrader doesn't support sub-strategies so how do we manage which strategy is getting executed on each given condition? (or do we just let each strategy check it's own condition regardless of other strategies, which sound really messy and inefficient)
    • how do we manage buy/sell orders when strategies does overlap? how do we notify the right strategy on any given change? how to prevent conflicting orders or duplicates?

    You create a communication channel for the strategies or a shared data structure that lets you control which strategy can operate and which cannot or if both have to be active or inactive.



  • @backtrader said in Purpose of adding multiple Strategies:

    You create a communication channel for the strategies or a shared data structure that lets you control which strategy can operate and which cannot or if both have to be active or inactive.

    Could you shed some light on how we could go about this.


  • administrators

    Sorry, but I really don't understand what you are expecting ...



  • Sure, i could elaborate....How do i go about creating a) A shared data structure? b) A communication channel ? c) How can I assign the results / output of a cerebro.run to a variable, or store it for subsequent use ?

    I apologise in advance, if my questions are too noob-ie, but i'm looking at a very similar architecture as Jacobs. Will also have to figure out how to work around the GIL (maybe using dask and distributed computing on GCP).

    PS. LOOOOVING bt until now. Clearly the most advanced tool with absolute granularity :)


  • administrators

    @vandan-chopra said in Purpose of adding multiple Strategies:

    a) A shared data structure?

    A dict which lives in the global scope?

    @vandan-chopra said in Purpose of adding multiple Strategies:

    b) A communication channel ?

    A queue.queue or collections.deque to which things are pushed and popped?

    @vandan-chopra said in Purpose of adding multiple Strategies:

    c) How can I assign the results / output of a cerebro.run to a variable, or store it for subsequent use ?

    Accessing the analyzers after running. Docs - Analyzers

    @vandan-chopra said in Purpose of adding multiple Strategies:

    Will also have to figure out how to work around the GIL (maybe using dask and distributed computing on GCP).

    Sorry but this is a very naive statement. Same as those saying they want to run the optimization using the GPU.

    The code has to be specifically written to use specific APIs. And using dask and distributed computing will only help (assuming things have been written so that it can be done) if the datasets are huge. Moving small datasets around will be slower than running synchronously.



  • @backtrader Got it. Thanks a ton for that. I didn't understand it all, but it gives me enough to start researching / learning/ building. :)