Calculates the sample autocorrelation function of a stationary
time series.
Syntax
TS_AUTOCORRELATION (timeseries_expression, lagmax, lag_elem)
OVER (window-spec)
Licensing Prerequisites
Available only with RAP – The Trading Edition Enterprise.
Parameters
- timeseries_expression – a numeric expression, generally a column name, containing
an element in a time series.
- lagmax – an integer specifying the maximum lag of autocovariances, autocorrelations,
and standard errors of autocorrelations. The integer must be greater
than or equal to 1, and less than the number of elements in the
time series.
- lag_elem – an integer specifying which element in the autocorrelation
array is to be returned. The integer must be greater than zero,
and less than or equal to lagmax.
- window-spec – TS_AUTOCORRELATION is an OLAP function requiring
an OVER () clause.
Usage
This time series function returns a double-precision floating-point
value representing the autocorrelation value. TS_AUTOCORRELATION calls
the function imsls_d_autocorrelation in
the IMSL libraries.
IMSL Mapping
The arguments of TS_AUTOCORRELATION map to the IMSL
library function imsls_d_autocorrelation() as
follows:
params = imsls_d_autocorrelation(n_objs, x[], lagmax, 0);
- n_objs – contains the number of rows in the current window frame.
- x[] – contains the value of timeseries_expression for
the current window frame.
- lagmax – maps to the user-defined aggregate function argument lag_max.
For detailed information on how the function imsls_d_autocorrelation performs time
series calculations, see IMSL C Numerical Library User’s Guide: Volume 2 of 2 C Stat Library.
Example
This example shows a SQL statement containing
the TS_AUTOCORRELATION function and the data values returned
by the function. This example uses the example input data table (called DATASET)
as its input data.
The following SQL statement returns the second element from
an array containing autocorrelations of the time series data from
the
data column:
SELECT TS_AUTOCORRELATION(data,2,2) OVER (ORDER BY ROWNUM rows BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS res FROM DATASET
Sybase IQ returns 50 rows, each containing the same value:
Values Returned from TS_AUTOCORRELATION
res
|
0.803659
|
0.803659
|
0.803659
|
0.803659
|
0.803659
|
0.803659
|
0.803659
|
0.803659
|
0.803659
|
...
|
0.803659
|
Standards and Compatibility
- SQL – ISO/ANSI SQL compliant
- Sybase – not compatible with SQL Anywhere or Adaptive Server Enterprise