BasicRealBusinessCycleModel Question

Are the MATLAB codes BasicRealBusinessCycleModel.m and BasicRealBusinessCycleModel_BusinessCycleStatistics.m able to handle multiple endogenous state variables and/or no choice variable? I have tried a=2, z=1, d=0, following the procedure in the VFI toolkit, and I am successful in the value function iteration, but the time series simulation fails. I am wondering if it is an error on my end, or are the time series codes for the RBC model not adjusted for a different number of state variables.

Thank you.

Dear Algonquin,

The toolkit should be able to handle that just fine. Could you please email me a copy of your codes (robertdkirkby@gmail.com) and I will take a look and let you know. (some things about setting up the time series simulations may need to be adjusted, but the actual simulation commands are unchanged)

Robert

For those reading. We sorted this out by email (was mostly to do with my not doing a lot of maintenance of the parallel cpu codes for value function iteration and the time series simulation codes as I don’t often use them). All working now and Algonquin was kind enough to let me upload a (lightly edited) version of his codes implementing a slight extension of the RBC to two endogenous states and using parallel cpu here.

The codes are here: https://www.dropbox.com/sh/uistf73bbmkhrz7/AAAYIxXuIrKC34GQ85Xv1EgKa?dl=0

Dear Robert,

The Toolkit is very helpful!!! Thanks so much. This two endogenous states example you provided is also inspiring.

However, I have three questions here:

  1. You set the vfoptions parallel=1, which means you dont allow GPU here? May I know why? Is it because GPU is not helping speed up?
  2. I wonder if I use parallel option =2, will the code work? I tried on my laptop and it got stuck, saying ‘an unexpected error occured during cuda execution. The CUDA error was unspecified launch failure’. Do you know why so?
  3. If further to this example, I have three endogenous states and all as choice variables(with 20 points, 40 points, 20 points) and 11 points for exogenous state, my matlab shows ‘requires a 160001600011(21.3G) exceeding the maximum’. In this case, How should I possibly resolve it?

Looking forward to your reply soon

Many thanks

Dear Julia,

  1. from memory, simply that Algonquin did not have gpu, so used parallel cpu instead (gpu would certainly be faster; unless it is a very small/cheap gpu and a very large/expensive cpu).

  2. should work. Do you have CUDA and an NVIDIA gpu, and is Matlab set up to use them? [If you run ones(2,2,'gpuArray') in Matlab, does that work?]

  3. You could try setting vfoptions.lowmemory=1, this uses less memory but is slower.

If your RBC model with three states has no ‘complications’ (non-convex choices, non-concave return functions, etc.) then you will find Dynare to be the better option to solve it. (Make sure you use at least 2nd-order solution, the 1st-order Dynare solutions all contain too much numerical approximation error to be truly useful).

Hope that helps. Ask away with any follow up questions.

Dear Robert,

Thanks for your prompt reply!

For point 2, I have
1 1
1 1 after running ones(2,2,‘gpuArray’) on my laptop. Further I switched to a desktop and it works. Though I still dont know why…

For point 3, if I use parallel CPU (not GPU) and vfoptions.lowmemory=1, I have the following:

WARNING: ValueFnIter_Case1_LowMem_NoD_Par1_raw is out of date
Undefined function or variable ‘n_d’.
Error in ValueFnIter_Case1_LowMem_NoD_Par1_raw (line 18)
d_gridvals=CreateGridvals(n_d,d_grid,1);
Error in ValueFnIter_Case1 (line 267)
[VKron,Policy]=ValueFnIter_Case1_LowMem_NoD_Par1_raw(V0Kron, n_a, n_z, a_grid, z_grid, pi_z,
DiscountFactorParamsVec, ReturnFn, ReturnFnParamsVec, vfoptions.howards, vfoptions.maxhowards,
vfoptions.tolerance, vfoptions.verbose);

For your last comment, as the model requires several facts such as occasionally binding, (though there are some toolkits that solve it, such as occbin with dynare), I would like to implement it with global solutions, thus your toolkit seems necessary.

  1. Following that, I notice on your original paper you mention lowmemory option being 2, I do find it in your toolkit. However, is the only difference between it and option being 1 is: 2 is slower, but allows larger size?
  2. When I got ‘Policy’, I now have some index being 1.000, some being 1. This causes problems when later doing ‘TimeSeriesIndexes=SimTimeSeriesIndexes_Case1(Policy,n_d,n_a,n_z,pi_z,simoptions);’ with two endogenous states, it is fine. however, with three states, it got stuck and saying ‘the index has to be positive integer or logic value’. I then use 'policy=round(Policy);'and it works. I wonder if this way is reasonable?

Additionally, I check the toolkit with my originally written code, it seems that, for a low size grid, the policy functions are the same, but the value functions are different, i wonder if you have any idea why so?

Sorry for so many questions! thanks very much!

  1. Will look into it and get back to you.

  2. vfoptions.lowmemory=0: fastest, but uses most memory
    vfoptions.lowmemory=0: medium speed, medium memory
    vfoptions.lowmemory=2: slowest, but uses least memory
    [essentially increasing lowmemory involves using smaller matrices (so less memory), but having to loop more (so slower)]

  3. sometimes Policy has numerical rounding errors. You can set vfoptions.policy_forceintegertype=1 which will then internally do the same thing as you have done with Policy=round(Policy). Before doing this you can double check that this (numerical rounding error) is the problem by calculating max(abs(Policy-round(Policy))) and making sure this number is tiny (say around 10^-10). You will want to use max() multiple times so it is just one number, have just put max() once to keep it easy to read.
    [I have considered doing this by default, but am worried there is some possible situation I have not thought of where this would lead to incorrect outcomes.]

Obviously I am a fan of the methods being used by VFI Toolkit (as long as enough grid points are used), but I also like to make sure users are aware that they can always beat them in terms of speed-accuracy trade-off if they do write their own more sophisticated codes. If VFI Toolkit works for you and your application then I am happy to hear it and all for using it!

I check the toolkit with my originally written code, it seems that, for a low size grid, the policy functions are the same, but the value functions are different, i wonder if you have any idea why so?

My guess, the policy functions have fully converged. Your code and VFI toolkit likely use different convergence criteria for value fn, and these result in slightly different numbers (I assume they give similar value functions and that any differences are small).

  1. Fixed. Have updated the codes for using vfoptions.lowmemory=1 together with cpu (mostly just improved implementation of Howards). The latest versions are now on github, so you will just need to update to those (either redownload whole toolkit, or just use ‘git pull’). I did some basic tests and they appear to work just fine.

Using vfoptions.lowmemory=1 slows things down a lot, so following are two suggestions. Turn on vfoptions.verbose=1 so you get occasional updates on progress. Consider ‘multi-grid’ approach: solve on small grid, interpolate to larger grid, solve on larger grid; slightly more lines of code, but potentially much faster.

[You could also set a lower tolerance, e.g., vfoptions.tolerance=10^(-5) for small grid. You can use Matlab interpn() command for the interpolation.]

Dear Robert,

Thanks so much for your detailed reply!! Your previous post solves my puzzles and I will definitely download the new version on github and check with it. I sincerely appreciate your timely and kind help!

For your last comment on interpolation, I have some basic idea of doing it for neoclassical growth model(for ONLY ONE endogenous states, say capital) and there are plenty of examples of this kind. However, I am kinda puzzled on cases of more than one endogenous grids (with potentially occasionally binding constraints). I wonder whether you happen to know if there are any websites resources or examples codes on this?

Additionally, I was actually thinking of vectorize three endo states into 2 states, and solve with your toolkit. Do you think this is a plausible way? Or I need to exactly use the same number of endogenous states there?

I am sincerely grateful and hope it won’t bring too much trouble.

Thanks!

I was actually thinking of vectorize three endo states into 2 states, and solve with your toolkit.

This is anyway what VFI toolkit does internally (vectorizes everything down to one endogenous state and one exogenous state, solves by brute force, unvectorizes the solution). So would be pointless when using VFI toolkit.

My above comment on interpolation is different to what you refer to (I am just talking about interpolating the solution, not interpolation as part of the solution method). As for endogenous grid method (EGM) this is a different thing again (it is part of the solution method, and is not exactly the same as just interpolation as part of the solution method; it is a clever way to avoid the maximization step in certain class of models). For EGM in more complex situations (one continuous endogenous state plus a discrete endogenous state, two or more continuous states) it can be done: see articles by, e.g., A Generalized Endogenous Grid Method for Non-Smooth and Non-Concave Problems. For the math of what goes on in some more complex cases see the The endogenous grid method for discrete‐continuous dynamic choice models with (or without) taste shocks. There are various articles on EGM with occasionally binding constraints, and with more than one continuous dimension, but as I have not read any of them I wouldn’t want to recommend a specific one,

I checked the new lowme=1 and it works now. Very helpful!

I will read the papers you mentioned in detail. Thanks again. The toolkit is very helpful!