TS_GARCH Function [Aggregate]

Used to analyze and forecast volatility in time series data. TS_GARCH computes the estimates of the parameters of a GARCH(p, q) model. GARCH (generalized autoregressive conditional heteroskedasticity) is a generalized model of ARCH; the ARCH computation relates the error variance to the square of a previous period's error.

Syntax

TS_GARCH (timeseries, garch_count, arch_count, xguess_binary_encoding[ , <max_sigma> ] ) 
OVER (window-spec)

Licensing Prerequisites

Available only with RAP – The Trading Edition Enterprise.

Parameters

Usage

As an OLAP-style aggregate function, TS_GARCH produces a single SQL result—a specially encoded variable-length binary result value. Supporting scalar functions accept the binary composite output value and return individual scalar result values from it.

Since an OLAP-style aggregate function returns one result value per input tuple, the same binary composite result is returned for each row within a partition. If you do not specify a PARTITION BY clause in the OVER clause, use SELECT FIRST to reduce the results to a single tuple containing the binary composite result. If you do specify a PARTITION BY clause in the OVER clause, use SELECT DISTINCT to eliminate all but one tuple per partition.

IMSL Mapping

Mapping to the parameters of the IMSL C functions in the external VNI library is performed by TS_GARCH_RESULT supporting scalar functions.

Example

This example computes a GARCH(1,2) model independently for the stock price for each of four specified companies stock prices. The query then uses the DISTINCT qualifier to reduce the set of tuples to one tuple per stock symbol. Finally, one output row is returned containing the stock symbol and all the relevant information describing the GARCH(1,2) model computed for that stock.

The second and third arguments to the TS_GARCH function are the p and q values specifying the GARCH(p,q) type of model is to be used. These values must be positive integer constants or constant expressions.

The fourth argument is the set of seed values for determining the GARCH(p,q) model encoded as a binary constant expression that must be generated via the supporting scalar function TS_DOUBLE_ARRAY.
select stock_symbol,
	TS_GARCH_RESULT_A( garch_res ) as log_likelihood, 
	TS_GARCH_RESULT_AIC( garch_res ) as akaike_info, 
	TS_GARCH_RESULT_USER( garch_res, 1) as sigma_squared, 
	TS_GARCH_RESULT_USER( garch_res, 2) as q_1,
	TS_GARCH_RESULT_USER( garch_res, 3) as p_1,
	TS_GARCH_RESULT_USER( garch_res, 4) as p_2
from ( select distinct 
		 stock_symbol,
		 TS_GARCH(stock_price, 1, 2,
			   TS_DOUBLE_ARRAY(1.2, 0.3, 0.2, 0.3), 4) 
		    over (partition by stock_symbol 
				    order by stock_trade_time) as garch_res
	from stock_trades
	where stock_symbol in (‘XYZ’, XZZ’, ‘ZXZ’, ‘ZZZ’)
	as dt1

Standards and Compatibility

Related concepts
Aggregate Time Series Forecasting and Analysis Functions
Related reference
TS_DOUBLE_ARRAY Function [Scalar]
TS_GARCH_RESULT_A Function [Scalar]
TS_GARCH_RESULT_AIC Function [Scalar]
TS_GARCH_RESULT_USER [Scalar]