MATLAB Examples

To illustrate assigning property values, consider specifying the AR(2) model

Generate data from a known model, specify a state-space model containing unknown parameters corresponding to the data generating process, and then fit the state-space model to the data.

The property values in an existing model are retrievable. Working with models resembles working with struct arrays because you can access model properties using dot notation. That is, type

Create a time-invariant state-space model by passing a parameter-mapping function describing the model to ssm (that is, implicitly create a state-space model). The state model is AR(1)

Fit a regression model with multiplicative ARIMA errors to data using estimate .

Estimate a multiplicative seasonal ARIMA model using estimate . The time series is monthly international airline passenger numbers from 1949 to 1960.

You can also modify model properties using dot notation. For example, consider this AR(2) specification:

Estimate a composite conditional mean and variance model using estimate .

Create a time-invariant, state-space model containing unknown parameter values using ssm .

Estimate the parameters of a VAR(4) model. The response series are quarterly measures of the consumer price index (CPI) and the unemployment rate.

As another illustration, consider specifying the GARCH(1,1) model

Compute and plot the impulse response function for an autoregressive (AR) model. The AR ( p ) model is given by

Estimate a seasonal ARIMA model:

Use arima to specify a multiplicative seasonal ARIMA model (for monthly data) with no constant term.

Specify an ARIMAX model using arima .

Specify an AR ( p ) model with nonzero coefficients at nonconsecutive lags.

Use the shorthand arima(p,D,q) syntax to specify the default AR ( p ) model,

Specify an MA ( q ) model with nonzero coefficients at nonconsecutive lags.

Specify an AR ( p ) model with a Student's t innovation distribution.

A model created by arima has values assigned to all model properties. To change any of these property values, you do not need to reconstruct the whole model. You can modify property values of an

Not all model properties are modifiable. You cannot change these properties in an existing model:

Use the shorthand arima(p,D,q) syntax to specify the default MA

Use the shorthand arima(p,D,q) syntax to specify the default ARIMA ( p , D , q ) model,

Estimate an ARIMA model with nonseasonal integration using estimate . The series is not differenced before estimation. The results are compared to a Box-Jenkins modeling strategy, where

Specify a multiplicative seasonal ARIMA model (for quarterly data) with known parameter values. You can use such a fully specified model as an input to simulate or forecast .

Specify an ARIMA ( p , D , q ) model with known parameter values. You can use such a fully specified model as an input to simulate or forecast .

Simulate sample paths from a stationary AR(2) process without specifying presample observations.

Specify an ARMA ( p , q ) model with known parameter values. You can use such a fully specified model as an input to simulate or forecast .

Plot the impulse response function for an autoregressive moving average (ARMA) model. The ARMA ( p , q ) model is given by

The property Distribution in a model stores the distribution name (and degrees of freedom for the t distribution). The data type of Distribution is a struct array. For a Gaussian innovation

Simulate sample paths from a multiplicative seasonal ARIMA model using simulate . The time series is monthly international airline passenger numbers from 1949 to 1960.

Forecast responses and conditional variances from a composite conditional mean and variance model.

Specify an MA ( q ) model with known parameter values. You can use such a fully specified model as an input to simulate or forecast .

Forecast an ARIMAX model two ways.

Specify a conditional variance model for daily Deutschmark/British pound foreign exchange rates observed from January 1984 to December 1991.

Specify a GARCH model with nonzero coefficients at nonconsecutive lags.

Specify an EGARCH model with nonzero coefficients at nonconsecutive lags.

Specify a GJR model with nonzero coefficients at nonconsecutive lags.

A model created by garch , egarch , or gjr has values assigned to all model properties. To change any of these property values, you do not need to reconstruct the whole model. You can modify

Assess the market risk of a hypothetical global equity index portfolio using a filtered historical simulation (FHS) technique, an alternative to traditional historical simulation and

Model the market risk of a hypothetical global equity index portfolio with a Monte Carlo simulation technique using a Student's t copula and Extreme Value Theory (EVT). The process first

Simulate a conditional variance model using simulate .

Specify a GARCH model with a Student's t innovation distribution.

Simulate from a GARCH process with and without specifying presample data. The sample unconditional variances of the Monte Carlo simulations approximate the theoretical GARCH

Specify an EGARCH model with known parameter values. You can use such a fully specified model as an input to simulate or forecast .

Use the shorthand egarch(P,Q) syntax to specify the default EGARCH ( P , Q ) model, \varepsilon_t = \sigma_t z_t with a Gaussian innovation distribution and

Generate MMSE forecasts from a GJR model using forecast .

Use the shorthand garch(P,Q) syntax to specify the default GARCH ( P , Q ) model, \varepsilon_t = \sigma_t z_t with Gaussian innovation distribution and

Simulate an EGARCH process. Simulation-based forecasts are compared to minimum mean square error (MMSE) forecasts, showing the bias in MMSE forecasting of EGARCH processes.

Specify a GARCH model with known parameter values. You can use such a fully specified model as an input to simulate or forecast .

Use the shorthand gjr(P,Q) syntax to specify the default GJR ( P , Q ) model, \varepsilon_t = \sigma_t z_t with a Gaussian innovation distribution and

Specify a GJR ( P , Q ) model with a mean offset. Use name-value pair arguments to specify a model that differs from the default model.

Specify an EGARCH ( P , Q ) model with a mean offset. Use name-value pair arguments to specify a model that differs from the default model.

Specify a GJR model with known parameter values. You can use such a fully specified model as an input to simulate or forecast .

Specify an EGARCH model with a Student's t innovation distribution.

Specify a GJR model with a Student's t innovation distribution.

Apply both nonseasonal and seasonal differencing using lag operator polynomial objects. The time series is monthly international airline passenger counts from 1949 to 1960.

Considers trending variables, spurious regression, and methods of accommodation in multiple linear regression models. It is the fourth in a series of examples on time series regression,

Select a parsimonious set of predictors with high statistical significance for multiple linear regression models. It is the fifth in a series of examples on time series regression,

Detect influential observations in time series data and accommodate their effect on multiple linear regression models. It is the third in a series of examples on time series regression,

The stationary stochastic process is a building block of many econometric time series models. Many observed time series, however, have empirical features that are inconsistent with the

Use a stable seasonal filter to deseasonalize a time series (using an additive decomposition). The time series is monthly accidental deaths in the U.S. from 1973 to 1978 (Brockwell and

Apply S_{n\times m} seasonal filters to deseasonalize a time series (using a multiplicative decomposition). The time series is monthly international airline passenger counts from 1949

Estimate long-term trend using a symmetric moving average function. This is a convolution that you can implement using conv . The time series is monthly international airline passenger

Take a nonseasonal difference of a time series. The time series is quarterly U.S. GDP measured from 1947 to 2005.

Estimate nonseasonal and seasonal trend components using parametric models. The time series is monthly accidental deaths in the U.S. from 1973 to 1978 (Brockwell and Davis, 2002).

Use the Hodrick-Prescott filter to decompose a time series.

Smooth states of a time-invariant, state-space model that contains a regression component.

Estimate a regression model containing a regression component, and then forecast observations from the fitted model.

Fit a state-space model that has an observation-equation regression component.

Filter states of a time-invariant, state-space model that contains a regression component.

Create a stationary ARMA model subject to measurement error using ssm .

Estimate a random, autoregressive coefficient of a state in a state-space model. That is, this example takes a Bayesian view of state-space model parameter estimation by using the

Generate data from a known model, fit a state-space model to the data, and then forecast states and observations states from the fitted model.

Generate data from a known model, fit a state-space model to the data, and then simulate series from the fitted model.

Implicitly create a diffuse state-space model that contains a regression component in the observation equation. The state model contains an ARMA(1,1) state and random walk.

Generate data from a known model, fit a state-space model to the data, and then smooth the states.

Create a time-varying, state-space model by passing a parameter-mapping function describing the model to ssm (i.e., implicitly create a state-space model).

Create and estimate a state-space model containing time-varying parameters.

Generate data from a known model, fit a diffuse state-space model to the data, and then smooth the states.

Generate data from a known model, fit a diffuse state-space model to the data, and then filter the states.

Generate data from a known model, fit a state-space model to the data, and then filter the states.

Generate data from a known model, fit a diffuse state-space model to the data, and then forecast states and observations states from the fitted model.

Generates data from a known model, fits a state-space model to the data, and then simulates series from the fitted model using the simulation smoother.

Create a time-varying, state-space model containing a random, state coefficient.

Create and estimate a diffuse state-space model containing time-varying parameters.

Create a diffuse state-space model in which one of the state variables drops out of the model after a certain period.

Implicitly create a state-space model that contains a regression component in the observation equation. The state model is an ARMA(1,1).

In the aftermath of the financial crisis of 2008, additional solvency regulations have been imposed on many financial firms, placing greater emphasis on the market valuation and

Forecast a state-space model using Monte-Carlo methods, and to compare the Monte-Carlo forecasts to the theoretical forecasts.

Inspect a squared residual series for autocorrelation by plotting the sample autocorrelation function (ACF) and partial autocorrelation function (PACF). Then, conduct a Ljung-Box

Assess whether a time series is a random walk. It uses market data for daily returns of stocks and cash (money market) from the period January 1, 2000 to November 7, 2005.

Do goodness of fit checks. Residual diagnostic plots help verify model assumptions, and cross-validation prediction checks help assess predictive performance. The time series is

Conduct the Ljung-Box Q-test for autocorrelation.

Test a univariate time series for a unit root. It uses wages data (1900-1970) in the manufacturing sector. The series is in the Nelson-Plosser data set.

Specify a composite conditional mean and variance model using arima .

Conduct a likelihood ratio test to choose the number of lags in a GARCH model.

Calculate the required inputs for conducting a Lagrange multiplier (LM) test with lmtest . The LM test compares the fit of a restricted model against an unrestricted model by testing whether

Check whether a linear time series is a unit root process in several ways. You can assess unit root nonstationarity statistically, visually, and algebraically.

Conduct Engle's ARCH test for conditional heteroscedasticity.

Compare two competing, conditional variance models using a likelihood ratio test.

Calculate the required inputs for conducting a Wald test with waldtest . The Wald test compares the fit of a restricted model against an unrestricted model by testing whether the restriction

Test univariate time series models for stationarity. It shows how to simulate data from four types of models: trend stationary, difference stationary, stationary (AR(1)), and a

Check the model assumptions for a Chow test. The model is of U.S. gross domestic product (GDP), with consumer price index (CPI) and paid compensation of employees (COE) as predictors. The

Estimate the power of a Chow test using a Monte Carlo simulation.

Select statistically significant predictor histories for multiple linear regression models. It is the ninth in a series of examples on time series regression, following the presentation

Detect correlation among predictors and accommodate problems of large estimator variance. It is the second in a series of examples on time series regression, following the presentation in

Illustrates the use of a vector error-correction (VEC) model as a linear alternative to the Smets-Wouters Dynamic Stochastic General Equilibrium (DSGE) macroeconomic model, and applies

Introduces basic assumptions behind multiple linear regression models. It is the first in a series of examples on time series regression, providing the basis for all subsequent examples.

Choose the state-space model specification with the best predictive performance using a rolling window. A rolling window analysis for an explicitly defined state-space model is

Estimate multiple linear regression models of time series data in the presence of heteroscedastic or autocorrelated (nonspherical) innovations. It is the tenth in a series of examples on

Evaluate model assumptions and investigate respecification opportunities by examining the series of residuals. It is the sixth in a series of examples on time series regression,

The use of the likelihood ratio, Wald, and Lagrange multiplier tests. These tests are useful in the evaluation and assessment of model restrictions and, ultimately, the selection of a model

Estimate a multivariate time series model that contains lagged endogenous and exogenous variables, and how to simulate responses. The response series are the quarterly:

Estimate the parameters of a vector error-correction (VEC) model. Before estimating VEC model parameters, you must determine whether there are any cointegrating relations (see Test for

Tests on B answer questions about the space of cointegrating relations. The column vectors in B , estimated by jcitest , do not uniquely define the cointegrating relations. Rather, they

Tests on A answer questions about common driving forces in the system. When constructing constraints, interpret the rows and columns of the n -by- r matrix A as follows:

The differences between orthogonal and generalized impulse response functions (IRF) using the three-dimensional VAR(2) model in docid:econ_ug.brz_lcd , p. 78. The variables in the

Simulates data from an arbitrary 3-D VAR(2) model, and fits a VAR(2) model to the simulated data.

Assess whether a multivariate time series has multiple cointegrating relations using the Johansen test.

Test the null hypothesis that there are no cointegrating relationships among the response series composing a multivariate model.

Convert an n -dimensional VAR model to a VEC model, and then compute and interpret the cointegration rank of the resulting VEC model.

Analyze a VAR model.

Generate impulse responses from this VEC(3) model ( docid:econ_ug.brz_lcd , Ch. 6.7):

Use Monte Carlo simulation via simulate to forecast a VAR model.

Comparing inferences and estimates from the Johansen and Engle-Granger approaches can be challenging, for a variety of reasons. First of all, the two methods are essentially different,

Use forecast to forecast a VAR model.

In addition to testing for multiple cointegrating relations, jcitest produces maximum likelihood estimates of VEC model coefficients under the rank restrictions on B . Estimation

Generate impulse responses of an interest rate shock on real GDP using armairf .

Implement the capital asset pricing model (CAPM) using the Econometrics Toolbox™ VAR model framework.

Create a three-dimensional VAR(4) model with unknown parameters using varm and the shorthand syntax. Then, this example shows how to adjust parameters of the created model using dot

Generate Monte Carlo forecasts from a VEC ( q ) model. The example compares the generated forecasts to the minimum mean squared error (MMSE) forecasts and forecasts from the VAR ( q +1) model

Include exogenous data for several seemingly unrelated regression (SUR) analyses. The response and exogenous series are random paths from a standard Gaussian distribution.

Generate simulated responses in the forecast horizon when some of the response values are known. To illustrate conditional simulation generation, the example models quarterly measures

Forecast responses conditional on the current values of other responses in the forecast horizon. To illustrate conditional forecasting, the example models quarterly measures of the

Create a three-dimensional VAR(4) model with unknown parameters using varm and the longhand syntax. Then, this example shows how to adjust parameters of the created model using dot

Simulate responses from a regression model with nonstationary, exponential, unconditional disturbances. Assume that the predictors are white noise sequences.

Set the innovation distribution of a regression model with AR errors to a t distribution.

Specify a regression model with MA errors, where the nonzero MA terms are at nonconsecutive lags.

Simulate responses from a regression model with ARIMA unconditional disturbances, assuming that the predictors are white noise sequences.

Specify the default regression model with ARIMA errors using the shorthand ARIMA ( p , D , q ) notation corresponding to the following equation:

Specify a regression model with AR errors, where the nonzero AR terms are at nonconsecutive lags.

If you create a regression model with ARIMA errors using regARIMA , then the software assigns values to all of its properties. To change any of these property values, you do not need to

RegARIMA stores the distribution (and degrees of freedom for the t distribution) in the Distribution property. The data type of Distribution is a struct array with potentially two fields:

The basic setup for producing conditional and unconditional forecasts from multiple linear regression models. It is the seventh in a series of examples on time series regression,

How lagged predictors affect least-squares estimation of multiple linear regression models. It is the eighth in a series of examples on time series regression, following the presentation

Examines regression lines of regression models with ARMA errors when the transient effects occur at the beginning of each series.

Plot a regression model with MA errors.

Apply the shorthand regARIMA(p,D,q) syntax to specify the regression model with ARMA errors.

Apply the shorthand regARIMA(p,D,q) syntax to specify the regression model with ARIMA errors.

Simulate sample paths from a regression model with multiplicative seasonal ARIMA errors using simulate . The time series is monthly international airline passenger numbers from 1949 to

Specify a regression model with AR errors without a regression intercept.

Forecast a regression model with ARIMA(3,1,2) errors using forecast and simulate .

Examines regression lines of regression models with ARMA errors when the transient effects are randomly spread with respect to the joint distribution of the predictor and response.

Simulate sample paths from a regression model with AR errors without specifying presample disturbances.

Set the innovation distribution of a regression model with SARIMA errors to a t distribution.

Set the innovation distribution of a regression model with MA errors to a t distribution.

Forecast a multiplicative seasonal ARIMA model using forecast . The response series is monthly international airline passenger numbers from 1949 to 1960.

Estimate the sensitivity of the US Gross Domestic Product (GDP) to changes in the Consumer Price Index (CPI) using estimate .

This demo shows how functionality within Econometric Toolbox can be used to identify and calibrate a simple, intraday pairs trading strategy.

Copyright 2016 The MathWorks Ltd.

This download contains the files used in the April 14, 2011 webinar titled Cointegration and Pairs Trading with Econometrics Toolbox. It is recomended that you watch the recording of the

Demo from the April 14, 2011 webinar titled "Cointegration and Pairs Trading with Econometrics Toolbox."

Kevin Chng

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Contact your local office