Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Imhotep, opm), 785 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Optimizing global & local parameters #481892
11/14/20 16:00
11/14/20 16:00
Joined: Jan 2017
Posts: 11
Israel
D
dBc Offline OP
Newbie
dBc  Offline OP
Newbie
D

Joined: Jan 2017
Posts: 11
Israel
I'm trying to optimize the following strategy, which has one global and two local parameters.

The optimization process runs OK when there are up to 7 assets. When I add the 8 and up assets I got the:

"Error 011: optimize(invalid parameters)"

I tied to debug with watch() and diag.txt, but nothing comes up.

Any help will be appreciated.

This is the code:
Code
function run()
{

	set(PARAMETERS|LOGFILE);
	BarPeriod    = 1440;
	StartDate     = 2010;
	LookBack    = 100;
	Verbose      = 7;
	assetList("AssetsZ9.csv");

	asset("AGG");
	int Max_Long_Assets = optimize(2,1,4,1);  //global optimization parameter
	
	for(listed_assets) {
		asset(Asset);
		vars Prices     = series(price());
		var  sma5       = ROC(Prices,5);
		
		var signal1     = SMA(Prices,5);
		var signal2     = SMA(Prices,30);
		var Threshold1  = optimize(0.05,0.0,0.1,0.01);  // local optimization parameter
		var Threshold2  = optimize(0.05,0.0,0.1,0.01);  // local optimization parameter
		int RR  = signal1 - signal2 < Threshold1;
		int TT  = signal1 - signal2 > Threshold2;
//		printf("\n%.3f",signal1 - signal2);
		
		
		int In = (sma5<0 && RR==1) || (sma5>0 && TT==1);
		int Out= (sma5>0 && RR=1) || (sma5<0 && TT==1);
		
		int NewShares = Balance/priceClose(0)/Max_Long_Assets-LotsPool;
		
		if(In && NumLongTotal < Max_Long_Assets)
			enterLong(NewShares);
		else if (Out)
			exitLong();
	}
	
}


Last edited by dBc; 11/14/20 16:04.
Re: Optimizing global & local parameters [Re: dBc] #481937
11/24/20 08:28
11/24/20 08:28
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Maybe that 8th asset had a problem, like missing history or a wrong asset parameter?

Re: Optimizing global & local parameters [Re: jcl] #481949
11/25/20 15:16
11/25/20 15:16
Joined: Jan 2017
Posts: 11
Israel
D
dBc Offline OP
Newbie
dBc  Offline OP
Newbie
D

Joined: Jan 2017
Posts: 11
Israel
Hi JCL,

Thank you for your reply.

Sorry that I didn't mention in my post that any 7 assets out of the assetsZ9 available, will train the strategy.
The 8th asset would be any asset out of the list.
For example:
Code
Name,Price,Spread,RollLong,RollShort,PIP,PIPCost,MarginCost,Leverage,LotAmount,Commission,Symbol,Type
AGG,50,0.1,0,0,0.01,0.01,0,1,1,0.02,*!STOOQ:*,1
#CWI,50,0.1,0,0,0.01,0.01,0,1,1,0.02,CWI!STOOQ:CWI,2
#DIA,50,0.1,0,0,0.01,0.01,0,1,1,0.02,*!STOOQ:DIA,0
#FDN,50,0.1,0,0,0.01,0.01,0,1,1,0.02,*!STOOQ:FDN,0
#HYG,50,0.1,0,0,0.01,0.01,0,1,1,0.02,HYG!STOOQ:HYG,1
IAU,50,0.1,0,0,0.01,0.01,0,1,1,0.02,IAU!STOOQ:IAU,2
IGM,50,0.1,0,0,0.01,0.01,0,1,1,0.02,*!STOOQ:IGM,0
IGSB,50,0.1,0,0,0.01,0.01,0,1,1,0.02,IGSB!STOOQ:IGSB,1
#ITB,50,0.1,0,0,0.01,0.01,0,1,1,0.02,ITB!STOOQ:ITB,0
SMH,50,0.1,0,0,0.01,0.01,0,1,1,0.02,SMH!STOOQ:SMH,0
TLT,50,0.1,0,0,0.01,0.01,0,1,1,0.02,TLT!STOOQ:TLT,1
#VGK,50,0.1,0,0,0.01,0.01,0,1,1,0.02,VGK!STOOQ:VGK,2
#VOO,50,0.1,0,0,0.01,0.01,0,1,1,0.02,VOO!STOOQ:VOO,1
SPY,50,0.1,0,0,0.01,0.01,0,1,1,0.02,SPY!STOOQ:SPY,3
#SPLV,50,0.1,0,0,0.01,0.01,0,1,1,0.02,*!STOOQ:SPLV,0
#XBI,50,0.1,0,0,0.01,0.01,0,1,1,0.02,XBI!STOOQ:XBI,0
#XLI,50,0.1,0,0,0.01,0.01,0,1,1,0.02,XLI!STOOQ:XLI,0
#XLU,50,0.1,0,0,0.01,0.01,0,1,1,0.02,*!STOOQ:XLU,0
#XLV,50,0.1,0,0,0.01,0.01,0,1,1,0.02,XLV!STOOQ:XLV,0



Any 7 assets you choose will train the strategy, but the 8th (could be any asset) will break the training.

AGG-CWI-DIA-FDN-HYG-IAU-IGM -> train is OK
AGG-CWI-DIA-FDN-HYG-IAU-IGM-IGSB -> train breaks
CWI-DIA-FDN-HYG-IAU-IGM-IGSB -> train OK

Last edited by dBc; 11/25/20 15:31.
Re: Optimizing global & local parameters [Re: dBc] #481967
11/28/20 10:29
11/28/20 10:29
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
You need loop() for optimizing local parameters. Correct would be: while(asset(loop(Assets))), not for(listed_assets).

Re: Optimizing global & local parameters [Re: dBc] #481969
11/28/20 14:56
11/28/20 14:56
Joined: Jan 2017
Posts: 11
Israel
D
dBc Offline OP
Newbie
dBc  Offline OP
Newbie
D

Joined: Jan 2017
Posts: 11
Israel
Thank you JCL, for your reply.

Please pay attention that there is ONE global parameter, so if I use your suggestion - no parameters train would take place.

Code
function run()
{

	set(PARAMETERS|LOGFILE);
	BarPeriod    = 1440;
	StartDate    = 2010;
	LookBack     = 1000;
	Verbose      = 7;
	assetList("AssetsZ9.csv");

	asset("AGG");
	int Max_Long_Assets = optimize(2,1,4,1);
//	int Max_Long_Assets = 2;

	
	while(asset(loop(Assets))) {
		vars Prices     = series(price());
		var  sma5       = ROC(Prices,5);
		
		var signal1     = SMA(Prices,5);
		var signal2     = SMA(Prices,30);
		var Threshold1  = optimize(0.05,0.0,0.1,0.01);
		var Threshold2  = optimize(0.05,0.0,0.1,0.01);
		int RR  = signal1 - signal2 <  Threshold1;
		int TT  = signal1 - signal2 >= Threshold2;
//		printf("\n%.3f %.3f",sma5,signal1 - signal2);
		
		
		int In = (sma5<0 && RR==1) || (sma5>0 && TT==1);
		int Out= (sma5>0 && RR==1) || (sma5<0 && TT==1);
		
		int NewShares = Balance/priceClose(0)/Max_Long_Assets-LotsPool;
		
		if(In && NumLongTotal < Max_Long_Assets)
			enterLong(NewShares);
		else if (Out)
			exitLong();
//	plot("TT",signal1 - signal2,NEW|LINE,RED);
	}
	
}



Zorro's train run results:

Code

XLV history up to date
XLV 3967 ticks read
Loop[8] p1 step  1:  0.00 => 0.00   0/ 0

Loop[8] p2 step  1:  0.00 => 0.00   0/ 0

XLV: 0.050 0.050=> 0.000

Parameters stored in David.par




If I disable the global parameter, then the train works OK

Code

//	int Max_Long_Assets = optimize(2,1,4,1);
	int Max_Long_Assets = 2;  // No global parameter



Code
Loop[8] p2 step  7:  0.06 => 0.72  460/651
Loop[8] p2 step  8:  0.07 => 0.72  461/649
Loop[8] p2 step  9:  0.08 => 0.72  459/649
Loop[8] p2 step 10:  0.09 => 0.73  460/646
Loop[8] p2 step 11:  0.10 => 0.73  458/645
Selected p2[9] = 0.080  => 0.73

XLV: 0.070 0.080=> 0.723

Parameters stored in David.par



The only way I succeeded to optimize ONE global and TWO local parameters , is using "listed_assets", but it works for 7 assets only.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1