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

Running Multiple Strategies & Combining the Output



  • I'm fairly new to BT, and have been able to get the system to start trading, but i am currently only using a couple of signals, and running one strategy. However, I want to run multiple strategies (each of which will each have their own signals, and their own assets / asset classes to trade), and then have these strategies talk to a "mothership" that finally puts all the trading signals and creates a portfolio to execute.

    • My question is, how do i run multiple strategies (read: instances of cerebro) programatically (Not from bash)?

    • How do I then get them to communicate with each other ? Should i be using the logging function to write to file, or use the writer, or move stuff to a shared dictionary? Which would be most memory / compute efficient ? (Especially since each strategy will be spitting data on every time-period, almost like a 'stream').

    • If a shared data structure like dict/list, how/where in my strategy should i be creating these ?

    • Lastly, can i pull something like this off in pure python, or do i need to move towards something like spark/stream



  • @vandan-chopra

    You can load multiple strategies into cerebro as far as I am aware. However, perhaps you just need to rethink your planned architecture?

    If the "mothership" will be finally responsible for buying and selling (creating the portfolio), then it sounds like you just need to generate unique signals on specific data feeds (assets).

    If that is the case, you can create indicators that generate signals according to your buy and sell principles. Then just allocate those indicators to the specific asset classes you are interested in. Finally, in next(), you can look at all of the signals and decide how to build your portfolio. No need for multiple instances.

    Just a suggestion.


  • administrators

    @vandan-chopra said in Running Multiple Strategies & Combining the Output:

    • My question is, how do i run multiple strategies (read: instances of cerebro) programatically (Not from bash)?

    addstrategy - See Docs - Cerebro

    @vandan-chopra said in Running Multiple Strategies & Combining the Output:

    • How do I then get them to communicate with each other ? Should i be using the logging function to write to file, or use the writer, or move stuff to a shared dictionary? Which would be most memory / compute efficient ? (Especially since each strategy will be spitting data on every time-period, almost like a 'stream').

    Writing to a file doesn't seem efficient. Choosing between a shared dict or a queue.queue or collections.deque is up to you. It won't make really a difference.

    @vandan-chopra said in Running Multiple Strategies & Combining the Output:

    • If a shared data structure like dict/list, how/where in my strategy should i be creating these ?

    Pass them as a parameter or create them at global level.

    @vandan-chopra said in Running Multiple Strategies & Combining the Output:

    • Lastly, can i pull something like this off in pure python, or do i need to move towards something like spark/stream

    Don't know why you would need spark or anything else.



  • @thatblokedave Super thanks Dave. This is exactly the direction I have taken, and it's slowing coming together. Will post the code here for everyone else, once i have some confidence in it. But thanks a ton.



  • @backtrader Thanks a ton for that. It does sort out quite a bit for me. Also gives me confidence in you saying that I wouldn't need spark for something like this and that python by itself should be able to handle the load. (Anyways, it's going to be a fairly small system to begin with).

    PS. Looks like i'm going to have to reach out to you again in the future. But SUPER appreciate your response (tipping my hat :)