Simulate Responses Using filter
Illustrate the relationship between
filter by estimating a 4-D VAR(2) model of the four response series in Johansen's Danish data set. Simulate a single path of responses using the fitted model and the historical data as initial values, and then filter a random set of Gaussian disturbances through the estimated model using the same presample responses.
Load Johansen's Danish economic data.
For details on the variables, enter
Create a default 4-D VAR(2) model.
Mdl = varm(4,2); Mdl.SeriesNames = DataTimeTable.Properties.VariableNames;
Estimate the VAR(2) model using the entire data set.
EstMdl = estimate(Mdl,DataTimeTable.Variables);
When reproducing the results of
Set the same random number seed using
Specify the same presample response data using the
Set the default random seed. Simulate 100 observations by passing the estimated model to
simulate. Specify the entire data set as the presample.
rng("default") YSim = simulate(EstMdl,100,Y0=DataTimeTable.Variables);
YSim is a 100-by-4 matrix of simulated responses. Columns correspond to the columns of the variables in
Set the default random seed. Simulate 4 series of 100 observations from the standard Gaussian distribution.
rng("default") Z = randn(100,4);
Filter the Gaussian values through the estimated model. Specify the entire data set as the presample.
YFilter = filter(EstMdl,Z,Y0=DataTimeTable.Variables);
YFilter is a 100-by-4 matrix of simulated responses. Columns correspond to the columns of the variables in the data
Data. Before filtering the disturbances,
Z by the lower triangular Cholesky factor of the model covariance in
Compare the resulting responses between
(YSim - YFilter)'*(YSim - YFilter)
ans = 4×4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The results are identical.