Description
This function fits a line through the series of input data over the lookback
period using the least squares fit method. intercept will produce a
set of y-intercept values for the line that best fits data points within
the lookback period. The y-intercept will be the value of y where the
line fit of the data over the lookback period intersects with zero on the
time scale or x-axis (i.e. at the left most end of the chart).
This is a useful tool when combined with lineslope
if one wished to plot a
running line fit through a set of data.
Inputs
slope is a double precision input series of line slopes for each
data point.
valx is the input series of x-axis (usually time) data which will
feed into the least squares method. valy is the y-axis data. valx and
valy must have the same vector lengths.
valx and valy may be real double precision or
integer vector (single column) matrices. The lookback
period, p, must be an integer scalar.
Output
The output will be an double precision vector of the same length as the
input vectors, slope, valx and valy. The vector will contain the
y-intercepts of the fitted line at for the line that best fits the input data over the
lookback period. Note that for values prior to the lookback
period, the output will be filled with the
first valid value of the calculation (i.e. at position p)
up to the index p-1, since the calculation could not be performed for time periods
prior to p. EAS substitutes the value of the slope at point
p into the intercept calculation to preserve the matrix length so
that the output may be used in further calculations using matrices of the same length.
Example
Entering intercept(lineslope(1::10,real(1::10)^2,5),1::10,real(1::10)^2,5) in the
O-Matrix Command line
produces the following output:
{
-7.00
-7.00
-7.00
-7.00
-7.00
-14.00
-23.00
-34.00
-47.00
-62.00
}
Notice that the output vector value positions 1-4 are equal to the intercept at
point 5, which is the value of the lookback period.