jmaih / RISE_toolbox

Solution and estimation of Markov Switching Rational Expectations / DSGE Models
BSD 3-Clause "New" or "Revised" License
106 stars 78 forks source link

Questions about simulate and irf commands #31

Closed mhardinga closed 8 years ago

mhardinga commented 8 years ago

I have some questions about the simulate and irf commands, in particular how the changing probabilities are treated in the simulations.

The first question is when and how the probabilities are taken into account in the simulations. Suppose that I have a (1x1) rise object m: m=rise('mymodel') with two regimes. If, after solving, I use the command simdata = simulate(m) I get one time series for each endogenous variable, and a variable called “nk” (for the markov chain is called nk), which, as I understand tells you whether the model is in regime 1 or 2.

1) Do these simulated time series take the probabilities (either exogenous or endogenous) of changing regime into account, in the sense that the simulated series is some weighted average of each variable obtained by multiplying the probabilities of being in regime 1 or 2 at each point in time, times the values that the variables would have in each state? And is the output of this command identical to the one I would get with the command simdata = simulate(m,'simul_regime',[1 2]); (I couldn’t really compare the outcomes since I don’t know how to trigger a deterministic simulator like the one of Dynare).

2) When you use the command simdata = simulate(m,'simul_regime',1); or simdata = simulate(m,'simul_regime',2); you get one time series for each variable and the nk variable is always in regime 1 or 2, respectively. Are these simulations identical to the case where you simulate the model “as if” it where a single-regime model for each regime? (i.e., simulating each model around its steady state ignoring completely the possibility of changing to a different regime).

3) If, instead, I run the model as (suggested in one of Tao Zha’s examples):

labels={0,'baseline'
            1,'alternative'};

for imod=1:size(labels,1)
            m(imod,1)=rise('mymodel',... % name of the file to read
            'rise_flags',struct('indx_model',labels{imod,1}));
            end

then the rise objet is (2x1) and the outcome of simdata = simulate(m) is two time series for each variable and two independent “nk” series that oscillate between 1 and 2. In this case it is not clear to me if these are just two independent models or a model with two regimes. If it’s the latter, how does this outcome relate to the one described at the very beginning of this post? (i.e, when using the simdata = simulate(m) on the (1x1) rise element described there).

4) As for the IRFs, I guess they are always computed either in one regime or another, i.e. the probabilities don’t affect them in any way?

Two additional questions are:

5) Is it possible to trigger a deterministic simulator like the mt199937ar algorithm with a seed of zero, as in Dynare? So far my simulations generate different results for subsequent runs.

6) How to control the volatility of the exogenous variables (shocks) in the simulations and IRFs? My RISE simulations yield strange results when compared with the ones of Dynare that I have performed for shock sizes consistent with reasonable values for the variables.

jmaih commented 8 years ago

Hi,

  1. Simulation does take into account the probability of switching in different regimes. The time series you get from the output is not an average! At each simulation step, there is a probability of going into the various regimes. RISE does report a time series of the regimes visited for a particular simulation. This is not a deterministic simulation. Running deterministic simulations in RISE is done using a different routine called simulate_nonlinear. Obviously, if you want to do a deterministic simulation in a switching environment, you also need to know the entire future of the regimes.
  2. What you say is correct. By running simdata = simulate(m,'simul_regime',1); essentially you are constraining the system to be in regime 1 throughout the simulation.
  3. You are running simulations over two different models. RISE will simply put the simulations together... for the variables that are common across models. The first simulation will refer to the first model, the second to the second model, etc. This is equivalent to running one simulation for each model and then putting the simulations together.
  4. There are two different forms of IRFs, one is the regime-specific IRF, which is the default. The other is the generalized IRF, which will behave like a simulation in the sense that it will always return only one time series.
  5. In the current version of RISE you set the seed yourself outside of RISE. You can do it simply by setting say, rng(yourseed). RISE does no longer sets seeds internally.
  6. You have not defined what you mean by strange. RISE does not have a concept for standard deviations and variances. They are always equal to 1. You scale the shocks by multiplying them with a constant that RISE treats as a parameter. I hope you are not comparing a regime-switching model against a constant-parameter model.

Cheers,

Junior

mhardinga commented 8 years ago

Hi Junior,

thanks for your answers! points 1., 2., 3. and 5. very clear. To point 6, I didn't know that the sd is always set to 1, so I was feeding a 100% shock instead of a 1% shock in my simulations. With the scaling all works fine.

And a follow up question to point 4.: how does the simulated series for the GIRF look like? e.g., for the 40-period GIRF in Dynare you draw two 140-period series, shock one of them with 1-sd in period 101, and then take the difference between the two, discarding the first 100 obs. How does this work in RISE and can you change the number of observations to be burned in these simulations?

Cheers, Martin

jmaih commented 8 years ago

Hi Martin,

In terms of the basic mechanics, the process is the same. i.e.

Now, when it comes to discarding some preliminary periods of the simulation, my understanding is that the purpose of the burning is to try to make the process forget about the initial conditions. There are several related issues to consider:

If the answer to those 3 questions is yes then the only remaining problem is how long should the burn-in period be.

I am tempted, however, to answer those questions with a NO. And that is why so far I do not include a burn-in period. Perhaps this should be included as an option but I am still not convinced I should.

Cheers,

Junior

mhardinga commented 8 years ago

Hi Junior,

Thank you, I agree in that the issues you mention have no obvious answers. So, to be clear about the details of the process (these details are important since I would like to compare RISE GIRFs with my own calculations), for a t-period GIRF to shock x, the process would be:

  1. simulate the model for t periods
  2. take the mean of the series produced in 1., call it the ergodic mean and use it as initial conditions for the GIRF
  3. shock one series for all t periods
  4. shock the other series for all but the first period
  5. take the difference
  6. repeat N times and take the average

Questions:

a) the simulations in step 1. are performed with all shocks that have a non-zero variance active (and not only with shock x active)? If so, then in step 3. you shock one series with all shocks for t periods and in step 4. you shocks the other series with all shocks but shock x in the in the first period, and with all shocks in the remaining periods, right? b) you didn't refer to the initial conditions, but in RISE's irf.m file it says that the ergodic mean is used. Is it correct how I described it in step 2.?

Cheers, Martin

jmaih commented 8 years ago

Hi Martin,

a) the paths are just regular simulations i.e. all shocks are considered. The only difference between two paths is in the first period where only the shock of interest is activated.

b) In step 2, RISE uses the analytical solution of the ergodic mean or the steady state.

Cheers,

J.

mhardinga commented 8 years ago

Hi Junior,

again on simulation: is it possible to know the history of shocks that have been used to conduct a stochastic simulation in RISE? I would like to use the same history of shocks to simulate models in RISE and Dynare. In Dynare you can specify your shock matrices when using the simult_ function, but I haven't figured out how to get the history of shocks used by the simulate function in RISE. I have tried setting equal seeds for the simulations for models with the same decission rules in both packages, but I still don't get the same outcome for the simulations.

Thank you! Martin

jmaih commented 8 years ago

Hi Martin,

The shocks are in the same list as the endogenous variables.

Please let me know if this is not the case,

Cheers,

Junior

mhardinga commented 8 years ago

Hi Junior, thanks! yes, they are in the list. Cheers, Martin

mhardinga commented 7 years ago

Hi Junior,

I wanted to ask whether there have been any changes to the RISE GIRF function in the last months. I cannot replicate GIRF functions that I had calculated some months ago; for instance, using the command mygirfs=irf(ms,'irf_periods',40,'irf_shock_sign',-1,'irf_type','girf','irf_regime_specific',false,'irf_draws',100); The GIRFs look very erratic, sometimes several orders of magnitude away from the regime-specific irfs (see attached file). I don't know if this is related to the way the GIRFs are computed or if it is a feature of my model. Thank you! Martin en

jmaih commented 7 years ago

Hi Martin,

In order to compute the girf under regime switching a decision has to be made as to whether the regime should change in the alternative simulation, which would make sense at least because under endogenous switching the regime depends on the state of the economy. Naturally two different sequences of shocks are going to imply different states of the economy, which is the case when doing girf (more accurately the two sequences differ only in one place).

But then allowing the regimes to change does not come free, and the cost is precisely the erratic behavior you observe.

There are two potential ways to address the issue

1) Increase the number of simulations. There is no guarantee that the simulations will be a smooth as you want them to especially if the number of simulation is not big enough

2) impose the sequence of regimes from the first simulation to the second simulation. This can be done in the latest version of RISE by setting option "irf_girf_regime_uncertainty" to false.

Hope it helps,

Cheers,

Junior

On Thu, May 18, 2017 at 2:09 PM, mhardinga notifications@github.com wrote:

Hi Junior,

I wanted to ask whether there have been any changes to the RISE GIRF function in the last months. I cannot replicate GIRF functions that I had calculated some months ago; for instance, using the command mygirfs=irf(ms,'irf_periods',40,'irf_shocksign',-1,'irf type','girf','irf_regime_specific',false,'irf_draws',100); The GIRFs look very erratic, sometimes several orders of magnitude away from the regime-specific irfs (see attached file). I don't know if this is related to the way the GIRFs are computed or if it is a feature of my model. Thank you! Martin [image: en] https://cloud.githubusercontent.com/assets/22789110/26201421/22ab8582-3bd3-11e7-90ec-676d22f3075e.jpg

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/jmaih/RISE_toolbox/issues/31#issuecomment-302385538, or mute the thread https://github.com/notifications/unsubscribe-auth/ACagz-_EeBhs55AAC0jLj8gSTXXjXV3Rks5r7DUKgaJpZM4Ka8pt .