Hi Everyone, 

I'm currently working on an allocation strategy (and framework) between algorithms.  Just to illustrate this: Imagine you have one strategy for ranging markets and one for trending markets and some logic/idea on how to switch between those based on how they perform, how do you do that without too much spaghetti code.
Has anyone done that already? Did I miss something in the Lean framework that would allow me to observe the performance of substrategies and switch their weight?

My problem:
I have several QCAlgorithm developed independently, but I would like to switch my cash allocation between those automatically from 0 to 100%. Currently, I do this manually between different IB accounts but I am therefore limited to a handful of strategies for practical reasons.

My goal:
Basically, my allocation model treats each individual algorithm as an asset and then trades/allocate each of those algorithms (long obviously ?). This is more or less a momentum model applied on Portfolios, depending on market regimes some strategies perform better than others.
The issue with the insight model is that while we can have many in a single QCAlgorithm, there is no performance record (that I know of) that can be linked to an Alpha and observed through time to make a decision on the weight to use on the insight.

My ideas/solution/work in progress!
I'm working on a Algo class that implements IAlgorithm and mimics QCAlgorithm so that porting/converting code from a standalone strategy to a multi-strategy is trivial.
I wish we could have multiple QCalgorithm within a project but it is not allowed.
I have a main QCalgorithm that create the many individual Algo classes and dispatches messages to them (OnData mostly) and treats each Strategy as external data with AddData which allows me to treat them as blackbox assets.

I've created a DummyPortfolio that is a much-simplified version of PortfolioSecurityManager and replace the portfolio objection the IAlgorihm implementation. The SetHoldings/Order methods then place trades in this DummyPortfolio recording the algorithm perfomance. There is an additional method that allows for the main QCAlgorithm to query trades that have been made by the strategy. (The DummyPortfolio also deals - or will deal! - with splits and dividends)

The main QCAlgo then decides which weight to use for each Algos and queries trades made by each algo and make convert them in the "real/main" Portfolio.


There are many limitations to this way of doing things (I may not have thought of all of them), what annoys me is the need to duplicate/reimplement some of the Lean code... which may be due to my lack of knowledge/understanding of its inner workings!

I hope this is clear enough. My code is not yet at a stage where I can post anything, but before I commit too much time, I wanted to see if anyone had done something similar successfully before or if anyone can think of a better/simpler way to do it?

Any comments or ideas are appreciated!