Gamestudio Links
Zorro Links
Newest Posts
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
Release 2.68 replacement of the .par format
by Martin_HH. 09/23/25 20:48
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (TipmyPip, alibaba, 3run), 15,721 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
optimize global parameters SOLVED #488922
09/26/25 13:29
09/26/25 13:29
Joined: Jan 2017
Posts: 15
Israel
D
dBc Offline OP
Newbie
dBc  Offline OP
Newbie
D

Joined: Jan 2017
Posts: 15
Israel
Hello,

I'm trying to optimize two global parameters in my strategy.
Workshop5/6 optimize per asset/algo, which is not my case.

I read the manual and probably misunderstand it; due I got an error:
Quote

Zorro 2.66.3
(c) oP group Germany 2025


rs compiling............
WFO: rs 2020..2025
Error 111: Crash in run: run() at bar 1


From the manual I read:
Quote

In portfolio strategies, parameters should be normally optimized separately for any component. Use one or two loop() calls to cycle through all used assets and algos. For optimizing asset/algo specific parameters, place the optimize calls inside the inner loop, and make sure to select asset and algo before. For optimizing additional global parameters that do not depend on asset and algo, place their optimize call in the very first loop run only, and store the parameter in a static or global variable outside the loop. The global parameters are then assigned to the first asset and/or algo. If asset/algo specific optimization is not desired at all, don't use loop, but enumerate the assets in a simple for loop, f.i. for(used_assets) ..., and optimize the parameters outside the for loop. Make sure in that case to select all assets before the first optimize call; otherwise the optimizer will assume a single-asset strategy.


From the bolded phrase I understood the following:

Code
// The strategy, once a week decides which 3 assets out of a bank of assets, to buy. It's a long only strategy.
// var threshold should optimize how many assets to hold

var threshold;  // this is a global var outside the loop which I wish to optimize

function run() 
{
   set(PARAMETERS);

   NumWFOCycles = 15; // activate WFO

   if (FIRSTINITRUN)  // I tried FIRSTRUN too, same error 
		threshold = optimize(N_OF_ASSETS-2,N_OF_ASSETS-3,N_OF_ASSETS,1);

   while( loop( ..... { // first loop over the assets
   } // end of while loop


   while(loop(.... { // second loop over the assets, run after the first loop was finished

   } // end of while loop


   for( over all assets ... {

                   Each asset is compared to the threshold, after optimizing it should decide to take 1 or 2 or 3 or 4 or 5 assets, instead 3 assets, before the optimize.

   } // end of for loop
                 


The second parameter I want to optimize, is the LookBack build-in var.

Any insight over global parameters optimization will be appreciated.

David

Last edited by dBc; 8 hours ago.
Re: optimize global parameters [Re: dBc] #488923
09/26/25 17:53
09/26/25 17:53
Joined: Feb 2017
Posts: 1,806
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,806
Chicago
The manual also says:
Quote
All optimize calls must be placed either in the run function or in functions that are called from the run function. Since parameters are identified by the order of their optimize calls, the order must not change between test and training or from one run to the next.

You made an optimize call disappear in subsequent run calls. Not good.

Then there's this quote:
Quote
For optimizing additional global parameters that do not depend on asset and algo, place their optimize call in the very first loop run only, and store the parameter in a static or global variable outside the loop.

Probably not the clearest verbiage, but I think it's saying that optimize() should only be called once for the global variables inside the first loop() call, not the first run() call. (That is, "the first time loop() is run".) If that's the case, you need to say if(this is the first loop call) then global variable = optimize().

Re: optimize global parameters SOLVED [Re: AndrewAMD] #488926
Yesterday at 17:07
Yesterday at 17:07
Joined: Jan 2017
Posts: 15
Israel
D
dBc Offline OP
Newbie
dBc  Offline OP
Newbie
D

Joined: Jan 2017
Posts: 15
Israel
Thank you AndrewAMD for your reply. Your suggestion unfortunately didn't work; it made optimization for the first asset only.

I read many times the manual and made the following changes in the code:

Quote

If asset/algo specific optimization is not desired at all, don't use loop, but enumerate the assets in a simple for loop, f.i. for(used_assets) ...,


I changed: while(loop(asset.... ===> for(used_assets) ...

Quote

and optimize the parameters outside the for loop.


Quote

Make sure in that case to select all assets before the first optimize call;


Quote

otherwise the optimizer will assume a single-asset strategy.


Code

var threshold;  // global optimize parameter  
function run() 
{
   set(LOGFILE | PLOTNOW );
   set(PARAMETERS);

   threshold = optimize(a,b,c,1);

   	for(used_assets)  // first loop
	{
             Needs no optimization
        }

   	for(used_assets)  // second loop
	{
             Needs no optimization
        }

   	for(used_assets)  // third loop
	{
             threshold decides how many assets to trade
             without optimize, go 3 assets long
             with optimize, go 1 or 2 or 3 or 4 or 5 assets long
        }

        The optimize runs on the last asset only. The manual says: [b]Make sure in that case to select all assets before the first optimize call[/b]
        How to select all assets before the first optimize call?

       David



***** UPDATE *****

The above code works OK, I got the optimization for the global var "threshold"

Interesting that the performance degraded after the optimization, holding always 3 assets got the best performance.

Last edited by dBc; 8 hours ago.

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1