Addtonal Codes usng Fnte Dfference Method Benamn Moll 1 HJB Equaton for Consumpton-Savng Problem Wthout Uncertanty Before consderng the case wth stochastc ncome n http://www.prnceton.edu/~moll/ HACTproect/HACT_Numercal_Appendx.pdf, t s useful to frst really understand the case wthout uncertanty: ρv(a) = max u(c) + v (a)[w + ra c] (1) c wth a state constrant a a, and we assume r < ρ and w > 0 and a > w/r. For future reference denote by s(a) = w + ra c(a) where c(a) s the optmal choce n (1). The state constrant mples s(a) = w + ra c(a) 0. Snce u (c(a)) = v (a) and snce u s concave therefore v (a) u (w + ra) (2) As above, we use a fnte dfference method and approxmate the functon v at J dscrete ponts n the space dmenson, a, = 1,..., J. We use equspaced grds, denote by a the dstance between grd ponts, and use the short-hand notaton v v(a ). Agan as before, one can mplement ether a so-called explct method or an mplct method. As usual, the mplct method s the preferred approach because t s both more effcent and more stable/relable. However, the explct method s easer to explan so we turn to t frst. 1.1 Explct Method Smplest Possble Algorthm. See matlab program HJB_no_uncertanty_smple.m. Gven that there s no uncertanty and r < ρ, we know the followng propertes of the soluton to (1): frst, savngs wll be negatve everywhere, s(a) 0 all a; and the borrowng constrant wll always bnd and hence (2) holds wth equalty. Gven these propertes, an extremely smple algorthm can be used. In partcular, use a backward dfference approxmaton to v everywhere v = v v 1, 2, v 1 = u (w + ra 1 ) (3) a 1
and update the value functon usng v n + ρv n = u(c n ) + (v n ) [w + ra c n ] (4) where c n = (u ) 1 [(v n ) ]. As above s the step sze of the explct scheme whch cannot be too large (CFL condton). A small enough also guarantees that the Barles-Sougands condtons are satsfed. See http://www.prnceton.edu/~moll/hact.pdf and http://www. prnceton.edu/~moll/hactproect/hact_numercal_appendx.pdf for more dscusson. Summary of Algorthm. Summarzng, the algorthm for fndng a soluton to the HJB equaton (1) s as follows. Guess v 0, = 1,..., J and for n = 0, 1, 2,... follow 1. Compute (v n ) from (3). 2. Compute c n from c n = (u ) 1 [(v n ) ] 3. Fnd from (4). 4. If s close enough to v n : stop. Otherwse, go to step 1. Upwnd Scheme. Note that (3) s an upwnd scheme. As explaned above, an upwnd scheme uses a forward dfference approxmaton whenever the drft of the state varable (here, savngs s n = w + ra c n ) s postve and a backwards dfference whenever t s negatve. In the specal case wthout uncertanty, we know that savngs are negatve everywhere and hence that one should always use the backwards dfference approxmaton. Instead of mposng that the backwards dfference s always used, we could have let the upwnd scheme choose the correct approxmaton as follows: frst compute savngs accordng to both the backwards and forward dfference approxmatons v,f and v,b s,f = w + ra (u ) 1 (v,f ), s,b = w + ra (u ) 1 (v,b) where we suppress n superscrpts for notatonal smplcty. Then use the followng approxmaton for v : v = v,f 1 {s,f >0} + v,b1 {s,b <0} + v 1 {s,f <0<s,B } (5) where 1 { } denotes the ndcator functon, and where v = u (w + ra ). Ths scheme would fnd that 1 {s,b <0} for all 2 and hence would pck the approxmaton n (3) by tself. Ths slghtly more general soluton algorthm s programmed up n HJB_no_uncertanty_explct.m. 1.2 Implct Method See HJB_no_uncertanty_mplct.m and also see Secton 1.2 of http://www.prnceton. edu/~moll/hactproect/hact_numercal_appendx.pdf for a detaled explanaton n the 2
verson wth uncertanty. Relatve to the explct scheme n (4), an mplct dffers n how v n s updated. In partcular, s now mplctly defned by the equaton v n + ρ = u(c n ) + ( ) F (w + ra c n,f ) + + ( ) B(w + ra c n,b) (6) where c n = (u ) 1 [(v n ) ] and (v n ) s gven by (5). For any number x, the notaton x + means the postve part of x,.e. x + = max{x, 0} and analogously x = mn{x, 0},.e. [w+ra c n,f ]+ = max{w + ra c n,f, 0} and [w + ra c n,b ] = mn{w + ra c n,b, 0}. Equaton (6) consttutes a system of J lnear equatons, and t can be wrtten n matrx notaton usng the followng steps. Substtutng the fnte dfference approxmatons to the dervatves, and defnng s n,f = w + ra c n,f and smlarly for sn,b, (6) s v n + ρ = u(c n ) + vn+1 +1 vn+1 a (s n,f ) + + vn+1 1 a Collectng terms wth the same subscrpts on the rght-hand sde (s n,b) v n + ρ = u(c n ) + 1 x + y + +1 z where x = (sn,b ) a, y = (sn,f )+ + (sn,b ) a a, z = (sn,f )+ a (7) Note that mportantly x 1 = z J = 0 so v0 n+1 and J+1 are never used. Equaton (7) s a lnear system whch can be wrtten n matrx notaton as: 1.3 Results 1 (vn+1 v n ) + ρ = u n + A n, A n = Fgure 1 plots the functon s(a). y 1 z 1 0 0. x 2 y 2 z 2.. 0 0 x 3 y 3 z 3 0............... 0..... xi y I 3
0 x 10 3 1 2 3 s(a) 4 5 6 7 8 9 0 0.2 0.4 0.6 0.8 1 a Fgure 1: Savngs Behavor n Model Wthout Uncertanty 2 Solvng the Neoclasscal Growth Model See matlab codes HJB_NGM.m and HJB_NGM_mplct. Fnally and for completeness, let us solve the neoclasscal growth model whch s the prototypcal dynamc programmng problem n macroeconomcs. The HJB equaton s ρv (k) = max c U(c) + V (k)[f (k) δk c] (8) As before s(k) = F (k) δk c(k) and c(k) = (U ) 1 (V (k)) denote optmal savngs and consumpton. We approxmate V at I dscrete grds ponts and use the short-hand notaton V = V (k ). We frst mplement an explct and then an mplct method. As usual, the mplct method s preferable due to better effcency and stablty propertes. 2.1 Explct Method See HJB_NGM.m. The explct method starts wth a guess V 0 = (V1 0,..., VI 0 ) and for n = 0, 1, 2,... updates V accordng to V n+1 V n + ρv n = U(c n ) + (V n ) [F (k ) δk c n ] (9) c n = (U ) 1 [(V n ) ] (10) Upwnd Scheme. The dervatve V (k ) s agan approxmated usng an upwnd scheme. That s compute savngs accordng to both the backwards and forward dfference approxma- 4
tons V,F and V,B s,f = F (k ) δk (U ) 1 (V,F ), s,b = F (k ) δk (U ) 1 (V,B) and then use the followng approxmaton for V : V = V,F 1 {s,f >0} + V,B1 {s,b <0} + V 1 {s,f <0<s,B } where V concave. = u (F (k ) δk ). Note agan that the case s,f > s,b wll not occur because V s Remark. We know that the neoclasscal growth model (8) has a steady state k satsfyng F (k ) = ρ + δ and that at ths steady state V (k ) = U (F (k ) δk ). Note that the upwnd scheme n effect uses the condton on the value functon at the steady state k as a boundary condton. It then uses a backward dfference approxmaton below the steady state, and a forward dfference approxmaton above the steady state. 2.2 Implct Method See HJB_NGM_mplct.m. The algorthm s exactly the same as n Secton 1.2. Also see Secton 1.2 of http://www.prnceton.edu/~moll/hactproect/hact_numercal_appendx.pdf. 2.3 Results. Fgure 2 plots the savngs polcy functon n the neoclasscal growth model. 0.3 0.2 0.1 s(k) 0 0.1 0.2 0.3 0.4 1 2 3 4 5 6 7 8 9 k Fgure 2: Savngs Polcy Functon n Neoclasscal Growth Model 5