6th Degree Poly Help! - page 3

 

I am thinking r2 might have something to do with variance ? Can anyone say what r2 is for sure ?



r2 is how well the data fits the curve https://en.wikipedia.org/wiki/Coefficient_of_determination
 
rocketman99:

r2 is how well the data fits the curve https://en.wikipedia.org/wiki/Coefficient_of_determination

Thanks rocketman, any thoughts about y=a+b1X+b2X2+b3X3+b4X4+b5X5+b6X6  ? Do you think that is the correct form for the 6th degree polynominal regression line and should we calculate a and b by the same slope intercept as in a linear regression ? I feel like I am missing something.


 
SDC:

Thanks rocketman, any thoughts about y=a+b1X+b2X2+b3X3+b4X4+b5X5+b6X6  ? Do you think that is the correct form for the 6th degree polynominal regression line and should we calculate a and b by the same slope intercept as in a linear regression ? I feel like I am missing something.


SDC, if X == 0 y = a.

and the slope at any point y' - this idenotes in math. the slope(s) of a function or more precise the 1st derivation

y'=b1+2b2X1+3b3X2+4b4X3+5b5X4+6b6X5

If you are interested you can go further and build y" = the 2nd derivation. It gives you the bend of the function.

If  y">0 the slope is increasing or an uptrend is about to occur or is strengthening: after a while one can call it a cup.

If  y"<0 the slope is decreasing or an downtrend is about to occur or is strengthening: faster down.

y"=2b2+6b3X1+12b4X2+20b5X3+30b6X4

But SDC, have you already decided how you will calculate the X-values from the TimeStamp? Where do you place the 0?

Gooly


 
I wasn't going to use timestamp I thought we could use the integer bar numbers ?
 

Well, as i suspected, i_regr works good and makes true polynomial regression. It was obvious from the generated curve shape. It uses standard algorithm for solving the equation system, identical to the ones i linked to in previous post.

Even the channel size is proportional to the standard deviation, with kstd used as factor of proportionality, so this free indicator is actually a very good one.

It is just a matter of orientation which causes difference from LIVEST() results.

 
SDC:
This could be all we need to know to code it, notice how the author writes y=a+b1X+b2X2 instead of y=ax2+bx+c  ? That was what was throwing me off, I thought c had to be entirely different coefficient. It appears from this article, the coefficients c,d,e,f,g in y=ax6+bx5+cx4+dx3+ex2+fx+g  are directly related to b which we already know from linear regression, is slope.


In the equation above, coefficients a thru f are slope coefficients - g is the Y-Intercept, the base value that when summed with the slope coefficients produces the value of the y-axis (price) for a given x (index).

SDC:

Aside from that, the article appears to imply r2 can be used to measure how well the line fits the data curve while we are testing increases in the polyline equation by degree, I am thinking r2 might have something to do with variance ? Can anyone say what r2 is for sure ?

The r^2 is the error factor used to determine the best fit which is then used to determine the best degree of the regression. e.g., if the data fits best at the 3rd degree, the r^2 value will have the lowest value i.e., lower than the r^2 value of a 2nd degree, 4th degree, and so on. The error factor is based on an average or mean (I assume) of the variance of a given (x,y) coordinate from the plotted line. I would consider using r^2 as a self-optimizer that would adjust the degree of our polynomial fit based on what the market is doing now. Perhaps this could be implemented to detect sideways ranging patterns. Perhaps a phase II topic.

I found someone who understands the math - I plan on spending a few hours with him this week. More to come.


Edit: On second thought, let's consider computing and holding the r^2 value of each degree up to n (where n is currently 6) - I think there may be some value in this measure.

 
graziani:

Well, as i suspected, i_regr works good and makes true polynomial regression. It was obvious from the generated curve shape. It uses standard algorithm for solving the equation system, identical to the ones i linked to in previous post.

Even the channel size is proportional to the standard deviation, with kstd used as factor of proportionality, so this free indicator is actually a very good one.

It is just a matter of orientation which causes difference from LIVEST() results.


Grazi - you are correct, the I-regr does, in fact, do a true polynomial regression - however, the regression method used by this indicator is a Gaussian Elimination. From what I've seen - the indicator is overly reactive in mild to moderate market corrections. Regarding your earlier post, I agree also that money management is the most important factor for any EA - and, I also agree that that a shorter term indicator is needed to determine precise entry/exit points. I have this covered already - the poly6 indicator is not going to be used for entry/exit points but for the direction, duration, and size of a given trade. This indicator is a trend analysis indicator, not an intraday oscillator. Used in conjunction with the other shorter term indicators already developed - I'll have what I need to maximize profit.

The difference between the I-regr and the LINEST() function is the method by which the slope coefficients are calculated. The Guass method vs. the Least Squares method. I just sat through a lecture on this topic from a Stanford University prof. that indicated (very emphatically) that the least squares method is once again becoming the most widely-trusted regression method and that the calculus approaches are becoming more theoretical.

 
SDC:
I wasn't going to use timestamp I thought we could use the integer bar numbers ?

Absolutely correct - from 0/current to N/range, perhaps in reverse order.
 
gooly:

SDC, if X == 0 y = a.


Gooly, took me awhile but, you are spot on! Coefficient a from the above example is the Y-intercept defined as "the value of y when x = 0" or the coordinate (0,a). Further, the quadratic (2nd degree) form you suggest does create a "cup" aka a parabola which doesn't have much practical application other then  to solve the binomial question "up" or "down".

 
dennisj2:


Grazi - you are correct, the I-regr does, in fact, do a true polynomial regression - however, the regression method used by this indicator is a Gaussian Elimination. From what I've seen - the indicator is overly reactive in mild to moderate market corrections. Regarding your earlier post, I agree also that money management is the most important factor for any EA - and, I also agree that that a shorter term indicator is needed to determine precise entry/exit points. I have this covered already - the poly6 indicator is not going to be used for entry/exit points but for the direction, duration, and size of a given trade. This indicator is a trend analysis indicator, not an intraday oscillator. Used in conjunction with the other shorter term indicators already developed - I'll have what I need to maximize profit.

The difference between the I-regr and the LINEST() function is the method by which the slope coefficients are calculated. The Guass method vs. the Least Squares method. I just sat through a lecture on this topic from a Stanford University prof. that indicated (very emphatically) that the least squares method is once again becoming the most widely-trusted regression method and that the calculus approaches are becoming more theoretical.


Yes it uses Gauss-Jordan, but it is completely irrelevant which method is used, as all of them (Gauss-Jordan, least squares, Gram-Schmidt or perhaps some other?) offer unique solutions. You can verify this through attached file, the results are printed in expert tab, and the input from your excel is hard coded in source.

However what is to be examined is how other factors affect the curve: applied price,  x-axis starting point, x-axis growth, number of points, TF etc.

And your way of using P6 is definitively innovative in a positive way, and in agreement with my critics of the standard approaches. 

Files:
i-regr.uni.mq4  12 kb
Reason: