adviseLong/Short, WFO and multiple assets

Posted By: gtell

adviseLong/Short, WFO and multiple assets - 08/26/16 06:03

Dear JCL,

thanks for your lovely trading system.
Recently I have read your last article on Deep Learning and tried to experiment some things.
Very intersting article, my compliments.
I have tried to apply this strategy to multiple assets, modifing the code in this way:

Code:
while(asset(loop("EUR/USD","USD/JPY","AUD/USD","EUR/JPY"))) {	   
		if(adviseLong(NEURAL+BALANCED,0,
			change(1),change(2),change(3),change(4),
			range(1),range(2),range(3),range(4)) > 0.5) 
			enterLong();
		if(adviseShort() > 0.5) 
			enterShort();
}




The problem is that if I Train/Test this strategy individually on each pair, I get positive results.
But if put all together in one multiple asset strategy, I do not get the sum of the results I am getting individually and sometime I am getting a completely failing strategy.
So my question is, with the respect to the manual:

[text]
NEURAL_SAVE Data Save all trained models in the file with the name given by the string Data. The function is called at the end of every WFO cycle in [Train] mode.
NEURAL_LOAD Data Load all trained models from the file with the name given by the string Data. The function is called at the begin of every WFO cycle in [Test] mode, and at the begin of a [Trade] session. It is also called every time when the model file is updated by re-training.
[/text]

I have noticed that even with multiple assets, only one file containing the trained model is created.
Could you please tell me:


  • Does this file contain the information for each currency pair?
  • Is there any way to make Zorro writing a different file for eacy currency pair at the end of each WFO cycle?



I hope I have been clear enough. If not, please tell me.
Thanks.
Regards.
Posted By: jcl

Re: adviseLong/Short, WFO and multiple assets - 08/26/16 08:09

Yes, the model file is supposed to contain all models of each asset. Storing several separate models had to be scripted explicitely. Still, the portfolio results must be different to single assets because the random initial weight states are different. They should however not be systematically worse, only different. Do you get always worse results?
Posted By: gtell

Re: adviseLong/Short, WFO and multiple assets - 08/26/16 09:58

I do not have any evidence now, but I can provide you later.
Results are good most of the times, but sometime are really completely wrong. For instance, from 3 pairs performing 200$ per year alone, I get one multiple asset strategy that looses 700$ with long period drawdown, which does not make sense, right?
Sorry if I ask you again, you wrote the model file contains all the models, do these models contain the information regarding the pair the model is related? How does Zorro handle these models.
The signal0.csv file, does not contain anything about what pair the data are related.
I am not sure if I am clear enough, but from what I understood, training and testing several times, it looks Zorro is not applying the correct model to the right pair.
Bu I am completely sure of what I am writing, neither I know how to check it better.
What do you think about?

PS.: I will attach some evidence at earliest.
Posted By: jcl

Re: adviseLong/Short, WFO and multiple assets - 08/26/16 11:10

The model file only contains the models, but no information about assets or algos. The model inside the file is identified by its number. So if the number is wrong, a wrong model is assigned to an asset. This can happen for instance when you change the order of assets after training.

But I also see a potential bug, not in your snippet but outside it: If you set Spread etc. = 0 in your script, as in my article, make sure to do that for all assets. Otherwise you'll indeed get much worse results with multiple assets.
Posted By: gtell

Re: adviseLong/Short, WFO and multiple assets - 08/30/16 16:42

Ok, so it make sense not switching the order of the assets.
I have several more questions.
I want to start from the following one.
Consider the following Objective function:

Code:
vars PriceMed = series((priceHigh()+priceLow())/2);
ZigZag(PriceMed, 0.0037, 16, 1);
adviseLong(SIGNALS+BALANCED, rSign, ADX(16));



If I run it in Train mode I get:

Code:
17.05083,1.00000
15.92449,1.00000
15.35854,1.00000
14.35458,1.00000
13.80413,1.00000
14.31322,1.00000
16.44507,-1.00000
16.44507,-1.00000
16.44507,-1.00000
16.44507,-1.00000
18.18639,-1.00000
19.83614,-1.00000
21.73008,-1.00000
23.44226,-1.00000
24.77156,-1.00000
25.96473,-1.00000
27.43466,-1.00000
29.02421,-1.00000
30.23936,-1.00000
32.22313,-1.00000



which make sense...but If I change the function to:

Code:
vars PriceMed = series((priceHigh()+priceLow())/2);
ZigZag(PriceMed, 0.0037, 16, 1);
adviseLong(SIGNALS+BALANCED, ifelse(rSign==1, 0, 1), ADX(16));



I get the following:

Code:
17.05083,-0.58358
15.92449,0.03484
15.35854,-0.78387
16.44507,1.00000
14.35458,-1.91621
18.18639,1.00000
13.80413,-2.16878
19.83614,1.00000
14.31322,-1.98588
21.73008,1.00000
23.44226,1.00000
24.77156,1.00000
25.96473,1.00000
27.43466,1.00000
29.02421,1.00000
30.23936,1.00000
32.22313,1.00000



which does not make so much sense!
The records are first records of the file. After the first records everything seems fine.
Is there any reason for that?

Thanks.
Cheers.
Posted By: jcl

Re: adviseLong/Short, WFO and multiple assets - 08/31/16 08:49

Yes. You can use 0 or 1 for the Objective, but according to the manual not both at the same time:

"All advise calls for a given asset/algo combination must use the same Method, the same signals, and the same training target type (either Objective or trade result)."
Posted By: gtell

Re: adviseLong/Short, WFO and multiple assets - 08/31/16 17:03

Ok, this now I get it.
But what is the last column in this case.
Suppose that I use this:

Code:
vars PriceMed = series((priceHigh()+priceLow())/2);
  ZigZag(PriceMed, 0.0037, 16, 1);
  adviseLong(SIGNALS+BALANCED, 0, ADX(16));	
   	enterLong();



and I get the following:

Code:
27.98701,-0.62714
26.37550,-0.31357
23.96109,0.00000
22.05319,0.31357
22.05319,0.31357
20.36910,0.23518
19.20755,0.52269
18.48154,0.31357
17.66632,0.54003
16.73169,-0.06967
16.73169,-0.06967
15.97246,-0.03478
17.35032,-0.37452
16.89325,0.13934
16.35416,0.41802
15.26053,0.62714
15.27519,0.60970
15.90981,-1.30651
15.90981,-1.30651
16.12806,-1.93365
17.01053,-2.79597
16.64948,-1.04517
17.42188,-1.60264
18.66212,-0.04351
19.78223,-0.47908
21.14320,0.76648
21.14320,0.76648
21.14320,0.76648



so first column is ADX, but the second column is what? From where it takes those values?
Thanks.
Cheers.
Posted By: jcl

Re: adviseLong/Short, WFO and multiple assets - 09/01/16 08:12

The trade result.
Posted By: gtell

Re: adviseLong/Short, WFO and multiple assets - 09/02/16 08:32

Originally Posted By: jcl
Yes. You can use 0 or 1 for the Objective, but according to the manual not both at the same time:

"All advise calls for a given asset/algo combination must use the same Method, the same signals, and the same training target type (either Objective or trade result)."



Sorry I am still confused about what you wrote, because in another part of the manual you wrote:

Quote:

When using a future value for prediction, such as the price change of the next bars (f.i. Objective = priceClose(-5) - priceClose(0)), make sure to set the PEEK flag in train mode. Alternatively, use the price change of a past bar to the current bar, and pass past signals - f.i. from a series - to the advise function in train mode, f.i.:
Objective = priceClose(0) - priceClose(5);
int Offset = ifelse(Train,5,0);
var Prediction = adviseLong(Method,Objective,Signal0[Offset],Signal1[Offset],...);


In this case, the Object variable has range of values.
So, my aim is to train a model against the ZigZag target and predict values of this target.
What about this snippet, what is wrong?

Code:
vars PriceMed = series((priceHigh()+priceLow())/2);
ZigZag(PriceMed, 0.0037, 16, 1);
adviseLong(SIGNALS+BALANCED, rSign, ADX(16));

Posted By: jcl

Re: adviseLong/Short, WFO and multiple assets - 09/02/16 15:49

Nothing, why don't you use it? You can have any Objective that you want, only 0 and != 0 at the same time cannot work.
Posted By: gtell

Re: adviseLong/Short, WFO and multiple assets - 09/05/16 05:42

Thanks JCL for your tip, it really seems to work.
However, consider the following code:

Code:
#include <r.h>

var change(int n)
{
	return scale((priceClose(0) - priceClose(n))/priceClose(0),100)/100;
}

var range(int n)
{
	return scale((HH(n) - LL(n))/priceClose(0),100)/100;
}

int prevTrend = 0;
var prevPrice = 0;

function run()
{
	StartDate = 20140601;
	BarPeriod = 60;	// 1 hour
	LookBack = 100;
	PlotBars = -250;
   PlotWidth = 1600;
	PlotHeight1 = 600;
	ColorWin = ColorLoss = 0; 

	WFOPeriod = 252*24; // 1 year
	DataSplit = 90;
	NumCores = -1;  // use all CPU cores but one

	set(RULES);
	Spread = RollLong = RollShort = Commission = Slippage = 0;
	LifeTime = 3;
	if(Train) Hedge = 2;

	vars PriceMed = series((priceHigh()+priceLow())/2);   
   ZigZag(PriceMed, 37*PIP, 16, 0); 	
	var advise = adviseLong(NEURAL+BALANCED, rSign,
		change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4));
	int trend = ifelse(advise>0.5, 1, 0);
	if(trend != prevTrend) {
		prevTrend = trend;
		var prevPrice = (priceClose(0)+priceOpen(0))/2;
		if(!Train) {
			printf("\n%04d%02d%02d %02d:%02d: %.4f", year(), month(), day(), hour(), minute(), prevPrice);
			plotGraph("Pr.ZZ", 0, prevPrice, LINE, RED);
		}
	} 
	
	
	/*
	if(advise > 0) 
		enterShort();
	if(advise < 0) 
	   enterLong();
	*/
	   
  

}



What I want to achieve is to predict the value of ZigZag and plot in the chart a line between each point where the predicted value of ZigZag changes.
What I get with the code above is the following:

[img]
https://postimg.org/image/3o86kblqr/
[/img]

If you notice, the X axis is not correct. The price and the LINE have different axis. If I remove "PlotBars = -250;" then it works. But I want to see the chart better in a smaller time period.
Could you please tell me how to change this script in the way it works?
Thanks.
Cheers.
Posted By: jcl

Re: adviseLong/Short, WFO and multiple assets - 09/05/16 15:08

Apparently the plotGraph elements are not clipped by PlotBars. I'll put this on the fix list - until then, limit the chart with StartDate instead of PlotBars.
Posted By: gtell

Re: adviseLong/Short, WFO and multiple assets - 09/17/16 16:04

Dear JCL,

the followig description in the manual:

Quote:

INITRUN
Initial run of the simulation before the price data is loaded and before the log file is opened. Can be used to initialize global and static variables. System variables that are not yet known - f.i. variables that depend on the asset and simulation period - are at 0 during the initial run.
FIRSTRUN
First run of the simulation with valid price data and system variables. Normally follows the INITRUN.
FIRSTINITRUN
First initial run of the script, in the case of multiple simulation runs due to training or Cycles. While INITRUN and FIRSTRUN is set at the start of any simulation run, FIRSTINITRUN is only set at the really first run.
EXITRUN
Last run of the simulation. All trades are closed. Can be used to calculate results, aside from the evaluate or objective functions.


are them valid for WFA? When you mention Cycles, are your talking about Optimization or WFA as well?
Thanks.
Cheers
Posted By: jcl

Re: adviseLong/Short, WFO and multiple assets - 09/19/16 09:46

For WFA, INITRUN and FIRSTINITRUN are the same. They are only different in training and when NumTotalCycles is used.
© 2024 lite-C Forums