The textbook by Fehr and Kindermann on computational economics (see here) is a great resource for those interested in quant macro with Fortran.
In order to compare strengths and weaknesses of the VFI toolkit with the Fortran implementation of FK, I replicated the baseline life-cycle model of FK Chapter 10.1 with the toolkit. Interested users can find my codes here:
The model in a nutshell:
V(a,z,\theta,j) = \max_{a'} u(c)+\beta s_j E[V(a',z',\theta,j+1)|z]
subject to
c+a' = (1+r)a+w \kappa_j \exp(\theta+z)+pen_j, a'\geq 0,
where \kappa_j=0 for all j\geq J_R and pen_j=0 for all j<J_R. Here \theta is a permanent income type (college vs no college), \kappa_j is a deterministic age-profile and pen denotes pension benefits.
The results match almost exactly those of FK ch.10.1, which is a useful cross-check for the toolkit codes (and for their Fortran codes as well).
Performance
As, expected, the toolkit is slower than Fortran. The run times of the toolkit replication on my laptop (in seconds) are: (which admittedly does not have a very good GPU)
time_vfi = 2.546369
time_distrib = 0.060441
time_stats = 2.079527 (with simoptions.whichstats=[1,1,1,0,0,0,0];)
With divide and conquer on, the time for VFI improves a bit down to 1.9 seconds (but I have to manually set vfoptions.level1n = 7
, with default value is slower.
In comparison the run time of the entire Fortran code (on the same laptop) is 0.3 seconds. A few things to observe:
- The Fortran code uses 200 grid points for assets but I use 1000 in order to get similar accuracy
- It took me half an hour to replicate the life-cycle model of FK, while writing the code in Fortran would take me one afternoon probably, with plenty of opportunities to make hard-to-catch mistakes.
Test case for finite-horizon model
If I have time I will test this code again with interpolation over a' to see how the trade-off between time and accuracy improves. Indeed, my idea was to prepare this nice life-cycle model of Fehr and Kindermann as a âtest caseâ for toolkit improvements. We know exactly how the solution must look like, so hopefully this helps!