6 registered members (TipmyPip, Niels, dBc, Ed_Love, 3run, 1 invisible),
17,577
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
optimize global parameters SOLVED
#488922
09/26/25 13:29
09/26/25 13:29
|
Joined: Jan 2017
Posts: 15 Israel
dBc
OP
Newbie
|
OP
Newbie
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: 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: 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:
// 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; Yesterday at 14:37.
|
|
|
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
Serious User
|
Serious User
Joined: Feb 2017
Posts: 1,806
Chicago
|
The manual also says: 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: 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
09/27/25 17:07
09/27/25 17:07
|
Joined: Jan 2017
Posts: 15 Israel
dBc
OP
Newbie
|
OP
Newbie
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: 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) ... 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.
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; Yesterday at 14:35.
|
|
|
|