Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,135 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
How to optimize a multiAsset script? #464136
01/24/17 17:09
01/24/17 17:09
Joined: Apr 2013
Posts: 35
J
Joaquin Offline OP
Newbie
Joaquin  Offline OP
Newbie
J

Joined: Apr 2013
Posts: 35
Hi, I have a pairs trading script which works correctly in [Test] mode.
I am adding the optimize(..) function to it, in order to optimize according to best Period (TimeFrame) and best LookBack. I use these lines to optimize:

Code:
set(LOGFILE|PARAMETERS);
	DataSplit = 90;
	NumWFOCycles = 10;
	//BarPeriod = 15;
	int Periods[2] = {1440,240};
	BarPeriod = Periods[round(optimize(1,0,1,1),1)];
	PlotWidth = 650;
	StartDate = 20150101; 
	EndDate = 20151201; 
	int lookBacks[2] = {150,300};
	LookBack = lookBacks[round(optimize(1,0,1,1),1)];



But it does not optimize with the 2 assets, it only "discovers" the asset I have marked when running "Train" mode, so every Step of the optimization gets "0", because it couldn't get the second asset's prices.

Is there any sample script in the manual which I could take a look in order to do this?

Thanks!

Re: How to optimize a multiAsset script? [Re: Joaquin] #464140
01/24/17 19:48
01/24/17 19:48
Joined: Aug 2016
Posts: 95
Wien
T
trenki2 Offline
Junior Member
trenki2  Offline
Junior Member
T

Joined: Aug 2016
Posts: 95
Wien
You need to select the asset you want with the asset call and then you can query its prices.

Like so for example:
Code:
asset("Asset1");
var asset1price = priceClose();

asset("Asset2");
var asset2price = priceClose();


Re: How to optimize a multiAsset script? [Re: trenki2] #464142
01/24/17 20:30
01/24/17 20:30
Joined: Apr 2013
Posts: 35
J
Joaquin Offline OP
Newbie
Joaquin  Offline OP
Newbie
J

Joined: Apr 2013
Posts: 35
Thanks! But...
I'm not sure that's the answer.
As I said, the script correctly works in "Test" mode, so I select the assets correctly in the buy and sell functions. These are the buy/sell functions of my script:

Code:
void vendemosSpread(double hedgeRatio){
	asset(asset1);
	Margin = 1;
	//if (!TradeIsOpen)
	enterShort();
	
	asset(asset2);
	Margin=1*abs(hedgeRatio);
	enterLong();	
}

void compramosSpread(double hedgeRatio){
	asset(asset1);
	Margin=1;
	//if (!TradeIsOpen)
	enterLong();
	
	asset(asset2);
	Margin=1*abs(hedgeRatio);
	//if (!TradeIsOpen)
	enterShort();	
}



being asset1 and asset2 strings of 2 different assets.
But when I'm in Training mode, with these optimize lines I've just added, this is the output:

Code:
Parameter 1 step  2:  1.00 => 0.00   0/34
Selected p1[2] = +0.600  => -0.67

Parameter 2 step  1:  0.00 => 0.00   0/46
Parameter 2 step  2:  1.00 => 0.00   0/34
Selected p2[2] = +0.600  => -0.67

USD/CHF: +0.600 +0.600=> 0.000

Parameters stored in statArb5_8.par
.
Parameter 1 step  1:  0.00 => 0.00   0/ 6.


Every output gives "0", and the training only generates .par for one of the assets, not the second one...

Any ideas?

Re: How to optimize a multiAsset script? [Re: Joaquin] #464143
01/24/17 20:57
01/24/17 20:57
Joined: Apr 2013
Posts: 35
J
Joaquin Offline OP
Newbie
Joaquin  Offline OP
Newbie
J

Joined: Apr 2013
Posts: 35
I think that the error was that I didn't have the loadHistory(asset1,1) in the INITRUN function... I have added it and now at least it correctly does the Test after the Train.

I don't understand why I'm getting all those zeroes, that's the truth, and also why .par files have rules similar to this:
Code:
USDUSD/CHF +0.600 +0.600=> 0.000



Where is the second asset? What does this .par means? Still looking for the answer...

Re: How to optimize a multiAsset script? [Re: Joaquin] #464147
01/25/17 07:53
01/25/17 07:53
Joined: Aug 2016
Posts: 95
Wien
T
trenki2 Offline
Junior Member
trenki2  Offline
Junior Member
T

Joined: Aug 2016
Posts: 95
Wien
The optimizer gave you two optimized parameter values (0.6 0.6) the asset name in the output i guess is irrelevant in this case.

If you want different parameters for different assets I think you need an asset loop construct.

Code:
while (asset(loop(Asset1, Asset2)))
{
}


Re: How to optimize a multiAsset script? [Re: trenki2] #464152
01/25/17 11:17
01/25/17 11:17
Joined: Apr 2013
Posts: 35
J
Joaquin Offline OP
Newbie
Joaquin  Offline OP
Newbie
J

Joined: Apr 2013
Posts: 35
Thanks for your answer. So the parameters are 0.6 and 0.6... ok.

But I still don't get to make optimization work ok. When I start an optimization with this script, I only get "meaningful" results in the first step of the loop ("walk [1] parameter [1]"). In this only scenario I get
Code:
Parameter 1 Step 1: 0.00 => 0.22 2/0.



So, 0.22 is the "rank performance" given by the optimization, 2 are the winning trades, 0 the losing trades.

The rest of the steps in the optimization loop always give the results
Code:
Parameter X Step X: X.00 => 0.00 0/0.



Maybe some of the combinations could possibly not open any order. But NOT all, this is not the behavior in the "Test" phase without having Trained before.

After training, if I run a Test, an error emerges:

Code:
Login Oanda V1 demo..
!Account 777829 at UTC 25.01. 11:12
EUR/USD 2015 complete
USD/CHF 2015 complete
Logout.. ok
Walk-Forward Test: statArb5 portfolio 2015
Read statArb5_1.par
Error 030: asset EUR/USD missing in INITRUN. statArb5_2.par
Error 030: asset EUR/USD missing in INITRUN. statArb5_3.par statArb5_4.par statArb5_5.par statArb5_6.par statArb5_7.par statArb5_8.par statArb5_9.par
Profit -1021$  MI -186$  DD 1021$  Capital 2630$
Trades 44  Win 0.0%  Avg -6340.1p  Bars 39
AR -85%  PF 0.00  SR 0.00  UI 0%  R2 0.91



I think I am doing something not correctly. But I have done the optimization part in the same way as I have seen it in the manual... So I don't know where is my mistake.

Thanks for your efforts!

Re: How to optimize a multiAsset script? [Re: Joaquin] #464154
01/25/17 14:29
01/25/17 14:29
Joined: Apr 2013
Posts: 35
J
Joaquin Offline OP
Newbie
Joaquin  Offline OP
Newbie
J

Joined: Apr 2013
Posts: 35
After many different tests, I have noticed something.
In my script, I have some calculations (the spread or ZScore of the 2 series) that must be made only after the LookBack period has elapsed. If I try to calculate this ZScore before LookBack has elapsed, I would find "0" and results would lead to errors.

In order to calculate this ZScore after LookBack, I did this:

Code:
if (Bar > StartBar) {
		var criticalValue = -1;
		//Some calculations...
	}



And I really think that this is the reason why my optimization only works in the first step of the WFO.

For now, I will comment out the "NumWFOCycles", and I will use normal Training (Vertical Split optimization, as it is called in the manual).

Any ideas how I could make WFO and not fall into the error of doing these calculations before the LookBack has passed?

Re: How to optimize a multiAsset script? [Re: Joaquin] #464156
01/25/17 16:43
01/25/17 16:43
Joined: Apr 2013
Posts: 35
J
Joaquin Offline OP
Newbie
Joaquin  Offline OP
Newbie
J

Joined: Apr 2013
Posts: 35
Another weird behavior, even with the normal Training (not WFO):

After having run a Training cycle, if I run a Test cycle, an error emerges:
Code:
statArb5 compiling..............
INICIO 
Login Oanda V1 demo..
!Account 777829 at UTC 25.01. 16:37
EUR/USD 2016 complete
USD/CHF 2016 complete
Assets..
Logout.. ok
Out-of-Sample Test: statArb5 portfolio 2012..2016
Read statArb5.par
Error 030: asset EUR/USD missing in INITRUN.



If I rename the .par file to something like statArb5.par.backup, the error dissapears. So, actually, EUR/USD is NOT missing in INITRUN, AFAIK.

I like a lot the power of Zorro Trader, but there are a lot of intricacies to learn when you are used to other languages/platforms!


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1