NexusFi: Find Your Edge


Home Menu

 





Optimizing Multiple Sub-Strategies in one Master Strategy


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one SMCJB with 3 posts (7 thanks)
    2. looks_two ABCTG with 1 posts (2 thanks)
    3. looks_3 vmodus with 1 posts (0 thanks)
    4. looks_4 kevinkdog with 1 posts (4 thanks)
    1. trending_up 4,472 views
    2. thumb_up 13 thanks given
    3. group 4 followers
    1. forum 5 posts
    2. attach_file 4 attachments




 
Search this Thread

Optimizing Multiple Sub-Strategies in one Master Strategy

  #1 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,041 since Dec 2013
Thanks Given: 4,375
Thanks Received: 10,192

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?

@ABCTG, @kevinkdog, @vmodus

Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
Better Renko Gaps
The Elite Circle
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
ZombieSqueeze
Platforms and Indicators
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
60 thanks
Funded Trader platforms
41 thanks
NexusFi site changelog and issues/problem reporting
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #2 (permalink)
 
vmodus's Avatar
 vmodus 
Somewhere, Delaware, USA
 
Experience: Intermediate
Platform: MultiCharts
Broker: Barchart.com
Trading: Everything, it all tastes like chicken
Posts: 1,271 since Feb 2017
Thanks Given: 2,958
Thanks Received: 2,853


SMCJB View Post
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?

@ABCTG, @kevinkdog, @vmodus

Let me think about this and get back to you.

~vmodus

~vmodus

Enjoy everything!
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #3 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,041 since Dec 2013
Thanks Given: 4,375
Thanks Received: 10,192



vmodus View Post
Let me think about this and get back to you.

~vmodus

Thanks


SMCJB View Post
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).

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.

Started this thread Reply With Quote
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

SMCJB,

take a look at the Optimization API as this might give you a bit more control over input ranges that are used in the optimization plus the ability to access results:
https://help.tradestation.com:443/09_05/eng/tsdevhelp/Subsystems/elobject/resources/pdf/easylanguage_optimization_api.pdf

Regards,

ABCTG


SMCJB View Post
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?

@ABCTG, @kevinkdog, @vmodus


Follow me on Twitter Reply With Quote
Thanked by:
  #5 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,647 since Jul 2012
Thanks Given: 1,890
Thanks Received: 7,338


SMCJB View Post
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?

@ABCTG, @kevinkdog, @vmodus


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...

Attached Files
Elite Membership required to download: greatguysean.xls
Follow me on Twitter Reply With Quote
Thanked by:
  #6 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,041 since Dec 2013
Thanks Given: 4,375
Thanks Received: 10,192


ABCTG View Post
take a look at the Optimization API as this might give you a bit more control over input ranges that are used in the optimization plus the ability to access results:
https://help.tradestation.com:443/09_05/eng/tsdevhelp/Subsystems/elobject/resources/pdf/easylanguage_optimization_api.pdf

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.

I couldn't get your link to work but assume that this is the same document.
https://community.tradestation.com/Discussions/DATA/20140911125726EasyLanguage_Optimization_API.pdf

Thank you for your assistance. I will take a further look. There is probably a way to do it programmatically through the API.


kevinkdog View Post
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...

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.

Started this thread Reply With Quote




Last Updated on July 23, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts