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
5 registered members (Nymphodora, AndrewAMD, TipmyPip, Quad, Imhotep), 846 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
Page 1 of 2 1 2
Linear Regression in objective function #469447
11/16/17 16:33
11/16/17 16:33
Joined: Aug 2017
Posts: 102
Spain
B
Brax Offline OP
Member
Brax  Offline OP
Member
B

Joined: Aug 2017
Posts: 102
Spain
Hi,

I am currently doing some research on optimization criteria and i´ve got stuck trying to apply LinearRegSlope*R2 to optimize parameters.

This code gives me an error regarding i need more lookback period:

Code:
var objective()
{
    return LinearRegSlope(ResultsDaily,Bar-StartBar)*R2;   	
}



I´ve also tried with Day instead of Bar-StarBar, and even putting directly a number lower than lookback for the period gets a crush.

¿How could i achieve this?

The alternative is using (WinTotal-LossTotal)*R2, but this is not what i really want.

Re: Linear Regression in objective function [Re: Brax] #469462
11/17/17 09:14
11/17/17 09:14
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Day is correct for getting the regression slope of the equity curve, but be aware: ResultsDaily is in chronological order, not reversed like a series. So use the negative slope. Lookback must be set to the number of days in the simulation, or above.

Re: Linear Regression in objective function [Re: jcl] #469544
11/20/17 13:13
11/20/17 13:13
Joined: Aug 2017
Posts: 102
Spain
B
Brax Offline OP
Member
Brax  Offline OP
Member
B

Joined: Aug 2017
Posts: 102
Spain
Ok, I understand.

The problem with increasing lookback is i run out of enough bars... So i can´t properly test this criteria.

I thought i wouldn´t need lookback for this, as in other platforms is not necessary, just take the whole equity and go.

Re: Linear Regression in objective function [Re: Brax] #469546
11/20/17 13:54
11/20/17 13:54
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Then set lookback to 0 when you don't need it. If Lookback is not 0, Zorro assumes that you need it for something.

Re: Linear Regression in objective function [Re: jcl] #469549
11/20/17 20:26
11/20/17 20:26
Joined: Aug 2017
Posts: 102
Spain
B
Brax Offline OP
Member
Brax  Offline OP
Member
B

Joined: Aug 2017
Posts: 102
Spain
I see your point, but at least in this case if i set lookback to 0, then no optimization is performed (everything returns 0) and the system is useless.

The only solution as it seems to be is just having at least double historic data than simulation period, if not, i can´t use this function.

So, i am afraid i´ll forget about this unless someone has an alternative solution.

Thanks.

Re: Linear Regression in objective function [Re: Brax] #469554
11/21/17 07:45
11/21/17 07:45
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Why so complicated? If you need lookback in the test, but not in the objective function, then set lookback in the run function to the value you need, and to 0 in the objective function.

The main purpose of variables like lookback is preventing errors. You normally adapt them to your script, not your script to the variables.

Re: Linear Regression in objective function [Re: jcl] #469556
11/21/17 12:25
11/21/17 12:25
Joined: Aug 2017
Posts: 102
Spain
B
Brax Offline OP
Member
Brax  Offline OP
Member
B

Joined: Aug 2017
Posts: 102
Spain
Sorry jcl but it still doesn´t work...

I´ve done as you state, and with other criteria goes fine but when i apply LinearRegSlope whether with Day, Bar-StarBar or a fixed number it crushes.

Quite strange indeed...

Thanks.

Re: Linear Regression in objective function [Re: Brax] #469558
11/21/17 13:13
11/21/17 13:13
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Ok. I cannot tell why "it crushes" because I have not yet used an indicator on something else than a data series. But here is how to look into such a problem.

First, check if ResultsDaily is really nonzero in the objective function. I believe it is, but otherwise the problem is clear.

Next, call LinearRegSlope with something simple, like an array { 1, 2, 3 } of length 3, and check if it still "crushes". If so, then LinearRegSlope only works with a real data series for some reason, and you need the more common polyFit function. When you're at this point, post again and I'll help.

Re: Linear Regression in objective function [Re: jcl] #469563
11/21/17 19:32
11/21/17 19:32
Joined: Aug 2017
Posts: 102
Spain
B
Brax Offline OP
Member
Brax  Offline OP
Member
B

Joined: Aug 2017
Posts: 102
Spain
Hi jcl.

ResultsDaily is nonzero and it´s reversed as you stated.

LinearRegSlope(ResultsDaily,Day) with LookBack = 0 doesn't seem to work properly. It always returns 1, maybe there is an issue with the reversed order of the series.

polyfit(0,ResultsDaily,Day,1,1) letting LookBack with its original value produces different results in training, but in test mode the system results aren't profitable when other criteria do.

I think i need to reverse the series or apply the slope over the differencies, need some help.

Thanks.



Last edited by brax; 11/21/17 19:38.
Re: Linear Regression in objective function [Re: Brax] #469571
11/22/17 14:40
11/22/17 14:40
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
I've checked now, but all the indicators definitely work with LookBack=0. Lookback=0 just switches off the error message.

So your problem has a different reason that is unrelated to LookBack. Without seeing your code this is of course hard to tell. It's not reversing the series - this just changes the sign of the slope.

Some lines of code for testing LinearRegSlope wit no LookBack - maybe it helps:

Code:
void run()
{
	LookBack = 40;
	vars Prices = series(price(),40);
	if(Bar > 40) {
		LookBack = 0;
		printf("nSlope = %.6f",LinearRegSlope(Prices,40));
		LookBack = 40;
	}
}


Page 1 of 2 1 2

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