A least squares approach fits a straight line t h rough the series of prices over a lookback period so the difference between each of the individual prices and the straight line is the smallest (least).

This is a “best fit“ line of the data (also re f e r red to as a “re g ression line”).

“Squares“ refers to finding the minimum squared difference between prices and the straight line. The differences are squared because some price points are above the line (positive) and some are below it (negative).

Plotting the final value, or endpoint, of the least squares lines for each bar calculated over a certain lookback period tracks price more closely than a moving average.

The formula for a least squares line is simple. A straight line has a beginning point and rises at a fixed rate. For example, if IBM starts at $100 and moves up for 10 more days, closing at $105, a straight line fit to the data would start at $100 and rise at 50 cents per day, arriving at $105 the final day.

The formula for a straight line is:

a0+a1*t
where

a0 is the initial value of the line;

a1 is the slope of the line;

t is time.

For our example, a0 is $100, a1 is 50 cents, and t is 10 (days). The formula has two terms: coefficients (a0+a1) and variables (t). Mathematicians call this formula a polynomial, which means it has more than one term. Because t is not raised to a power, the polynomial is referred to as a “first-order” polynomial.

Although the least squares line may be an improvement over the moving average, it still changes directions too late for tradable signals. What’s needed is a formula for a line that curves.

A curved line does not change direction at a fixed rate, but at an accelerating or decelerating rate. The mathematical trick to making a line curve is to add an additional term to the formula for a straight line, and have this term be squared (i.e., raised to the second power). The formula for a line that can curve is a0+a1*t+a2*t2. This line takes on the appearance of a parabola. Because it curves, this line fits price data better than a straight line. Because the final term of this polynomial is squared, it is called a “second-order” polynomial. Just as the second-order (parabolic) polynomial calculation displays changes in trend direction sooner than a straight line, higher- order polynomials a p p roximate price better than straight or parabolic lines. The more terms added to a formula, the closer the fit to the price data.

0 comments