Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (EternallyCurious, howardR), 646 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 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,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
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,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
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,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
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,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
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,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
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