Investment Studio > Expressions > Functions > Statistical > FORECAST

float forecast(float x, float array known_ys, float array known_xs)

Returns a y value for the specified x value, computed by linear regression analysis (i.e. least square fit of a straight line to the data) of a set of known y(x) pairs.

x is the coordinate for which y is to be computed.

known_ys and known_xs contain the known y(x) pairs. Arrays with different dimensions are allowed as long as they all have the same number of elements (e.g. 2 x 3 and 3 x 2 arrays). Corresponding elements are determined by order of appearance (reading from left to right, top to bottom).

All array elements are converted to float, with exclusion if conversion fails.

Example

To forecast where the Dow Jones Industrial Average would close year 2000, an investor with a strong belief in linear regression could have taken the DJIA's last close for each year in the 90s to come up with

=forecast(2000, {2633.7, 3168.8, 3301.1, 3754.1, 3834.4, 5117.1, 6448.3, 7908.3, 9181.4, 11497.1}, {1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999})

» 10826.4. The actual close (on December 29, 2000) was 10788, an error of less than 0.4%; not bad! On the other hand, adding the 2000 close to the series and using it to forecast the 2001 close would have led our simple-minded investor seriously astray, with a prediction of Dow 11747.4, overshooting the actual close (10021.5) by more than 17%.

No tree grows all the way to heaven.

See also growth, intercept, linest, logest, slope, trend.