IRIS-Solutions-Team / IRIS-Toolbox

[IrisToolbox] for Macroeconomic Modeling
Other
92 stars 42 forks source link

Maximum/Minimum #244

Closed DerWiMa closed 4 years ago

DerWiMa commented 4 years ago

Hello everyone,

I receive spurious results using MATLABs inbuilt max or min function in an IRIS model file. While MATLAB of course evaluates e.g. min(0.105,max(1,3))=0.105, IRIS evaluates min(0.105,max(1,3)) to 1.

I use both a minimum and a maximum function within a dynamic equation which then results into wrong values. What can I do about it?

Thanks in advance!

jaromir-benes commented 4 years ago

Could you please upload an example of when this happens? Thanks, Jaromir

On Wed, Apr 8, 2020 at 2:16 PM DerWiMa notifications@github.com wrote:

Hello everyone,

I receive spurious results using MATLABs inbuilt max or min function used in an IRIS model file. While MATLAB of course evaluates e.g. min(0.105,max(1,3))=0.105, IRIS evaluates min(0.105,max(1,3)) to 1.

I use both a minimum and a maximum function within a dynamic equation which then results into wrong values. What can I do about it?

Thanks in advance!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/IRIS-Solutions-Team/IRIS-Toolbox/issues/244, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGCVKKQZD26VRDVSJEADHILRLRTIHANCNFSM4MD4ICHA .

DerWiMa commented 4 years ago

Dear Jaromir,

I tried to create a minimal working example using your SPBC model file. (I am not sure if I am allowed to distribute my original working file publicly since I retrieved parts of it externally, but in case needed I can send it by private message)

When I run the Example_Min.m file (i.e. the simulation), I obtain again min(0.105,max(1,3))=1 in variable s.test. Furthermore, I have altered the policy rate R to contain min() and max(). Though, by calculating manually, I receive different values than IRIS does.

Best,

DerWiMa

MWE.zip

jaromir-benes commented 4 years ago

Hi DerWiMa

You're making a couple of mistakes in your extensions to the model files. The three most important are these:

---[1]---

The results you're getting for the variable test are what they are because you simulate the model with the option Deviation=true.

This option means that all values in the input database as well as all values in the output database are DEVIATIONS from the respective steady states. The deviations are computed either as x - x_ss (difference from the steady state) for linearized variables, or as x / x_ss (ratio over the steady state) for log variables, where x_ss is the steady state for the respective variable.

Because there is !log-variables !all-but Short, Infl, Growth, Wage declaration in the model file, all variables (except the four listed) are log-variables, and hence the results for all variables (except those four) are the ratio over the steady state. If you see 1, this means that the simulated values are exactly equal to steady state.

Hence, the value returned from the simulate command (test=1) simply means that the test variable is always on its steady state in all periods, which is of course a trivial result since the variable is a static constant.

To simulate the actual values, not the deviations from steady state, you need to make two changes:

  1. The input databank needs to be created using the sstatedb command, not zerodb

  2. Remove the option Deviation=true from the simulate command.

---[2]---

Look very carefully at the way the model is coded up and calibrated, and the variables interpreted.

The interest rate R (unlike the measurement variable Short) is expressed as the GROSS QUARTERLY RATE OF INTEREST. In other words, if e.g. R = 1.02, this means 2% quarterly, or approx 8.24% annualized. Conversely, a 0.25% PA interest rate would be R = (1+0.0025)^(1/4) = 1.00062. A zero interest rate would not be R = 0, but rather R = 1.

The max and min values your choosing for R are therefore incorrect. If you want to impose a zero lower bound on R, then Rmin must be 1, and Rmax must be definitely greater than 1.

Also, again, whenever you simulate with Deviation=true, remember that R is a log variable, and hence the results will be in the form of R / R_ss (where R_ss is the steady state of R). I recommend that you simulate without the Deviation=true option, and use sstatedb to create the input databank. That way, the results will be more straightforward to interpret.

---[3]---

By default, IRIS simulates models using a first-order approximation algorithm (linearizing or log-linearizing the variables). If you wish to simulate the model so that some of the equations are preserved in their nonlinear form using, you need to use the =# sign in the model file to select these equations (which you did), and choose a so-called equation-selective nonlinear solution method (instead of the first-order method) in the simulate command, like this:

s = simulate( ...
    m, d, 1:40, ...
    'Deviation=', true, ...
    'AppendPresample=', true, ...
    'Method=', 'Selective' ...
);

You may also need to manipulate some other options to achieve convergence if you bump into convergence issues.


Lastly, a recommendation. I'm not sure what exactly you're trying to achieve with the Rmin and Rmax. If you, however, wish to impose bounds on the policy interest rate, you need to do it this way:

First, create a new variable, called say R_unc (as for R unconstrained). The equation for R_unc is the usual policy reaction function without any constraints where there is R (not R_unc) on the RHS for its lag. In the simple_SPBC model, that would simply be

log(R_unc) = rhor*log(R{-1}) + (1-rho)* etc... etc.... etc...

where R_unc is the new variable which needs to be added to the list of variables.

Then, you add another equation to define the constraint. For example, a lower bound would be defined as

R = min(Rmin, R);

where Rmin is a parameter set to 1 for zero floor (because 1 is the gross rate of interest corresponding to a zero net interest rate), or alternatively a little bit below 1 allowing for negative interest rates (such as those in the Euro area), e.g. Rmin=(1-0.005)^(1/4) for a -0.50% PA bound.

Hope this helps. Let me know if you have any other issues.

Best Jaromir


DerWiMa commented 4 years ago

Dear Jaromir,

Thanks for your extensive answer! The modifications were just for illustrating the "issue" with maximum/minimum, it was by no means intended to be a realistic modeling strategy. I was indeed unaware of the "deviations=true" option, hence my interpretation mistake.

Ah, good point with the selection option! I did not know that either (I am working with IRIS since a week). One question regarding the usage of =#: When is the use actually needed? Only when one wishes to preserve the nonlinear form e.g. R = min(Rmin, R)?

Best

DerWiMa

jaromir-benes commented 4 years ago

Hi DerWiMa

There are two nonlinear simulation methods in IRIS - one is a tradition quasi Newton based stacked-time method, which simply takes all equations, stacks them across a larger number of periods, and solves them as one big system of nonlinear equations. This is very costly (in terms of CPU time and memory) for larger models.

The other approach is the equations-selective nonlinear solver. It runs a first-order approximate solution, however it iterates to find add-factors to selected equations such that the simulated paths will satisfy those equations exactly, in their nonlinear forms. This method is much more efficient,

For this, you use the =# sign in the model file to mark those equations you wish to preserve as nonlinear.

Again, keep in mind that the default solution method is FirstOrder. You need to change this to Selective.

Best Jaromir

On Thu, Apr 9, 2020 at 4:21 PM DerWiMa notifications@github.com wrote:

Dear Jaromir,

Thanks for your extensive answer! The modifications were just for illustrating the "issue" with maximum/minimum, it was by no means intended to be a realistic modeling strategy. I was indeed unaware of the "deviations=true" option, hence my interpretation mistake.

Ah, good point with the selection option! I did not know that either (I am working with IRIS since a week). One question regarding the usage of =#: When is the use actually needed? Only one wishes to preserve the nonlinear form e.g. R = min(Rmin, R)?

Best

DerWiMa

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/IRIS-Solutions-Team/IRIS-Toolbox/issues/244#issuecomment-611554693, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGCVKKXUNAYW5PCLCDTFO6TRLXKXVANCNFSM4MD4ICHA .

DerWiMa commented 4 years ago

Thanks for the explanation!