Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals, U308 and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,058 since Dec 2013
Thanks Given: 4,409
Thanks Received: 10,226
Lets assume I have 3 strategies, A, B, and C. Now I want to create a fourth strategy D that is an ensemble / combined voting strategy of A. B and C. For example it might only buy when two or more of A, B and C have buy signals.
Combining A, B and C to create D is quiet easy. Instead of the individual strategies issuing orders you instead have them trigger a -1/0/1 trade flag variable, and then have the order generation based upon the sum of the trade flag variable's.
Question is how do you optimize Strategy D?
- Obviously you can optimize A, B, and C separately and then use / transfer the optimized variables to Strategy D. While this is the obvious way to do this, it involves 3x as many backtests (or walkforwards), is more difficult to track, and more difficult to explain to others.
- If you do a typical optimization of Strategy D, optimizing all the variables of all the sub-strategies, it will optimize the variables so that the combined ensemble has the best profit - ie it will optimize for D not for A, B and C separately - which is obviously very different than optimizing the individual strategies. This is undesirable.
Is there a way I can run an optimization of the sub-strategies A, B, and C all at once as part of master strategy D while maintaining their independence?
I can create a dummy variable, for example iVersion with values 0, 1 or 2. Then when I optimize if iVersion is 0 have the code only optimize sub-strategy A, when 1 have the code only optimize sub-strategy B etc etc. If we assume that all 3 strategies have two variables that each have 3 possible inputs, each strategy has 9 (3x3) scenarios. Hence strategy D actually has 27 (9+9+9) different scenarios. Unfortunately doing it this way yields 729 (9x9x9) different scenarios rather than 27. This is both wastefully computationally and makes reading the results very difficult. The computational issue becomes important when the number of variables increases. If each sub strategy has 3 variables each with 4 possibilities the difference becomes 192 (3x 4x4x4) vs 262,144 (64x64x64).
Anybody know any other way to do this? Can easylanguage remember optimization results during the optimization process? (Obviously I could write them to a text file but that's not much different than the massive optimization report). Is there a way I can get easylanguage to skip certain optimizations? Any other suggestions?
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals, U308 and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,058 since Dec 2013
Thanks Given: 4,409
Thanks Received: 10,226
Thanks
Math is wrong. It's worse than I said.
With 3 Strategies each with two variables each with 3 inputs, D does have 27 (9+9+9) different scenarios. But doing the optimization as above performs 2187 optimizations (3 x 9x9x9) and not 729 as originally said.
With 3 Strategies each with three variables each with 4 inputs, D does have 192 (3x 4x4x4) different scenarios. But doing the optimization as above performs 786,432 optimizations (3 x 64x64x64) and not 262,144 as originally said.
If I understand your problem well, you instead of doing an "orthogonal" type optimization (where every case is computed), you want to only do certain cases (which I assume you know those cases up front).
Here is an example of an orthogonal optimization, with 3 variables (iStratA, iStratB and iStratC) with 2 values each. This produces 8 unique cases:
But let's say you only want the cases highlighted in yellow to be part of your optimization:
To do this, I would have a strategy with one input (which you can "optimize") IMaster. That is your run number, and will go from 1 to the number of iterations you have.
Then, your other inputs (iStratA, iStratB and iStratC above) should be defined as variables - since you are now setting them in code.
I created a spreadsheet for you that will create the code for you once you have defined parameters for each case. You should just be able to copy and paste it into a strategy (you'd have to define IMaster as an input, and iStratA, iStratB and iStratC as variables).
Let me know if this works or not, or if I have misinterpreted what you wanted...
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals, U308 and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,058 since Dec 2013
Thanks Given: 4,409
Thanks Received: 10,226
I am fortunate enough to know two people that have programmed to the Optimization API and to share their work. It really is an amazing tool. Once you have it working, the bigger issues become how to interpret the results as generating tens of thousands of backtests suddenly becomes very easy.
Thank you for your assistance. I will take a further look. There is probably a way to do it programmatically through the API.
In my utopian dream I suppose I was trying to achieve something like the following
In this case SubA would be 1 & 2, SubB would also be 1 & 2 and SubC would be 2 & 1. Hence the actual solution result would be
vSubA_1 = 1
vSubA_2 = 2
vSubB_1 = 1
vSubB_2 = 2
vSubC_1 = 2
vSubC_2 = 1
I had thought of your solution but dismissed it on the grounds that it would be a too difficult to write out all the individual combinations. Your use of concatenating text in excel though is excellent and something that I am going to persue.
Thank You Both for your responses.
Sorry for the edit. Somehow I submitted the reply when I was only half way through.