Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (rki), 405 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
polyfit order 1 - coeff[1] sign is reversed? #430222
09/25/13 18:55
09/25/13 18:55
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline OP
Serious User
DdlV  Offline OP
Serious User
D

Joined: Jun 2013
Posts: 1,609
Latest play topic laugh has been polyfit. Starting simple with order 1 (straight line), the intercept returned as coeff[0] seems correct, but it appears the slope returned as coeff[1] has opposite sign. When the price curve goes up, the slope is negative, and vice versa. It's also opposite from what is returned by LinearRegSlope, which appears to be correct. Please check this, and if it's a bug also verify that the coeff[n]'s for higher order have the correct sign - I'll get there someday! laugh

Thanks.

Re: polyfit order 1 - coeff[1] sign is reversed? [Re: DdlV] #430232
09/26/13 00:11
09/26/13 00:11
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline OP
Serious User
DdlV  Offline OP
Serious User
D

Joined: Jun 2013
Posts: 1,609
Or is it the other way 'round? polyfit is correct and LinearReg is wrong? For TimePeriod=2, coeff[0]=price(). Both this and the coeff[1] slope make sense if x=0 is the current bar, and the slope works backwards in time. Is that how polyfit works? How about LinearReg?

Thanks.

Re: polyfit order 1 - coeff[1] sign is reversed? [Re: DdlV] #430248
09/26/13 08:03
09/26/13 08:03
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
Both are correct. It's just simple math: in data series, the time scale is reversed, i.e. higher indexes go backwards in time. This reverses the sign of first coefficient, of the third, fifth, and so on. LinearReg does not generate coefficients for a data series polynom, polyfit does.

Re: polyfit order 1 - coeff[1] sign is reversed? [Re: jcl] #430282
09/26/13 12:33
09/26/13 12:33
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline OP
Serious User
DdlV  Offline OP
Serious User
D

Joined: Jun 2013
Posts: 1,609
Thanks for the explanation, jcl, but this simpleton still doesn't get it. I don't understand the inconsistency. LinearReg is the same as polyfit order 1, and Linear Reg does generate coefficients. Just because one calls them "Slope" and "Intercept" doesn't change that. I can plug those coefficients into an array and pass them to polynom, and should get the same result as if they were generated by polyfit. polynom doesn't know and shouldn't care that the coefficients came from polyfit, LinearReg, random number generators, or anywhere else. Someone - the Zorro gods, the trading community, whoever - has decided that LinearReg should work in forward time and polynom/polyfit in reverse time. Please don't tell me that this difference in behavior is simple math, because it isn't. If you wish to maintain this difference, please highlight it in the manual. Although it would seem to me a better solution to have all functions work in the same time direction.

Thanks.

Re: polyfit order 1 - coeff[1] sign is reversed? [Re: DdlV] #430287
09/26/13 13:10
09/26/13 13:10
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
The problem is that you seem to think that LinearReg is the same as polyfit order 1. It is not. LinearReg is for calculating the slope of a line, polyfit calculates coefficients. Both are different because series go backwards. If you draw a reverse slope on a piece of paper, you can easily see that this just inverts the sign of the slope.

http://manual.zorro-trader.com/ta.htm

http://manual.zorro-trader.com/polyfit.htm

Re: polyfit order 1 - coeff[1] sign is reversed? [Re: jcl] #430293
09/26/13 13:33
09/26/13 13:33
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline OP
Serious User
DdlV  Offline OP
Serious User
D

Joined: Jun 2013
Posts: 1,609
Thanks jcl.

Actually, the problem is forest vs. trees. At your trees level, what you say makes some sense. Although I don't understand your distinction between "calculating the slope of a line" and "calculates ... coefficients" - the slope is a coefficient.

In any case, at the forest level, it breaks down. An order 1 polynomial is a straight line (if you don't believe me, your 2nd link above says so laugh ). 2 functions doing the same thing at the same polynomial order should return the same results. Imagine further that Zorro had a "LinearRegnom" function designed to take the Slope and Intercept and compute the value for any bar - like, say, polynom does. The results should be identical, and the input coefficients should be interchangeable.

But hey - it's your system - look at it whatever way you wish! laugh

Just realize that you caused this user some confusion. If you're going to leave the functions the way they are, please at least point out in the manual the difference in time perspective, x=0 point, whatever you want to call it.

Thanks.


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