Investment Studio > Expressions > Functions > Statistical > TREND

float array[*][1] trend(float array known_ys, float array known_xs = {1, 2, 3 [, ...]}, float array new_xs = known_xs, boolean fit_constant = TRUE)

Returns a column vector containing y values for the specified points (new_xs) on the plane in N dimensions (independent variables)

  N  
y(x1, x2, x3, ... xN) = b + S mk^xk
  k = 1  

providing the best (least squares) fit to the known data pairs (known_ys, known_xs).

known_ys is the set of known y values. If it contains a single column (row), each column (row) in known_xs is interpreted as containing the values of a separate independent variable. Note that this can be used for polynomial fitting by putting different powers of the same independent variable in different columns (rows).

If known_ys contains multiple columns and rows, known_xs is interpreted as containing the values of a single independent variable. Corresponding elements in the two arrays are then determined by order of appearance (reading from left to right, top to bottom).

known_xs is the set of known x values. It can contain one or more independent variables. If only one independent variable is used, known_xs and known_ys can have any shape(s) as long as they contain the same number of elements; corresponding elements in the two arrays are then determined by order of appearance (reading from left to right, top to bottom). If more than one independent variable is used, known_ys must be a column (row) vector, and known_xs must contain a column (row) for each independent variable.

known_xs may be omitted, in which case it defaults to the array {1, 2, 3, ...} with the same number of elements as known_ys.

new_xs is the set of x values for which y values are to be computed using the best (least squares) fit of an exponential surface to the known data pairs. It must contain a column (row) for each independent variable, i.e. for each column (row) in known_xs if known_ys contains a single column (row).

new_xs may be omitted, in which case it defaults to known_xs.

fit_constant is used to specify how the b (intercept) parameter of the fit is to be computed. If fit_constant = TRUE, the value of b returned by the normal least square fit is used. If fit_constant = FALSE, b is forced to = 1 and the mk parameters are adjusted accordingly to still fit the known y values.

If fit_constant is omitted, it defaults to TRUE.

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

Example

On January 1, 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 the following projection for the years 2000 and 2001:

=trend({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}, {2000, 2001})

Rounded to one decimal, this returns {{10826.4}, {11761.3}}. The actual close on December 29, 2000, was 10788, an error of less than 0.4%; not bad! On the other hand, the close on December 31, 2001, was 10021.5, an error of more than 17%.

No tree grows all the way to heaven.

See also forecast, growth, linest, logest.