Optimizing Multiple Sub-Strategies in one Master Strategy - futures io
futures io futures trading



Optimizing Multiple Sub-Strategies in one Master Strategy


Discussion in EasyLanguage Programming

Updated by SMCJB
      Top Posters
    1. looks_one SMCJB with 3 posts (6 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 (3 thanks)
    1. trending_up 431 views
    2. thumb_up 11 thanks given
    3. group 4 followers
    1. forum 5 replies
    2. attach_file 4 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 100,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Optimizing Multiple Sub-Strategies in one Master Strategy

(login for full post details)
  #1 (permalink)
Legendary Market Wizard
Houston, TX
 
Experience: Advanced
Platform: XTrader and Cloud TT
Broker: Advantage Futures
Trading: Energy
 
Posts: 3,544 since Dec 2013
Thanks: 2,829 given, 6,642 received

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

Reply With Quote
The following 2 users say Thank You to SMCJB for this post:

Can you help answer these questions
from other members on futures io?
Horizontal Line Indicator
Platforms and Indicators
OPEN_CLOSE_DOTS
ThinkOrSwim
Moving Pivot Point Indicator
Platforms and Indicators
DLL with webrequest function for MC
MultiCharts
IB Bracker Order
Platforms and Indicators
 
 
(login for full post details)
  #2 (permalink)
Legendary Market Wizard
Somewhere, Delawhere, USA
 
Experience: Intermediate
Platform: TradeStation,Sierra Chart
Broker: Tradestation Securities
Trading: My kids, VX, Eurodollar
 
vmodus's Avatar
 
Posts: 746 since Feb 2017
Thanks: 1,386 given, 1,353 received


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

You panic, you die.
Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #3 (permalink)
Legendary Market Wizard
Houston, TX
 
Experience: Advanced
Platform: XTrader and Cloud TT
Broker: Advantage Futures
Trading: Energy
 
Posts: 3,544 since Dec 2013
Thanks: 2,829 given, 6,642 received



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.

Reply With Quote
 
(login for full post details)
  #4 (permalink)
Hamburg Germany
 
Experience: Advanced
Platform: Multicharts, Tradestation
Broker: DTN IQ
Trading: ES
 
Posts: 2,192 since Apr 2013
Thanks: 385 given, 1,427 received

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/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 Visit my Facebook Reply With Quote
The following 2 users say Thank You to ABCTG for this post:
 
(login for full post details)
  #5 (permalink)
Market Wizard
Cleveland Ohio/United States
 
Experience: Advanced
Platform: Tradestation
Broker: Tradestation, DeCarley, others
Trading: futures
 
Posts: 2,791 since Jul 2012
Thanks: 1,439 given, 5,382 received


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
Register to download File Type: xls greatguysean.xls (28.5 KB, 1 views)
Follow me on Twitter Reply With Quote
The following 3 users say Thank You to kevinkdog for this post:
 
(login for full post details)
  #6 (permalink)
Legendary Market Wizard
Houston, TX
 
Experience: Advanced
Platform: XTrader and Cloud TT
Broker: Advantage Futures
Trading: Energy
 
Posts: 3,544 since Dec 2013
Thanks: 2,829 given, 6,642 received


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

Reply With Quote
The following 4 users say Thank You to SMCJB for this post:


futures io Trading Community Platforms and Indicators EasyLanguage Programming > Optimizing Multiple Sub-Strategies in one Master Strategy


July 23, 2020


Upcoming Webinars and Events
 

Live Video Panel: Ask Me Anything w/Ironbeam Brokerage

Aug 6
     



Copyright © 2020 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts