Matlab, Econometrics toolbox - Simulate ARIMA with deterministic time-varying variance

StackOverflow https://stackoverflow.com/questions/12781748

  •  05-07-2021
  •  | 
  •  

質問

DISCLAIMER: This question is only for those who have access to the econometrics toolbox in Matlab.

The Situation: I would like to use Matlab to simulate N observations from an ARIMA(p, d, q) model using the econometrics toolbox. What's the difficulty? I would like the innovations to be simulated with deterministic, time-varying variance.

Question 1) Can I do this using the in-built matlab simulate function without altering it myself? As near as I can tell, this is not possible. From my reading of the docs, the innovations can either be specified to have a constant variance (ie same variance for each innovation), or be specified to be stochastically time-varying (eg a GARCH model), but they cannot be deterministically time-varying, where I, the user, choose their values (except in the trivial constant case).

Question 2) If the answer to question 1 is "No", then does anyone see any reason why I can't edit the simulate function from the econometrics toolbox as follows: a) Alter the preamble such that the function won't throw an error if the Variance field in the input model is set to a numeric vector instead of a numeric scalar. b) Alter line 310 of simulate from:

E(:,(maxPQ + 1:end)) = Z * sqrt(variance);

to

E(:,(maxPQ + 1:end)) = (ones(NumPath, 1) * sqrt(variance)) .* Z;

where NumPath is the number of paths to be simulated, and it can be assumed that I've included an error trap to ensure that the (input) deterministic variance path stored in variance is of the right length (ie equal to the number of observations to be simulated per path).

Any help would be most appreciated. Apologies if the question seems basic, I just haven't ever edited one of Mathwork's own functions before and didn't want to do something foolish.

UPDATE (2012-10-18): I'm confident that the code edit I've suggested above is valid, and I'm mostly confident that it won't break anything else. However it turns out that implementing the solution is not trivial due to file permissions. I'm currently talking with Mathworks about the best way to achieve my goal. I'll post the results here once I have them.

役に立ちましたか?

解決

It's been a week and a half with no answer, so I think I'm probably okay to post my own answer at this point.

In response to my question 1), no, I have not found anyway to do this with the built-in matlab functions.

In response to my question 2), yes, what I have posted will work. However, it was a little more involved than I imagined due to matlab file permissions. Here is a step-by-step guide:

i) Somewhere in your matlab path, create the directory @arima_Custom.

ii) In the command window, type edit arima. Copy the text of this file into a new m file and save it in the directory @arima_Custom with the filename arima_Custom.m.

iii) Locate the econometrics toolbox on your machine. Once found, look for the directory @arima in the toolbox. This directory will probably be located (on a Linux machine) at something like $MATLAB_ROOT/toolbox/econ/econ/@arima (on my machine, $MATLAB_ROOT is at /usr/local/Matlab/R2012b). Copy the contents of @arima to @arima_Custom, except do NOT copy the file arima.m.

iv) Open arima_Custom for editing, ie edit arima_Custom. In this file change line 1 from:

classdef (Sealed) arima < internal.econ.LagIndexableTimeSeries

to

classdef (Sealed) arima_Custom < internal.econ.LagIndexableTimeSeries

Next, change line 406 from:

function OBJ = arima(varargin)

to

function OBJ = arima_Custom(varargin)

Now, change line 993 from:

if isa(OBJ.Variance, 'double') && (OBJ.Variance <= 0)

to

if isa(OBJ.Variance, 'double') && (sum(OBJ.Variance <= 0) > 0)

v) Open the simulate.m located in @arima_Custom for editing (we copied it there in step iii). It is probably best to open this file by navigating to it manually in the Current Folder window, to ensure the correct simulate.m is opened. In this file, alter line 310 from:

E(:,(maxPQ + 1:end)) = Z * sqrt(variance);

to

%Check that the input variance is of the right length (if it isn't scalar)
if isscalar(variance) == 0
    if size(variance, 2) ~= 1
        error('Deterministic variance must be a column vector');
    end
    if size(variance, 1) ~= numObs
        error('Deterministic variance vector is incorrect length relative to number of observations');
    end
else
    variance = variance(ones(numObs, 1));
end
%Scale innovations using deterministic variance
E(:,(maxPQ + 1:end)) =  sqrt(ones(numPaths, 1) * variance') .* Z;

And we're done!

You should now be able to simulate with deterministically time-varying variance using the arima_Custom class, for example (for an ARIMA(0,1,0)):

ARIMAModel = arima_Custom('D', 1, 'Variance', ScalarVariance, 'Constant', 0);
ARIMAModel.Variance = TimeVaryingVarianceVector;
[X, e, VarianceVector] = simulate(ARIMAModel, NumObs, 'numPaths', NumPaths);

Further, you should also still be able to use matlab's original arima class, since we didn't alter it.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top