polyfit (var* Coeff, vars Data, int Length, int Order, var Weight) : var
Polynomial regression. Generates a polynomial
of the form y = anxn +
... + a1x + a0 that is the best fit to a section of a price series or any other data series. This polynomial can be used for extrapolating the Data series into the future, and thus predicting future prices.
||A var array for storing the calculated polynomial coefficients
an, or 0 for storing the coefficients internally.
||Data series to be approximated by the polynomial.
||Number of elements in the Data series to be approximated by the polynomial.
||Order of the polynom (1..7). Use 1 for linear regression, 2 for parabolic
(quadratic) regression, and higher numbers for nth-order regression.
||Ratio of the weight of the last data value to the weight of the first value, for "fading-memory" polynomials. Use 1 for equal weights.
Correlation coefficient, normally in the 0..1 range. Gives the similarity of the price curve and the polynomial.
Coeff - set to the coefficients of the polynomial, in the order of their index, starting with
The remaining coefficients are set to 0.
polynom (var* Coeff, int Offs) : var
Returns the value of the polynomial with the given coefficients at a given
||A var array that contains the polynomial coefficients
an, or 0 for using the last coefficients generated by polyfit.
||The offset into the polyfit Data series of the
returned polynomial value. Use negative offsets for extending the series
into the future.
Value of the polynomial at the given bar offset.
- Polynomials of order 1 (straight line), 2 (parabola), or 3 are useful for price change predictions. Higher order polynomials are unlikely to give good predictions.
- The weight ratio can be used for giving recent data more weight; however the best predictions are usually generated with weight at 1.
- For better accuracy in price prediction, don't fit the polynomial to a price series, but to a series of price differences. Price differences vary more than prices and thus give more accurate correlation coefficients.
- As data series are stored in reverse order, a rising data series generates a polynomial with a falling slope, and vice versa.
- For predicting curve events with polynomial regression, such as crossovers, peaks, or valleys, use the predict function.
- For logistic linear regression with multiple variables, use the advise(PERCEPTRON,...) function.
// least square moving average indicator
var LSMA(vars Data,int Period,int Offset)
// quadratic least square moving average indicator
var QLSMA(vars Data,int Period,int Offset)
// predict price change by parabolic regression
vars Diff = series(price(0)-price(1));
var Correlation = polyfit(0,Diff,15,2,1);
// sum up the differences for predicting the price change over the next 3 bars
var Change3 = polynom(0,-1)+polynom(0,-2)+polynom(0,-3);
frechet, advise, predict