Polynomial Regression (untradable)

Top  Previous  Next

Category: Advanced Indicator Set 1

 

Input parameters

Name

Setting

Default

Input series

Input Time Series

Close

Polynomial degree

0<= Integer <=100

2

Number of points

Integer 1 or >=2

-1

Date gap mode

Integer 0 or 1

1

Date

Date Time Series

Date

 

Calculations

Given Input time series y(t), the Polynomial Regression indicator draws a polynomial p(t) in the form:

p(t) = a0 + a1 * x(t) + a2 * x(t)^2 + … + aN * x(t) ^ N,

where a0..aN - polynomial coefficients, x(t) - X-coordinate value, and N - Polynomial Degree.

The goal of the regression is to find a set of coefficients a0, a1, …, aN, which minimize the error function Sum(y(t)-p(t))^2, where y(t) are actual Y-coordinates.

The “Number of points” input controls how many points in the data series to consider for polynomial calculation. A value of minus one (-1) will calculate and draw the polynomial through all points found in the data series. Any positive number will take the most recent Number of points to calculate and draw the polynomial. For example, if Number of points = 100, then only the most recent 100 points (bars) will be considered for the polynomial. The Polynomial Degree must be less than or equal to (Number of points 1).

The Date gap mode input variable controls how to treat date gaps (weekends, holidays, etc.) found in the Input data series. The Date gap mode can be set to either 0 or 1 (one is the default). A zero setting forces the indicator to consider the point number as the X-axis (i.e., if using daily bars, if Friday is point 7, Monday will be point 8, assuming there are no bars during the weekend). A setting of one (1) includes all possible points where bars could occur in the X-axis (in other words, if bars are daily, and Friday is point 7, Monday will be point 10).

 

Discussion

A polynomial degree of zero  (N=0) will draw a constant line through the Input data, N=1 will draw a linear trend line, N=2 is a parabola, N=3 is a cubic equation and so on. Theoretically, using polynomial regression, through M data points one can draw a polynomial of degree (M-1) or less, but not more. Therefore, the indicator will not consider a Polynomial Degree higher than the Number of points 1.

As you increase the polynomial degree starting with zero, you will get increasingly better and better polynomial fitting of the data (i.e., tighter fits). However, for each data series there is some polynomial degree after which the polynomial doesnt really change to any further extent even as its degree increases. This limit degree varies for each data series depending on the number of points and the data series behavior.

For example, you may set the polynomial degree to 100, but the regression will most likely find polynomial coefficients such that on the chart it will look like a 10th degree polynomial. This happens because higher power terms in such a polynomial will be so small that their contribution to the total sum is negligible.

Also, the higher the degree of the polynomial, the more chances are that the polynomial will get unstable. In some cases this unstable behavior can be seen on the chart as wild oscillations. The more points are on the chart the more likely the oscillations will start. To avoid this problem try to use polynomial degrees lower than 20.

Polynomial regression may be helpful to find and to eliminate underlying long-term and/or seasonal trends in the time series.

NOTE. The Polynomial Regression indicator CANNOT be used in trading strategies or neural nets used in trading strategies. This indicator was designed to be viewed as a trend curve through the entire set of data. It is not appropriate for use in a trading strategy because new data bars can cause the trend line to change the trend through past data. This in turn can cause the NeuroShell Trader signals to change in the past. Use this indicator ONLY for viewing in a static chart, but do NOT insert it in a trading strategy or a neural net used for trading. Use Polynomial Predict indicator instead.