# Codes for simple model of Gertler 2012 financial crisis

Hey Everybody,
I am a working on a new simple model of “financial crisis bank risk exposure and government financial policy” Gertler(2012) model in endowment economy. I have tried to write the codes to solve this DSGE model in Octave and find the steady state for using next in Dynare. But I ran the program this morning and after 6 hours, it is still working without any change! Is there anybody who can tell me what is happening? what is the meaning of this? Does it mean there is no solution for this problem? I put the source and the picture of the last line of octave here.
Also octave always warns me by " warning: Using rat() heuristics for double-precision input (is this what you wanted?)" , what is the meaning of this?
exam4.m (768 Bytes)

Why are you trying to solve it symbolically? Matlab by the way says:

[quote]Warning: Possibly spurious solutions.

In symengine (line 57)
In solve (line 294)
In exam4 (line 32)

c1 =

(41088359662199595756018374622987642534756753735219RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[1]^2)/8253645380417850248572855815140150125664158523600 - (2892041258574030020858495305409616575487179946711RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[1])/3301458152167140099429142326056060050265663409440 + (35452014165741131716200886706732739034213493687643RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[1]^3)/6602916304334280198858284652112120100531326818880 + (23416679371841609110617044245346183593671901425RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[1]^4)/20634113451044625621432139537850375314160396309 - 14512991042676875930076788798898918663/263642864415884982981083129533540341800
(41088359662199595756018374622987642534756753735219RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[2]^2)/8253645380417850248572855815140150125664158523600 - (2892041258574030020858495305409616575487179946711RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[2])/3301458152167140099429142326056060050265663409440 + (35452014165741131716200886706732739034213493687643RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[2]^3)/6602916304334280198858284652112120100531326818880 + (23416679371841609110617044245346183593671901425RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[2]^4)/20634113451044625621432139537850375314160396309 - 14512991042676875930076788798898918663/263642864415884982981083129533540341800
(41088359662199595756018374622987642534756753735219RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[3]^2)/8253645380417850248572855815140150125664158523600 - (2892041258574030020858495305409616575487179946711RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[3])/3301458152167140099429142326056060050265663409440 + (35452014165741131716200886706732739034213493687643RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[3]^3)/6602916304334280198858284652112120100531326818880 + (23416679371841609110617044245346183593671901425RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[3]^4)/20634113451044625621432139537850375314160396309 - 14512991042676875930076788798898918663/263642864415884982981083129533540341800
(41088359662199595756018374622987642534756753735219RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[4]^2)/8253645380417850248572855815140150125664158523600 - (2892041258574030020858495305409616575487179946711RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[4])/3301458152167140099429142326056060050265663409440 + (35452014165741131716200886706732739034213493687643RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[4]^3)/6602916304334280198858284652112120100531326818880 + (23416679371841609110617044245346183593671901425RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[4]^4)/20634113451044625621432139537850375314160396309 - 14512991042676875930076788798898918663/263642864415884982981083129533540341800
(41088359662199595756018374622987642534756753735219RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[5]^2)/8253645380417850248572855815140150125664158523600 - (2892041258574030020858495305409616575487179946711RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[5])/3301458152167140099429142326056060050265663409440 + (35452014165741131716200886706732739034213493687643RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[5]^3)/6602916304334280198858284652112120100531326818880 + (23416679371841609110617044245346183593671901425RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[5]^4)/20634113451044625621432139537850375314160396309 - 14512991042676875930076788798898918663/263642864415884982981083129533540341800

c2 =

(6461592747012331985598425731614926703897028254710066614965RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[1])/89480049096909733965970344172527079739403869167795600756 - (36399563446478490096181843230561428595440973757390244534739RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[1]^2)/178960098193819467931940688345054159478807738335591201512 - (3376880053759249216436770012542785043008605929624600392385RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[1]^3)/178960098193819467931940688345054159478807738335591201512 + (291002678943547758701238882116270488899313777170870885000RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[1]^4)/22370012274227433491492586043131769934850967291948900189 + 14052619606303877447483231558998719123242485065798900382107/89480049096909733965970344172527079739403869167795600756
(6461592747012331985598425731614926703897028254710066614965RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[2])/89480049096909733965970344172527079739403869167795600756 - (36399563446478490096181843230561428595440973757390244534739RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[2]^2)/178960098193819467931940688345054159478807738335591201512 - (3376880053759249216436770012542785043008605929624600392385RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[2]^3)/178960098193819467931940688345054159478807738335591201512 + (291002678943547758701238882116270488899313777170870885000RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[2]^4)/22370012274227433491492586043131769934850967291948900189 + 14052619606303877447483231558998719123242485065798900382107/89480049096909733965970344172527079739403869167795600756
(6461592747012331985598425731614926703897028254710066614965RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[3])/89480049096909733965970344172527079739403869167795600756 - (36399563446478490096181843230561428595440973757390244534739RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[3]^2)/178960098193819467931940688345054159478807738335591201512 - (3376880053759249216436770012542785043008605929624600392385RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[3]^3)/178960098193819467931940688345054159478807738335591201512 + (291002678943547758701238882116270488899313777170870885000RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[3]^4)/22370012274227433491492586043131769934850967291948900189 + 14052619606303877447483231558998719123242485065798900382107/89480049096909733965970344172527079739403869167795600756
(6461592747012331985598425731614926703897028254710066614965RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[4])/89480049096909733965970344172527079739403869167795600756 - (36399563446478490096181843230561428595440973757390244534739RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[4]^2)/178960098193819467931940688345054159478807738335591201512 - (3376880053759249216436770012542785043008605929624600392385RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[4]^3)/178960098193819467931940688345054159478807738335591201512 + (291002678943547758701238882116270488899313777170870885000RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[4]^4)/22370012274227433491492586043131769934850967291948900189 + 14052619606303877447483231558998719123242485065798900382107/89480049096909733965970344172527079739403869167795600756
(6461592747012331985598425731614926703897028254710066614965RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[5])/89480049096909733965970344172527079739403869167795600756 - (36399563446478490096181843230561428595440973757390244534739RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[5]^2)/178960098193819467931940688345054159478807738335591201512 - (3376880053759249216436770012542785043008605929624600392385RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[5]^3)/178960098193819467931940688345054159478807738335591201512 + (291002678943547758701238882116270488899313777170870885000RootOf(z^5 + (37673186677331z^4)/11705388552000 - (176952252581991899z^3)/65908653415605000 - (433165132324398560503z^2)/56549624630589090000 + (243488330353295899z)/428406247201432500 + 245018894734010518801/169648873891767270000, z)[5]^4)/22370012274227433491492586043131769934850967291948900189 + 14052619606303877447483231558998719123242485065798900382107/89480049096909733965970344172527079739403869167795600756
[/quote]

Thank you so much for the reply.
Is there any other way to solve it except using symbolic toolbox? It would be appreciated if you help me find easier way! I have just moved to Octave because its symbolic toolbox is free.
Can I ask you how you got this solution and what is “z” in this solution?
Many many Thanks

This is the output I got when running your code in Matlab. My question was why you do not try to search for the steady state numerically, but rather symbolically.

could you put a traceable sample of finding steady state numerically?! I tried to put my equations in matlab and it always says it is undefined, so I thought I have to use symbolic toolbox and move to Octave!
anyway, as i search in the forum it seems there is some template to find ss by dynare, I downloaded them (I put it here, just for information), Is it possible to change them to solve my model and then import the result to my basic dynare codes?
Thanks a lot.
exam4 is my equations!
exam4.m (868 Bytes)

Please step back for a moments and explain what you are trying to do. Do you need to compute the steady state of the nonlinear model to enter them as parameters in the linearized version entered into Dynare?

General remark: the easiest way is to plug the steady state equations into each other until you get a small number of equations in the same number of unknowns. The NK_baseline.mod in the Dynare examples folder is an example of this approach.

Yes, Exactly. I have already pluged the steady state equations into each other until getting a small number of equations in the same number of unknowns. You can see this in exam4.m file. I put all equations together and finally I get 2 equation (eq1 & eq2) which are a system equations which should be solved simultaneously to get Qbar and Omegabar. When we have these two, we can get all other steady states. (My friend solved my equations in maple and get the answer, even I still can’t solve that by Octave!). as you told it might be solved numerically (How?).
I put the answers my friend gave me,(Omegabar = 1.3857; Qbar = 97.961) in my basic dynare code. but it has still problem on the second equation(in linear version) and could not solve the simple version !
I put 2 versions of my dynare code here, simple and linearized one.
Another question is: is there any other way to put the solved steady state automatically in the dynare code and not solving other program and put the result manually in dynare?
Thanks.
lucasline2.mod (3.33 KB)
lucas3.mod (2.98 KB)

Your mod-files are still not correct.

lucasline.mod must be wrong. Using resid(1) before steady yields

[quote]Residuals of the static equations:

Equation number 1 : 0
Equation number 2 : 0
Equation number 3 : 0
Equation number 4 : 0
Equation number 5 : 0
Equation number 6 : 0
Equation number 7 : 0
Equation number 8 : 0
Equation number 9 : 0
Equation number 10 : 0
Equation number 11 : 0
Equation number 12 : 0
Equation number 13 : -1
Equation number 14 : -1
Equation number 15 : 0
Equation number 16 : 0
Equation number 17 : 0
Equation number 18 : 0
Equation number 19 : 0
Equation number 20 : 0
Equation number 21 : 0[/quote]

Thus, equations 13 and 14 are not linear. In a linearized model, all variables are percentage deviations from steady state and thus 0 in steady state. The initval block is thus redundant

Regarding lucas3.mod you have

[quote]MODEL_DIAGNOSTICS: The following endogenous variables aren’t present at the current period in the model:
Rl
Re
[/quote]

With

the unstable version (to be Dynare 4.5 is able to find the steady state given your initial values)

Dear,
Thank you for the reply. I have corrected the problem of linear version, Now I have the ss , though still eigenvalues are larger than 1, and can’t print any result.
The unstable version is (dynare-2015-07-21-win.zip)? I got this and run the nonlinear model with "steady( maxit=1000), but still the same result (can’t solve). Could you give me the link to get dynare 4.5, and the result you get with this version.
Merci
lucasline2.mod (3.37 KB)

You are not listening. You still posted a linear version with an initval block different from 0. That makes no sense.
The nonlinear version needs to have the outlined errors fixed as well. If it does not work, post the updated version.

Regarding the eigenvalues: It seems you are neglecting Dynare’s timing convention for predetermined state variables like capital or debt. Search the forum or see the manual for more information on this. You need to fix this. Your code has no variables dated (-1), which is suspicious if you have Euler equations.

oh Yes, you’re totally right. I have just change the model and I got the steady state as you told.

Lambda 0
uc 0
C 0
x 0
mue 0
mus 0
mun 0
Theta 0
phi 0
Omega 0
Rl 0
R 0
Re 0
Q 0
Y 0
N 0
D 0
E 0
Pi 0
Nn 0
epers 0[/quote]

I also change the nonlinear one, (I had a mistake in defining the chock: in nonlinear one it should be ```log(Y)=rho*log(Y(-1))+psi; // output 21 ``` and in linear one should be the same without log! ). Thanks , now I have the steady!
[/code]I have this result:

but I have still the problem of eigenvalues! I have to work on what you told to find the issue!
lucas3.mod (3.02 KB)