Home | Command Reference | Run Example

GLS Command

The GLS command estimates a Generalized Least Squares regression from an existing REGRESSION result. It is useful when the variance of the regression residuals is not constant through time. Instead of treating every observation equally, the command builds a diagonal omega matrix from a rolling estimate of residual variance and then re-estimates the regression using inverse-variance weights.

This version of GLS is especially useful for financial and macroeconomic time series where volatility changes over time. For example, daily market returns often have quiet periods and crisis periods. A rolling GLS regression allows the model to reduce the influence of high-variance periods without discarding them.

Syntax

GLS(regression, window)

The first argument must be a regression result. The second argument is the rolling window size used to estimate the local residual variance.

Example

GLS(REGRESSION(LOGDIFF(LIST(VIXCLS,SP500))),63)

This example first estimates a regression between daily log changes in the VIX and daily log changes in the S&P 500. It then re-estimates the model using GLS with a 63-observation rolling residual variance window. For daily data, 63 observations is roughly one trading quarter.

How It Works

The command starts with an ordinary regression and obtains its residuals. It then computes a rolling estimate of residual variance over the requested window. These rolling variances form the diagonal of the omega matrix:

Omega = diagonal(rolling residual variance)

The regression is then estimated using the GLS formula:

Beta = inverse(X' Omega^-1 X) X' Omega^-1 Y

Observations from high-volatility periods receive lower weight. Observations from low-volatility periods receive higher weight. This can produce more stable coefficient estimates and more appropriate standard errors when heteroskedasticity is present.

Choosing the Window

The rolling window should reflect the frequency of the data and the kind of volatility variation being modeled.

GLS(REGRESSION(LOGDIFF(LIST(VIXCLS,SP500))),21)   // about one trading month
GLS(REGRESSION(LOGDIFF(LIST(VIXCLS,SP500))),63)   // about one trading quarter
GLS(REGRESSION(LOGDIFF(LIST(VIXCLS,SP500))),126)  // about half a trading year
GLS(REGRESSION(LOGDIFF(LIST(VIXCLS,SP500))),252)  // about one trading year

Shorter windows adapt more quickly but can be noisy. Longer windows are smoother but may react slowly to regime changes.

Multiple Regression

The command also works with multiple explanatory variables. The regression object may contain one or many independent variables.

GLS(REGRESSION(LOGDIFF(LIST(VIXCLS,SP500,NASDAQCOM,DJIA))),63)

In this case, the first series is the dependent variable and the remaining series are explanatory variables. The same rolling omega matrix is applied to the full regression.

Interpreting the Output

The GLS output includes the fitted coefficients, standard errors, t-statistics, residual diagnostics, fitted values, and charts. The coefficient estimates may be close to ordinary least squares when the residual variance is fairly stable. Larger differences can appear when volatility changes sharply over time.

The GLS command uses a rolling residual variance estimate rather than each individual squared residual. Using each residual squared directly can create extreme weights when a residual is near zero. The rolling version is more stable and is better suited for production use.

Related Commands

REGRESSION estimates the original ordinary least squares model. The GLS command takes that regression result and re-estimates it using rolling inverse-variance weights.