Home | Command Reference | Run Example

Constrained OLS Command

The CONSTRAINED_OLS command estimates a linear regression while forcing the predictor coefficients to satisfy a budget constraint. It is useful when the regression coefficients should behave like portfolio weights, index weights, or factor exposures that must add up to a fixed total.

Example

CONSTRAINED_OLS(logdiff(LIST(SP500,DJIA,NDX100)),1)

This example models the daily log returns of the S&P 500 using the Nasdaq 100 and Dow Jones Industrial Average. The first series is the dependent variable, while the remaining series are predictors. The final argument specifies a budget of 1, forcing the regression coefficients to sum to one.

Syntax

CONSTRAINED_OLS(seriesList, budget)

The input must be a list of time series:

Model

Y = α + β1X1 + β2X2 + ... + βnXn + ε

Unlike ordinary least squares, the beta coefficients are estimated subject to a constraint:

β1 + β2 + ... + βn = budget

By default, the budget is 1.0. This makes the command especially useful for replication, attribution, and constrained factor modeling.

Output

The command returns a panel containing:

Extractable Results

Individual results can be extracted from the model:

model.extract("actual_vs_fitted")
model.extract("betachart")
model.extract("r2chart")
model.extract("text")

Interpretation

A constrained regression is helpful when the coefficients must obey an economic or financial restriction. For example, if the betas represent portfolio weights, forcing them to sum to 1.0 keeps the fitted model comparable to a fully invested portfolio.

The fitted-vs-actual chart shows how closely the constrained model tracks the dependent series. The rolling beta chart shows whether the constrained exposures are stable through time. The rolling R² chart shows whether the explanatory power of the model is improving or deteriorating.

Typical Use Cases

Notes

The command aligns all input series to the same date range before estimation. Standard errors and t-statistics are approximate because they are computed using the unconstrained OLS framework as a diagnostic reference.