forked from llorracc/SolvingMicroDSOPs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSolvingMicroDSOPs.tex
3221 lines (2831 loc) · 205 KB
/
SolvingMicroDSOPs.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% -*- mode: LaTeX; TeX-PDF-mode: t; -*- # Tell emacs the file type (for syntax)
\input{./.econtexRoot} % Set paths (like, \LaTeXInputs to find resources)
\newcommand{\texname}{SolvingMicroDSOPs}% Keyname for the paper
\documentclass[titlepage, headings=optiontotocandhead]{\econtex}
\usepackage{accents,xr-hyper}
\usepackage{\LaTeXInputs/\texname}% LaTeX Shortcuts for whole paper
\usepackage{\econark}
\usepackage{\econtexSetup} % Gets, configures often-used packages
% \usepackage{econtexSetup} sets boolean Web=true if compilation type is dvi
\ifthenelse{\boolean{Web}}{
\setboolean{showPageHead}{false}}{ %
\usepackage{scrlayer-scrpage} % Package for page headers if PDF
\usepackage{caption} % allow suppression of appendix figures in NoAppendix PDF
}
\newcommand{\Mma}{\textit{Mathematica}}
\providecommand{\stge}{t}\renewcommand{\stge}{t}
\providecommand{\Stge}{T}\renewcommand{\Stge}{T}
\providecommand{\interval}{period}\renewcommand{\interval}{period}
\providecommand{\move}{move}\renewcommand{\move}{move}
\providecommand{\moves}{moves}\renewcommand{\moves}{moves}
\providecommand{\interval}{period}\renewcommand{\interval}{period}
% Switches
\provideboolean{ctwVersion}\setboolean{ctwVersion}{false}\newcommand{\ctw}{\ifthenelse{\boolean{ctwVersion}}}
\provideboolean{trpVersion}\setboolean{trpVersion}{false}\newcommand{\trp}{\ifthenelse{\boolean{trpVersion}}}
\setboolean{trpVersion}{true}
\setboolean{trpVersion}{false}
\provideboolean{uCDC}
\setboolean{uCDC}{true}
% Include or exclude Method of Moderation material
\provideboolean{MoMVersion}
\setboolean{MoMVersion}{true}
% \setboolean{MoMVersion}{false}
\newcommand{\MoM}{\ifthenelse{\boolean{MoMVersion}}}
% Include or exclude Method of Moderation material
\provideboolean{PermShkVersion}
% \setboolean{PermShkVersion}{true}
\setboolean{PermShkVersion}{false}
\newcommand{\PermShkOn}{\ifthenelse{\boolean{PermShkVersion}}}
% MPCMatch
\provideboolean{MPCMatchVersion}
\setboolean{MPCMatchVersion}{true}
\newcommand{\MPCMatch}{\ifthenelse{\boolean{MPCMatchVersion}}}
\usepackage{\econtexSetup}\usepackage{\econtexShortcuts}
\provideboolean{MyNotes}\setboolean{MyNotes}{true}\setboolean{MyNotes}{false}
\provideboolean{Habits}
\setboolean{Habits}{false}
\newcommand{\Habits}{\ifthenelse{\boolean{Habits}}}
\provideboolean{habitsSolve}
\setboolean{habitsSolve}{false}
\newcommand{\ifhabits}{\ifthenelse{\boolean{habitsSolve}}}
\bibliographystyle{\econtexBibStyle}
\begin{document}
% Redefine \onlyinsubfile command defined in \texname.sty file:
% This lets any submaterial called from here know that it is not standalone
% If not called from here and IS standalone, can make bib (or other content)
\renewcommand{\onlyinsubfile}[1]{}\renewcommand{\notinsubfile}[1]{#1}
\hfill{\tiny \jobname, \today}
\begin{verbatimwrite}{./\texname.title}
Solution Methods for Microeconomic Dynamic Stochastic Optimization Problems
\end{verbatimwrite}
\title{Solution Methods for Microeconomic Dynamic Stochastic Optimization Problems}
\author{Christopher D. Carroll\authNum}
\keywords{Dynamic Stochastic Optimization, Method of Simulated Moments, Structural Estimation}
\jelclass{E21, F41}
\date{2023-03-16}
\maketitle
\noindent Note: The code associated with this document should work (though the Matlab code may be out of date), but has been superceded by the set of tools available in the \href{https://github.com/econ-ark/HARK}{Econ-ARK} toolkit, more specifically the \href{https://github.com/econ-ark/HARK}{HARK Framework}. The SMM estimation code at the end has specifically been superceded by the \href{https://econ-ark.org/materials/solvingmicrodsops?launch}{SolvingMicroDSOPs} \href{https://github.com/econ-ark/REMARK}{REMARK}
\hypertarget{Abstract}{}
\begin{abstract}
These notes describe tools for solving microeconomic dynamic stochastic optimization problems, and show how to use those tools for efficiently estimating a standard life cycle consumption/saving model using microeconomic data. No attempt is made at a systematic overview of the many possible technical choices; instead, I present a specific set of methods that have proven useful in my own work (and explain why other popular methods, such as value function iteration, are a bad idea). Paired with these notes is \textit{Mathematica}, Matlab, and Python software that solves the problems described in the text.
\end{abstract}
\begin{footnotesize}
\begin{center}
\begin{tabbing}
\texttt{~~~~PDF:~} \= \= \url{https://github.com/llorracc/SolvingMicroDSOPs/blob/master/SolvingMicroDSOPs.pdf} \\ % This line establishes the locations of the tabs, but is not printed because of the \kill directive
\texttt{~Slides:~} \> \> \url{https://github.com/llorracc/SolvingMicroDSOPs/blob/master/SolvingMicroDSOPs-Slides.pdf} \\
\texttt{~~~~Web:~} \> \> \url{https://llorracc.github.io/SolvingMicroDSOPs} \\
\texttt{~~~Code:~} \> \> \url{https://github.com/llorracc/SolvingMicroDSOPs/tree/master/Code} \\
\texttt{Archive:~} \> \> \url{https://github.com/llorracc/SolvingMicroDSOPs}\\
\texttt{~~~~~~~~~} \> \> \textit{(Contains LaTeX code for this document and software producing figures and results)}
\end{tabbing}
\end{center}
\end{footnotesize}
\begin{authorsinfo}
\name{Carroll: Department of Economics, Johns Hopkins University, Baltimore, MD, \url{http://www.econ2.jhu.edu/people/ccarroll/},
\href{mailto:[email protected]}{\texttt{[email protected]}}, Phone: (410) 516-7602}
\end{authorsinfo}
\thanksFooter{The notes were originally written for my Advanced Topics in Macroeconomic Theory class at Johns Hopkins University; instructors elsewhere are welcome to use them for teaching purposes. Relative to earlier drafts, this version incorporates several improvements related to new results in the paper \href{http://econ-ark.github.io/BufferStockTheory}{``Theoretical Foundations of Buffer Stock Saving''} (especially tools for approximating the consumption and value functions). Like the last major draft, it also builds on material in ``The Method of Endogenous Gridpoints for Solving Dynamic Stochastic Optimization Problems'' published in \textit{Economics Letters}, available at \url{http://www.econ2.jhu.edu/people/ccarroll/EndogenousArchive.zip}, and by including sample code for a method of simulated moments estimation of the life cycle model \textit{a la} \cite{gpLifecycle} and Cagetti~\citeyearpar{cagettiWprofiles}. Background derivations, notation, and related subjects are treated in my class notes for first year macro, available at \url{http://www.econ2.jhu.edu/people/ccarroll/public/lecturenotes/consumption}. I am grateful to several generations of graduate students in helping me to refine these notes, to Marc Chan for help in updating the text and software to be consistent with \cite{carrollEGM}, to Kiichi Tokuoka for drafting the section on structural estimation, to Damiano Sandri for exceptionally insightful help in revising and updating the method of simulated moments estimation section, and to Weifeng Wu and Metin Uyanik for revising to be consistent with the `method of moderation' and other improvements. All errors are my own. This document can be cited as \cite{SolvingMicroDSOPs} in the references.}
\titlepagefinish
\setcounter{page}{1}
\ifpdf % For some reason, the table of contents does not work if not in pdf mode
\tableofcontents \addtocontents{toc}{\vspace{1em}}\newpage
\fi
\hypertarget{Introduction}{}
\section{Introduction}
Calculating the mathematically optimal amount to save is remarkably difficult. Under well-founded assumptions about the nature of risk (and attitudes toward risk), the problem cannot be solved analytically; computational solutions are the only option. To avoid having to solve this hard problem, past generations of economists showed impressive ingenuity in reformulating the question. Budding graduate students are still taught a host of tricks whose purpose is partly to avoid the resort to numerical solutions: Quadratic or Constant Absolute Risk Aversion utility, perfect markets, perfect insurance, perfect foresight, the ``timeless perspective,'' the restriction of uncertainty to very special kinds,\footnote{E.g., lognormally distributed rate-of-return risk -- but no labor income risk -- under CRRA utility (the \cite{merton:restat}-\cite{samuelson:portfolio} model).} and more.
The motivation for these reformulations is to exchange an intractable general problem
for a tractable specific alternative. Unfortunately, the burgeoning
literature on numerical solutions has shown that the features that
yield tractability also profoundly change the essence of the solution. These tricks
are excuses to solve a problem that has defined away the central
difficulty: Understanding the proper role of uncertainty (and other
complexities like constraints) in optimal intertemporal choice.
% The temptation to use such tricks (and the tolerance for them in leading academic journals) is palpably lessening, thanks to advances in mathematical analysis, increasing computing power, and the growing capabilities of numerical computation software. Together, such tools permit today's laptop computers to solve problems that required supercomputers a decade ago (and, before that, could not be solved at all).
These points are not unique to the consumption/saving problem; the
same propositions apply to almost any question that involves both
intertemporal choice and uncertainty, including many aspects of the
behavior of firms and governments.
% Given the ubiquity of such problems, one might expect that the use of numerical methods for solving dynamic optimization problems would by now be nearly as common as the use of econometric methods in empirical work. Of course, we remain far from that equilibrium. The most plausible explanation for the gap is that barriers to the use of numerical methods have remained forbiddingly high.
These lecture notes provide a gentle introduction to a particular set
of solution tools and show how they can be used to solve some
canonical problems in consumption choice and portfolio allocation.
Specifically, the notes describe and solve optimization problems for a
consumer facing uninsurable idiosyncratic risk to nonfinancial income
(e.g., labor or transfer income),\footnote{Expenditure shocks (such as
for medical needs, or to repair a broken automobile) are usually
treated in a manner similar to labor income shocks. See
\cite{merton:restat} and \cite{samuelson:portfolio} for a solution
to the problem of a consumer whose only risk is rate-of-return risk
on a financial asset; the combined case (both financial and
nonfinancial risk) is solved below, and much more closely resembles
the case with only nonfinancial risk than it does the case with only
financial risk.} with detailed intuitive discussion of the various
mathematical and computational techniques that, together, speed the
solution by many orders of magnitude compared to
``brute force'' methods. The problem is solved with and without
liquidity constraints, and the infinite horizon solution is
obtained as the limit of the finite horizon solution. After the basic
consumption/saving problem with a deterministic interest rate is
described and solved, an extension with portfolio choice between a
riskless and a risky asset is also solved\ifhabits{, and
then a version with habit formation.}{.} Finally, a simple example
is presented of how to use these methods (via the statistical `method
of simulated moments' or MSM; sometimes called `simulated method of
moments' or SMM) to estimate structural parameters like the
coefficient of relative risk aversion (\textit{a la} Gourinchas and
Parker~\citeyearpar{gpLifecycle} and
Cagetti~\citeyearpar{cagettiWprofiles}). % The tricks and techniques used in solving these problems have broad applicability to many dynamic stochastic optimization problems.
\renewcommand{\DiscAlt}{\beta} % Erase the distinction between the alternative and the standard discount factor
\hypertarget{the-problem}{}
\section{The Problem}\label{sec:the-problem}
\begin{verbatimwrite}{./subfile-the-problem.texinput}
The usual analysis of dynamic stochastic programming problems packs a great many events (intertemporal choice, stochastic shocks, intertemporal returns, income growth, and more) into a small number of steps and variables. For the detailed analysis here, we will be careful to disarticulate everything that happens in the problem explicitly into separate steps so that each element can be scrutinized and understood in isolation.
We are interested in the behavior a consumer who begins {\interval} $t$ with a certain amount of `capital' $\kLvl_{t}$, which is immediately rewarded by a return factor $\Rfree_{t}$ with the proceeds deposited in a \textbf{b}ank account \textbf{b}alance:
\begin{equation}\begin{gathered}\begin{aligned}
\bLvl_{t} & = \kLvl_{t}\Rfree_{t}. \label{eq:bLvl}
\end{aligned}\end{gathered}\end{equation}
Simultaneously with the realization of the capital return, the consumer also receives noncapital income $\yLvl_{t}$, which is determined by multiplying the consumer's `permanent income' $\pLvl_{t}$ by a transitory shock $\TranShkEmp_{t}$:
\begin{equation}\begin{gathered}\begin{aligned}
\yLvl_{t} & = \pLvl_{t}\TranShkEmp_{t} \label{eq:yLvl}
\end{aligned}\end{gathered}\end{equation}
whose whose expectation is 1 (that is, before realization of the transitory shock, the consumer's expectation is that actual income will on average be equal to permanent income $\pLvl_{t}$).
The combination of bank balances $\bLvl$ and income $\yLvl$ define's the consumer's `market resources' (sometimes called `cash-on-hand', following~\cite{deatonUnderstandingC}):
\begin{equation}\begin{gathered}\begin{aligned}
\mLvl_{t} & = \bLvl_{t}+\yLvl_{t} \label{eq:mLvl},
\end{aligned}\end{gathered}\end{equation}
which are available to be spent on consumption $\cLvl_{t}$.
The consumer's goal is to maximize discounted utility from consumption over the rest of a lifetime whose last {\interval} is date $T$:
\end{verbatimwrite}
\input{./subfile-the-problem.texinput}
\begin{verbatimwrite}{./Equations/MaxProb.tex}
\begin{equation}\label{eq:MaxProb}
\max ~ \Ex_{t}\left[ \sum_{n=0}^{T-t} {\DiscAlt}^{n} \uFunc({\cLvl}_{t+n})\right].
\end{equation}
\end{verbatimwrite}
\input{./Equations/MaxProb.tex}\unskip
For now, we will assume that income evolves according to: \ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny Subscript on permanent income allows pattern of income growth over the lifetime.}}{}
\begin{verbatimwrite}{./Equations/ExogVars.tex}
\begin{equation}\begin{gathered}\begin{aligned}
% \Rfree_{t} & = \Rfree~\forall~t & \text{- constant interest factor = $1+\rfree$}
\pLvl_{t+1} & = \PermGroFac_{t+1}\pLvl_{t} & \text{- permanent labor income dynamics} \label{eq:permincgrow}
\\ \log ~ \TranShkEmp_{t+n} & \sim ~\mathcal{N}(-\sigma_{\TranShkEmp}^{2}/2,\sigma_{\TranShkEmp}^{2}) & \text{- lognormal transitory shocks}~\forall~n>0
\end{aligned}\end{gathered}\end{equation}
\end{verbatimwrite}
\input{./Equations/ExogVars.tex}\unskip
% \ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny Assumption on $\TranShkEmp$ implies $\Ex_{t}[\TranShkEmp_{t+1}] = 1$.}}{} Using the fact about lognormally distributed variables \handoutM{ELogNorm}\footnote{This fact is referred to as \texttt{ELogNorm} in the handout \handoutM{MathFactsList}, in the references as \cite{MathFacts}; further citation to facts in that handout will be referenced simply by the name used in the handout for the fact in question, e.g.\ \handoutM{LogELogNorm} is the name of the fact that implies that $\log \Ex[{\TranShkEmp}]=0$.} that if $\log \EPrem \sim \mathcal{N}(\eprem,\sigma_{\eprem}^{2})$ then $\log \Ex[{\EPrem}] = \eprem +\sigma_{\eprem}^{2}/2$, our assumption about the distribution of the transitory shock guarantees that $\log \Ex[{\TranShkEmp}] = 0$ which means that $\Ex[{\TranShkEmp}]$=1 (the mean value of the transitory shock is 1).
Equation \eqref{eq:permincgrow} indicates that we are allowing for a predictable average profile of income growth over the lifetime $\{\PermGroFac\}_{0}^{T}$ (to capture typical career wage paths, pension arrangements, etc).\footnote{This equation assumes that there are no shocks to permanent income. A large literature finds that, in reality, permanent (or at least extremely highly persistent) shocks exist and are quite large; such shocks therefore need to be incorporated into any `serious' model (that is, one that hopes to match and explain empirical data), but the treatment of permanent shocks clutters the exposition without adding much to the intuition, so permanent shocks are omitted from the analysis until the last section of the notes, which shows how to match the model with empirical micro data. For a full treatment of the theory including permanent shocks, see \cite{BufferStockTheory}.} %\ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny However, note the $t$ subscript indicating that a life cycle profile is possible. It's fairly easy to modify this to allow permanent shocks as well.}}{}
Finally, the utility function is of the
Constant Relative Risk Aversion (CRRA), form, $\uFunc(\bullet) = \bullet^{1-\CRRA}/(1-\CRRA)$.
It is well known that this problem can be rewritten in recursive (Bellman) form
\begin{verbatimwrite}{./Equations/vrecurse.tex}
\begin{equation}\begin{gathered}\begin{aligned}
{\vLvl}
_{t}(\mLvl_{t},\pLvl_{t}) & = \max_{\cLvl_{t}}~ \uFunc(\cLvl_{t}) + {\DiscAlt}\Ex_{t}[ {\vLvl}
_{t+1}({\mLvl}_{t+1},\pLvl_{t+1})]\label{eq:vrecurse}
\end{aligned}\end{gathered}\end{equation}
\end{verbatimwrite}
\input{./Equations/vrecurse.tex}\unskip
subject to the Dynamic Budget Constraint (DBC) implicitly defined by equations~\eqref{eq:bLvl}-\eqref{eq:mLvl}
and the transition equation that defines next period's initial capital as this period's end-of-period assets:
\begin{equation}\begin{gathered}\begin{aligned}
\kLvl_{t+1} & = \aLvl_{t}. \label{eq:transition.state}
\end{aligned}\end{gathered}\end{equation}
\hypertarget{Normalization}{}
\section{Normalization}\label{sec:normalization}
\ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny Goal: Convert 2-state to 1-state problem; makes computational solutions much easier and easier to debug.}}{} The single most powerful method for speeding the solution of such models is to redefine the problem in a way that reduces the number of state variables (if possible). Here, the obvious idea is to see whether the problem can be rewritten in terms of the ratio of various variables to permanent noncapital (`labor') income $\pLvl_{t}$ (henceforth for brevity referred to simply as `permanent income.')
\ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny Call this `curly V'.}}{}
In the last {\interval} of life, there is no
future, ${\vLvl}
_{T+1} = 0$, so
the optimal plan is to consume everything:
\begin{equation}\begin{gathered}\begin{aligned}
{\vLvl}
_{T}(\mLvl_{T},\pLvl_{T}) & = \frac{\mLvl_{T}^{1-\CRRA}}{1-\CRRA}. \label{eq:levelTm1}
\end{aligned}\end{gathered}\end{equation}
Now define nonbold variables as the bold variable divided by
the level of permanent income in the same period, so that, for
example, ${m}_{T}=\mLvl_{T}/\pLvl_{T}$; and define
$\vFunc_{T}({m}_{T}) = \uFunc({m}_{T})$.\footnote{Nonbold value is bold value divided by $\pLvl^{1-\CRRA}$ rather than $\pLvl$.} For our CRRA utility function, $\uFunc(xy)=x^{1-\CRRA}\uFunc(y)$, so equation (\ref{eq:levelTm1}) can be
rewritten as
\begin{equation*}\begin{gathered}\begin{aligned}
{\vLvl}
_{T}(\mLvl_{T},\pLvl_{T}) & = \pLvl_{T}^{1-\CRRA}\frac{{m}_{T}^{1-\CRRA}}{1-\CRRA}
\\ & = (\pLvl_{T-1}\PermGroFac_{T})^{1-\CRRA}\frac{{m}_{T}^{1-\CRRA}}{1-\CRRA}
\\ &= \pLvl_{T-1}^{1-\CRRA}\PermGroFac_{T}^{1-\CRRA}\vFunc_{T}({m}_{T}).
\end{aligned}\end{gathered}\end{equation*}
Now define a new optimization problem:\ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny Note that in mathematical terms, the $\PermGroFac_{t+1}^{1-\CRRA} {\DiscAlt}$ term is basically just a time-varying discount factor.}}{}
\begin{verbatimwrite}{./Equations/vNormed.tex}
\begin{equation}\begin{gathered}\begin{aligned}
\null{\vFunc}_{t}({m}_{t}) & = \max_{{c}_{t}} ~~ \uFunc({c}_{t})+
{\DiscFac}\Ex_{t}[ \PermGroFac_{t+1}^{1-\CRRA}\null{\vFunc}_{t+1}({m}_{t+1})] \label{vtNorm}
\\ & \text{s.t.} & \\
{a}_{t} & = {m}_{t}-{c}_{t}
\\ {m}_{t+1} & = \underbrace{\left(\Rfree/\PermGroFac_{t+1}\right)}_{\equiv \RNrm_{t+1}}{a}_{t}+\TranShkEmp_{t+1} .
\end{aligned}\end{gathered}\end{equation}
\end{verbatimwrite}
\input{./Equations/vNormed.tex}\unskip
where the last equation is the normalized version of the transition equation for $\mLvl_{t+1}$.\footnote{Derivation:
\begin{equation*}\begin{gathered}\begin{aligned}
\mLvl_{t+1}/\pLvl_{t+1} & = (\mLvl_{t}-\cLvl_{t})\Rfree/\pLvl_{t+1} + {\yLvl}_{t+1}/\pLvl_{t+1}
\\ {m}_{t+1} & = \left(\frac{\mLvl_{t}}{\pLvl_{t}} - \frac{\cLvl_{t}}{\pLvl_{t}}\right)\Rfree\frac{\pLvl_{t}}{\pLvl_{t+1}} + \frac{{\yLvl}_{t+1}}{\pLvl_{t+1}}
\\ & = \underbrace{({m}_{t} - {c}_{t})}_{{a}_{t}}(\Rfree/\PermGroFac_{t+1}) + \TranShkEmp_{t+1}.
\end{aligned}\end{gathered}\end{equation*}
} Then it is easy to see that for $t=T-1$,
\begin{equation*}\begin{gathered}\begin{aligned}
{\vLvl}_{T-1}(\mLvl_{T-1},\pLvl_{T-1}) & = \pLvl_{T-1}^{1-\CRRA}\null{\vFunc}_{T-1}({m}_{T-1})
\end{aligned}\end{gathered}\end{equation*}
and so on back to all earlier periods. Hence, if we solve the problem \eqref{vtNorm}
which has only a single state variable $\mNrm_{t}$, we can obtain the levels of
the value function, consumption, and all other variables
from the corresponding permanent-income-normalized solution objects by multiplying each by $\pLvl_{t}$, e.g.\ ${\pmb{\cLvl}}
_{t}(\mLvl_{t},\pLvl_{t})=\pLvl_{t}\cFunc_{t}(\mLvl_{t}/\pLvl_{t})$ (or, for the value function, ${\vLvl}
_{t}({\mLvl}_{t},\pLvl_{t}) = \pLvl_{t}^{1-\CRRA}\vFunc_{t}({m}_{t}))$. We have thus reduced the
problem from two continuous state variables to one (and thereby enormously simplified its solution).
For some problems it will not be obvious that there is an appropriate `normalizing' variable, but many problems can be normalized if sufficient thought is given. For example, \cite{valencia:2006} shows how a bank's optimization problem can be normalized by the level of the bank's productivity.
\ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny Point out that right
thing to normalize by will vary from problem to problem, e.g.
Geiregat normalized banking problem by size of capital.}}{}
\hypertarget{The-Usual-Theory}{}
\section{The Usual Theory, and A Bit More Notation}
\label{sec:usualtheory}
The first order condition for \eqref{vtNorm} with respect to ${c}_{t}$ is
\begin{equation}\begin{gathered}\begin{aligned}
\uFunc^{{c}}({c}_{t}) & = \Ex_{t}[\DiscFac \RNrm_{t+1}\PermGroFac_{t+1}^{1-\CRRA}\null{\vFunc}^{{m}}_{t+1}({m}_{t+1})] \label{eq:upceqEvtp1}
\\ & = \Ex_{t}[\DiscFac\Rfree\phantom{._{t+1}}\PermGroFac_{t+1}^{\phantom{1}-\CRRA}\null{\vFunc}^{{m}}_{t+1}({m}_{t+1})]
\end{aligned}\end{gathered}\end{equation}
and because the \handoutC{Envelope} theorem tells us that
\begin{equation}\begin{gathered}\begin{aligned}
\null{\vFunc}^{{m}}_{t}({m}_{t}) & = \Ex_{t} [\DiscFac\Rfree\PermGroFac_{t+1}^{-\CRRA}\null{\vFunc}^{{m}}_{t+1}({m}_{t+1})] \label{eq:envelope}
\end{aligned}\end{gathered}\end{equation}
we can substitute the LHS of \eqref{eq:envelope} for the RHS of
(\ref{eq:upceqEvtp1}) to get
\begin{verbatimwrite}{./Equations/Envelope.tex}
\begin{equation}\begin{gathered}\begin{aligned}
\uFunc^{{c}}({c}_{t}) & = \null{\vFunc}^{{m}}_{t}({m}_{t})\label{eq:Envelope}
\end{aligned}\end{gathered}\end{equation}
\end{verbatimwrite}
\input{./Equations/Envelope.tex}\unskip
and rolling this equation forward one {\interval} yields
\begin{equation}\begin{gathered}\begin{aligned}
\uFunc^{{c}}({c}_{t+1}) & = \null{\vFunc}^{{m}}_{t+1}({a}_{t}\RNrm_{t+1}+\TranShkEmp_{t+1}) \label{eq:upctp1EqVpxtp1}
\end{aligned}\end{gathered}\end{equation}
while substituting the LHS in equation (\ref{eq:upceqEvtp1})
gives us the Euler equation for consumption
\begin{verbatimwrite}{./Equations/cEuler.tex}
\begin{equation}\begin{gathered}\begin{aligned}
\uFunc^{{c}}({c}_{t}) & = \Ex_{t}[\DiscFac\Rfree \PermGroFac_{t+1}^{-\CRRA}\uFunc^{{c}}({c}_{t+1})]. \label{eq:cEuler}
\end{aligned}\end{gathered}\end{equation}
\end{verbatimwrite}
\input{./Equations/cEuler.tex}\unskip
\begin{verbatimwrite}{./subfile-stages} Although our focus so far has been on the consumer's consumption problem once $\mNrm$ is known, for constructing the computational solution it will be useful to distinguish a sequence of three {\moves} (we use the word `\moves' to capture the fact that we are not really thinking of these as occurring at different moments in time -- only that we are putting the things that happen within a given moment into an ordered sequence). The first {\move} captures calculations that need to be performed before the shocks are realized, the middle {\move} is after shocks have been realized but before the consumption decision has been made (this corresponds to the timing of $\vFunc$ in the treatment above), and the final {\move} captures the situation \textit{after} the consumption decision has been made.
\end{verbatimwrite}
\input{./subfile-stages}
\begin{verbatimwrite}{./subfile-stage-notation}
We need to define notation for these three {\moves} within a {\interval}. We will use $\BegStge$ as a marker for the {\move} before shocks have been realized, $\MidStge$ to indicate the move in which the choice is made, and $\EndStge$ as the indicator for the situation once the choice has been made.
\end{verbatimwrite}
\input{./subfile-stage-notation}
\begin{verbatimwrite}{./Equations/vBegStge}
\begin{equation}\begin{gathered}\begin{aligned}
\vBegStge(\kNrm_{\stge}) & = \Ex_{\BegStge}[\vMidStge(\overbrace{\kNrm_{\stge} \Rnorm_{\stge} + \TranShkEmp_{\stge}}^{=\mNrm_{\stge}})] \label{eq:vBegStge}
\end{aligned}\end{gathered}\end{equation}
\end{verbatimwrite}
\input{./Equations/vBegStge}\unskip
\begin{verbatimwrite}{./Equations/vMidStge}
\begin{equation}\begin{gathered}\begin{aligned}
\vMidStge(\mNrm_{\stge}) & = \uFunc(\cFunc_{\stge}(\mNrm_{\stge})) + \vEndStge(\aNrm_{\stge}) \label{eq:vMidStge}
\end{aligned}\end{gathered}\end{equation}
\end{verbatimwrite}
\input{./Equations/vMidStge}\unskip
\begin{verbatimwrite}{./Equations/vEndStge}
\begin{equation}\begin{gathered}\begin{aligned}
\vEndStge(\aNrm_{\stge}) & = \DiscFac \vBegStge(\underbrace{\kNrm_{\stge+1}}_{=\aNrm_{\stge}}) \label{eq:vEndStge}
\end{aligned}\end{gathered}\end{equation}
\end{verbatimwrite}
\input{./Equations/vEndStge}\unskip
where the last line illustrates the notation for addressing the beginning {\move} of a future {\interval}.
%Now note that in equation \eqref{eq:upctp1EqVpxtp1} neither ${m}_{\stge}$ nor ${c}_{\stge}$ has any \textit{direct} effect on $\null{\vFunc}_{\stge+1}$ - only the difference between them (i.e.\ unconsumed market resources or `assets' ${a}_t$) matters. It is therefore possible (and will turn out to be convenient) to define a function\footnote{The peculiar letter designating our new function is pronounced `Gothic v'. Letters in this font will be used for end-of-period quantities.} \ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny Define $\Alt{\vEndStge}({a}_{\stge})$.}}{}
Putting all this together, we can write the `continuation value' function from the perspective of the end of the {\interval} $\stge$ as
\begin{verbatimwrite}{./Equations/vEndtdefn.tex}
\begin{equation}\begin{gathered}\begin{aligned}
\vEndStge({a}_{\stge}) & = \Ex_{\stge}[\DiscFac \PermGroFac_{\stge+1}^{1-\CRRA}\null{\vFunc}_{\stge+1}(\RNrm_{\stge+1} {a}_{\stge}+{\TranShkEmp}_{\stge+1})] \label{eq:vEndtdefn}
\end{aligned}\end{gathered}\end{equation}
\end{verbatimwrite}
\input{./Equations/vEndtdefn.tex}\unskip
because it returns the expected $t+1$ value associated with ending {\interval} $\stge$ with any given amount of assets. Differentiating with respect to $\aNrm$, we get
\begin{equation}\begin{gathered}\begin{aligned}
{\vPEndStge}({a}_{\stge}) & = \Ex_{\stge}[\DiscFac \Rfree \PermGroFac_{\stge+1}^{-\CRRA} \null{\vFunc}_{\stge+1}^{{m}}(\RNrm_{\stge+1}{a}_{\stge}+{\TranShkEmp}_{\stge+1})] \label{eq:vEndPrimetdefn}
\end{aligned}\end{gathered}\end{equation}
or, substituting from equation (\ref{eq:upctp1EqVpxtp1}),
\begin{equation}\begin{gathered}\begin{aligned}
\vPEndStge({a}_{\stge}) & = \Ex_{\stge}\left[\DiscFac \Rfree \PermGroFac_{\stge+1}^{-\CRRA} \uFunc^{{c}}\left(\cFunc_{\stge+1}(\RNrm_{\stge+1} {a}_{\stge}+{\TranShkEmp}_{\stge+1})\right)\right]. \label{eq:vEndPrimetOfc}
\end{aligned}\end{gathered}\end{equation}
Finally, note for future use that the first order condition
(\ref{eq:upceqEvtp1}) can now be rewritten compactly as
\begin{verbatimwrite}{./Equations/upEqbetaOp.tex}
\begin{equation}\begin{gathered}\begin{aligned}
\uFunc^{{c}}({c}_{\stge}) & = \vEndStge^{{a}}({m}_{\stge}-{c}_{\stge}).
\label{eq:upEqbetaOp}
\end{aligned}\end{gathered}\end{equation}
\end{verbatimwrite}
\input{./Equations/upEqbetaOp.tex}\unskip
\subsection{Implementation in Python}
The code which implements the tasks outlined each of the sections to come are available in the \texttt{SolvingMicroDSOPs} jupyter notebook, written in Python programming language. The benefits of Python lie in its utilization of object-oriented programming (OOP). The notebook imports various modules, including the standard \texttt{numpy} and \texttt{scipy} modules used for numerical methods in Python, as well as some user-defined modules designed to provide numerical solutions to the consumer's problem from the previous section. Before delving into the computational exercise, it is essential to touch on the practicality of these custom modules.
\subsubsection{Useful auxillary files}
In this exercise, two primary user-defined modules are frequently imported and utilized. The first is the \texttt{gothic\_class} module, which contains functions describing the end-of-period value functions found in equations \eqref{eq:vBegStge} - \eqref{eq:vEndStge} (and the subsequent first and second derivatives). The advantage of defining functions in the code which decompose the consumer's optimal behavior in a given period will become evident in section \ref{subsec:transformation}
The \texttt{resources} module is also used repeatedly throughout the notebook. This file has three primary objectives: (i) providing functions that discretize the continuous distributions from the theoretical model that describe the uncertainty a consumer faces, (ii) defining the utility function over consumption under a number of specifications, and (iii) enhancing the grid of end-of-period assets for which functions (such as those from the \texttt{gothic\_class} module) will be defined. These objectives will be discussed in greater detail and with respect to the numerical solution to the problem in subsequent sections of this document.
\hypertarget{Solving-the-Next-To-Last-Period}{}\section{Solving the Next-to-Last Period}\label{sec:NextToLast}
The problem in the second-to-last period of life is:
\begin{equation*}\begin{gathered}\begin{aligned}
\null{\vFunc}_{T-1}({m}_{T-1}) & = \max_{{c}_{T-1}} ~~ \uFunc({c}_{T-1}) +
\DiscFac \Ex_{T-1} \left[\PermGroFac_{T}^{1-\CRRA}\null{\vFunc}_{T}(({m}_{T-1} - {c}_{T-1})\RNrm_{T} + \TranShkEmp_{T})\right],
\end{aligned}\end{gathered}\end{equation*}
and using (1) the fact that $\vFunc_{T}=\uFunc(c)$; (2) the definition of $\uFunc(c)$; (3) the
definition of the expectations operator, and (4) the fact that $\PermGroFac_{T}$ is nonstochastic, this becomes
\begin{equation*}\begin{gathered}\begin{aligned}
\null{\vFunc}_{T-1}({m}_{T-1}) & = \max_{{c}_{T-1}} ~~
% \{
\frac{{c}_{T-1}^{1-\CRRA}}{1-\CRRA} + \DiscFac \PermGroFac_{T}^{1-\CRRA}\int_{0}^{\infty}
\frac{\left(({m}_{T-1}-{c}_{T-1})\RNrm_{T}+ \TranShkEmp\right)^{1-\CRRA}}{1-\CRRA}
d\FDist(\TranShkEmp)
% \}.
\end{aligned}\end{gathered}\end{equation*}
where $\FDist$ is the cumulative distribution function for ${\TranShkEmp}$.
In principle, the maximization implicitly defines a function $\cFunc_{T-1}({m}_{T-1})$ that yields optimal consumption in period $T-1$ for any given level of resources ${m}_{T-1}$. Unfortunately, there is no general analytical solution to this maximization problem, and so for any given ${m}_{T-1}$ we must use numerical computational tools to find the ${c}_{T-1}$ that maximizes the expression. This is excruciatingly slow because for every potential ${c}_{T-1}$ to be considered, the integral must be calculated numerically, and numerical integration is \textit{very} slow.
\hypertarget{Discretizing-the-Distribution}{}
\subsection{Discretizing the Distribution}
Our first time-saving trick is therefore to construct a discrete approximation to the lognormal distribution that can be used in place of numerical integration. That is, we want to approximate the expectation of a function $g(\TranShkEmp)$ by value at set of $n_{\TranShkEmp}$ points $\TranShkEmp_{i}$, each of which is given an associated probability weight $w_{i}$:
\begin{equation*}\begin{gathered}\begin{aligned}
\Ex[g(\TranShkEmp)] & = \int_{\TranShkEmpMin}^{\TranShkEmpMax}g(\TranShkEmp)d\FDist(\TranShkEmp) \\
& \approx \sum_{\TranShkEmp = 1}^{n}w_{i}g(\TranShkEmp_{i})
\end{aligned}\end{gathered}\end{equation*}
because adding $n$ weighted values to each other is enormously faster than general-purpose numerical integration.
Such a procedure is called a `quadrature' method of integration; \cite{Tanaka2013-bc} survey a number of options, but for our purposes here we choose the one which is perhaps easiest to understand: An `equiprobable' approximation (that is, one where each of the values of $\TranShkEmp_{i}$ has an equal probability, equal to $1/n_{\TranShkEmp}$).
We calculate such an $n$-point approximation as follows.
Define a set of points from $\sharp_{0}$ to $\sharp_{n_{\TranShkEmp}}$ on the $[0,1]$ interval
as the elements of the set $\sharp = \{0,1/n,2/n, \ldots,1\}$.\footnote{These points define intervals that constitute a partition of the domain of $\FDist$.} Call the inverse of the $\TranShkEmp$ distribution $\FDist^{-1}_{\phantom{\TranShkEmp}}$, and define the
points $\sharp^{-1}_{i} = \FDist^{-1}_{\phantom{\TranShkEmp}}(\sharp_{i})$. Then
the conditional mean of $\TranShkEmp$ in each of the intervals numbered 1 to $n$ is:
\begin{equation}\begin{gathered}\begin{aligned}
\TranShkEmp_{i} \equiv \Ex[\TranShkEmp | \sharp_{i-1}^{-1} \leq \TranShkEmp < \sharp_{i}^{-1}] & = \int_{\sharp^{-1}_{i-1}}^{\sharp^{-1}_{i}} \vartheta ~ d\FDist_{\phantom{\TranShkEmp}}(\vartheta) .
\end{aligned}\end{gathered}\end{equation}
The method is illustrated in Figure~\ref{fig:discreteapprox}. The solid continuous curve represents
the ``true'' CDF $\FDist(\TranShkEmp)$ for a lognormal distribution such that $\Ex[\TranShkEmp] = 1$, $\sigma_{\TranShkEmp} = 0.1$. The short vertical line segments represent the $n_{\TranShkEmp}$
equiprobable values of $\TranShkEmp_{i}$ which are used to approximate this
distribution.\footnote{More sophisticated approximation methods exist
(e.g.\ Gauss-Hermite quadrature; see \cite{kopecky2010finite} for a discussion of other alternatives), but the method described here is easy to understand, quick to calculate, and has additional advantages briefly described in the
discussion of simulation below.}
\begin{verbatimwrite}{\econtexRoot/Figures/discreteApprox.tex}
\hypertarget{discreteApprox}{}
\begin{figure}
\includegraphics[width=6in]{./Figures/discreteApprox}
\caption{Equiprobable Discrete Approximation to Lognormal Distribution $\FDist$}
\label{fig:discreteapprox}
\end{figure}
\end{verbatimwrite}
\input{\econtexRoot/Figures/discreteApprox.tex}\unskip
% \write18{cat \econtexRoot/Figures/discreteApprox.tex >> \econtexRoot/Figures/SolvingMicroDSOPs-Figures-List.tex}
Substituting into our definition of $\vEndStge({a}_{t})$, for $t=T-1$
\begin{verbatimwrite}{./Equations/vDiscrete.tex}
\begin{equation}\begin{gathered}\begin{aligned}
\vFunc_{T^{+}-1}({a}_{T-1}) & = \DiscFac \PermGroFac_{t+1}^{1-\CRRA}\left(\frac{1}{n_{\TranShkEmp}}\right)\sum_{i=1}^{n_{\TranShkEmp}} \frac{\left(\RNrm_{t+1} {a}_{t} + \TranShkEmp_{i}\right)^{1-\CRRA}}{1-\CRRA} \label{eq:vDiscrete}
\end{aligned}\end{gathered}\end{equation}
\end{verbatimwrite}
\input{./Equations/vDiscrete}\unskip
so we can rewrite the maximization problem as \ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny Be sure to discuss \eqref{eq:vEndTm1} explicitly, as it is implemented directly in the program as per equation \eqref{eq:vEndTm1prog}.}}{}
\begin{verbatimwrite}{./Equations/vEndTm1.tex}
\begin{equation}\begin{gathered}\begin{aligned}
{\vFunc}_{T-1}({m}_{T-1}) & = \max_{\cNrm_{T-1}}
\left\{
\frac{{c}_{T-1}^{1-\CRRA}}{1-\CRRA} +
\vFunc_{T^{+}-1}({m}_{T-1}-{c}_{T-1})
\right\}.
\label{eq:vEndTm1}
\end{aligned}\end{gathered}\end{equation}
\end{verbatimwrite}
\input{./Equations/vEndTm1.tex}\unskip
In the \texttt{SolvingMicroDSOPs} notebook, the section ``Discretization of the Income Shock Distribution'' provides code which instantiates the \texttt{DiscreteApproximation} class defined in the \texttt{resources} module. This class creates a discretization of the continuous log-normal distribution of transitory shocks to income by utilizing seven points, where the mean value is $-.5 \sigma^2$, and the standard deviation is $\sigma = .5$.
With a close look at the \texttt{DiscreteApproximation} class and its subclasses, one may notice that the code is a computational implementation of the mathematical description of equiprobable discrete approximation in this section. Moreover, the Python code generates a graph of the discretized distribution, similar to the one depicted in figure 1.
\hypertarget{The-Approximate-Consumption-and-Value-Functions}{}
\subsection{The Approximate Consumption and Value Functions}
Given a particular value of ${m}_{T-1}$, a numerical maximization routine can now find the ${c}_{T-1}$ that maximizes \eqref{eq:vEndTm1} in a reasonable amount of time.
The \texttt{SolvingMicroDSOPs} notebook follows a series of steps to achieve this. Initially, parameter values for the coefficient of relative risk aversion (CRRA, $\rho$), the discount factor ($\beta$), the permanent income growth factor ($\PermGroFac$), and the risk-free interest rate ($R$) are specified in ``Define Parameters, Grids, and the Utility Function''. Predictably, the CRRA utility function is defined for the given value of $\rho$ here as well.
After defining the utility function, the natural borrowing constraint is defined to be $\underline{a}{T-1}=-\underline{\TranShkEmp}\RNrm{T}^{-1}$, which will be discussed in greater depth in section \ref{subsec:LiqConstrSelfImposed}. Following the reformulation of the maximization problem, an instance of the \texttt{gothic\_class} is created using the specifications and the discretized distribution described in the previous lines of code; this is required to provide the numerical solution.
The heart of the program responsible for computing an estimated consumption function begins in ``Solving the Model by Value Function Maximization'', where a grid characterizing the possible values of market resources ($m$) is initialized, which is the first step in computing the optimal consumption and value functions. For each of the $m$ values, the consumption values $c$ that solve the minimization problem equivalent to \eqref{eq:vEndTm1} are computed using \texttt{scipy}'s minimize function. This level of consumption is used to calculate the value function at each point in the grid of market resources. The process is repeated until all $m$ grid points have been exhaused.
Finally, the previously computed values of optimal consumption and the grid of market resources are utilized to generate a graph of the approximated consumption function for this specific instance of the problem. To reduce the computational expenses of solving the problem, the process is repeated with a more sparse grid of market resources.
\hypertarget{an-interpolated-consumption-function}{}
\subsection{An Interpolated Consumption Function} \label{subsec:LinInterp}
Given a set of points on a function (in this case, the consumption function $\cFunc_{T-1}(\mNrm)$), we can create an object called an `interpolating function' which when applied to an input ${m}$ will yield the value of $\cNrm$ that corresponds to a linear `connect-the-dots' interpolation of the value of $\cNrm$ from the points, creating a function that aims to provide an approximation of the functions whose points have been sampled.
This is accompished in ``An Interpolated Consumption Function'', where the \texttt{InterpolatedUnivariateSpline} function is called from the \texttt{scipy} module to define an approximation to the consumption function $\Alt{\cFunc}_{T-1}({m}_{T-1})$. That is, when called with an ${m}_{T-1}$ that is equal to one of the points in \texttt{mVec\_int} returns the associated value of ${c}_{T-1,i}$, and when called with a value of ${m}_{T-1}$ that is not exactly equal to one of the \texttt{mVec\_int}, returns the value of ${c}$ that reflects a linear interpolation between the ${c}_{T-1,i}$ associated with the two \texttt{mVec\_int} points nearest to ${m}_{T-1}$. Thus if the function is called with ${m}_{T-1} = 1.75$ and the nearest gridpoints \ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny Go to the optimal consumption figure and show the connect-the-dots; point out that it's more obvious for the ${\vFunc}_{T-1}$.}}{} are ${m}_{j,T-1}=1$ and ${m}_{k,T-1}=2$ then the value of ${c}_{T-1}$ returned by the function would be $(0.25 {c}_{j,T-1}+0.75 {c}_{k,T-1})$. We can define a numerical approximation to the value function $\Alt{\vFunc}_{T-1}({m}_{T-1})$ in an exactly analogous way.
Figures \ref{fig:PlotcTm1Simple} and~\ref{fig:PlotVTm1Simple} show
plots of the $\Alt{\cFunc}_{T-1}$ and $\Alt{\vFunc}_{T-1}$
\texttt{InterpolatedUnivariateSpline} function calls. While the $\Alt{\cFunc}_{T-1}$ function looks very smooth, the fact that the $\Alt{\vFunc}_{T-1}$ function is a set of line segments is very evident. This figure provides the beginning of the intuition for why trying to approximate the value function directly is a bad idea (in this context).\footnote{For some problems,especially ones with discrete choices, value function approximation is unavoidable; nevertheless, even in such problems, the techniques sketched below can be very useful across much of the range over which the problem is defined.}
\hypertarget{PlotcTm1Simple}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/PlotcTm1Simple}}
\caption{$\cFunc_{T-1}({m}_{T-1})$ (solid) versus $\Alt{\cFunc}_{T-1}({m}_{T-1})$ (dashed)}
\label{fig:PlotcTm1Simple}
\end{figure}
\hypertarget{PlotvTm1Simple}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/PlotVTm1Simple}}
\caption{$\vFunc_{T-1}$ (solid) versus $\Alt{\vFunc}_{T-1}({m}_{T-1})$ (dashed)}
\label{fig:PlotVTm1Simple}
\end{figure}
\hypertarget{Interpolating-Expectations}{}
\subsection{Interpolating Expectations}
\ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny Good approximation in the sense that increasing the number of points makes no discernable difference.}}{}
The \texttt{InterpolatedUnivariateSpline} function works well in the sense that it generates a good approximation to the true optimal consumption function. However, there is a clear inefficiency in the program: Since it uses equation \eqref{eq:vEndTm1}, for every value of ${m}_{T-1}$ the program must calculate the utility consequences of various possible choices of $\cNrm_{T-1}$ as it searches for the best choice.
\ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny Problem:
\eqref{eq:maxprob2} means for every ${m}_{T-1}$ calc the value of
$\cFunc_{T-1}$; for a given ${a}_{T-1}$ (say 0) the value may be
calculated many times.}}{}
For any given value of ${a}_{T-1}$, notice that there is a good chance that the program may end up calculating the corresponding $\vEndStge$ many times while maximizing utility from different ${m}_{T-1}$'s. For example, it is possible that the program will calculate the value of ending the period with ${a}_{T-1}=0$ dozens of times. It would be much more efficient if the program could make that calculation once and then merely recall the value when it is needed again.
This can be achieved using the same interpolation technique used above
to construct a direct numerical approximation to the value function:
Define a grid of possible values for saving at time $T-1$,
$\vec{a}_{T-1}$
(\texttt{aVec}
in the code), designating the
specific points $\null{a}_{T-1,i}$; for each of these values of
$\null{a}_{T-1,i}$, calculate the vector $\vec{\vFunc}_{T^{+}-1}$ as the collection of points $\vFunc_{T^{+}-1,i} =
\vFunc_{T^{+}-1}(\null{a}_{T-1,i})$ using equation
(\ref{eq:vEndtdefn}); then construct an
\texttt{InterpolatingUnivariateSpline} object
$\Alt{\vFunc}_{T^{+}-1}({a}_{T-1})$ by passing the lists \texttt{aVec} and \texttt{gothicvVec} as arguments.
These lists contain the points of the $\vec{a}_{T-1}$ and $\vec{\vFunc}_{T^{+}-1}$ vectors, respectively.
As seen in the section ``Interpolating Expectations'', we are now interpolating for the function
that reveals the expected value of \textit{ending} the period with a given amount
of assets.\footnote{What we are doing here is closely related to `the
method of parameterized expectations' of
\cite{denHaanMarcet:parameterized}; the only difference is that our
method is essentially a nonparametric version.} The problem is solved in the same block withthe remaining following lines of code. Figure~\ref{fig:PlotOTm1RawVSInt}
compares the true value function to the
approximation produced following the interpolation procedure; the functions are of course
identical at the gridpoints chosen for ${a}_{T-1}$ and they appear
reasonably close except in the region below
${m}_{T-1}=1$.
\hypertarget{PlotOTm1RawVSInt}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/PlotOTm1RawVSInt}}
\caption{End-Of-Period Value $\vFunc_{T^{+}-1}({a}_{T-1})$ (solid) versus $\Alt{\vFunc}_{T^{+}-1}({a}_{T-1})$ (dashed)}
\label{fig:PlotOTm1RawVSInt}
\end{figure}
\hypertarget{PlotComparecTm1AB}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/PlotComparecTm1AB}}
\caption{$\cFunc_{T-1}({m}_{T-1})$ (solid) versus $\Alt{\cFunc}_{T-1}({m}_{T-1})$ (dashed)}
\label{fig:PlotComparecTm1AB}
\end{figure}
Nevertheless, the resulting consumption rule obtained when $\Alt{\vFunc}_{T^{+}-1}({a}_{T-1})$
is used\ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny Don't skip the 2-3-3-4
example in the text - it will be used again in a moment.}}{}
instead of $\vFunc_{T^{+}-1}({a}_{T-1})$ is surprisingly bad, as
shown in figure \ref{fig:PlotComparecTm1AB}. For example, when
${m}_{T-1}$ goes from 2 to 3, $\Alt{\cFunc}_{T-1}$ goes from about 1
to about 2, yet when ${m}_{T-1}$ goes from 3 to 4, $\Alt{\cNrm}_{T-1}$
goes from about 2 to about 2.05. The function fails even to be
strictly concave, which is distressing because Carroll and
Kimball~\citeyearpar{ckConcavity} prove that the correct
consumption function is strictly concave in a wide class of problems that
includes this problem.
\hypertarget{Value-Function-versus-First-Order-Condition}{}
\subsection{Value Function versus First Order Condition}\label{subsec:vVsuP}
Loosely speaking, our difficulty reflects the fact that the
consumption choice is governed by the \textit{marginal} value function,
not by the \textit{level} of the value function (which is the object that
we approximated). To understand this point, recall that a quadratic
utility function\ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny
Intuitively speaking, if one's goal is to accurately capture
behavior that is governed by marginal utility or the marginal
value function, numerical techniques that approximate the \textit{
marginal} value function are likely to work better.}}{} exhibits
risk aversion because with a stochastic ${c}$,
\begin{equation}
\Ex[-({c} - \cancel{c})^{2}] < - (\Ex[{c}] - \cancel{c})^{2}
\end{equation}
where $\cancel{c}$ is the `bliss point'. However, unlike the CRRA utility function,
with quadratic utility the consumption/saving \textit{behavior} of consumers
is unaffected by risk since behavior is determined by the first order condition, which
depends on \textit{marginal} utility, and when utility is quadratic, marginal utility is unaffected
by risk:
\begin{equation}
\Ex[-2({c} - \cancel{c})] = - 2(\Ex[{c}] - \cancel{c}).
\end{equation}
Intuitively, if one's goal is to accurately capture choices
that are governed by marginal value,
numerical techniques that approximate the \textit{marginal} value
function will yield a more accurate approximation to
optimal behavior than techniques that approximate the \textit{level}
of the value function.
The first order condition of the maximization problem in period $T-1$ is:
\begin{verbatimwrite}{./Equations/FOCTm1.tex}
\begin{equation}\begin{gathered}\begin{aligned}
\uFunc^{{c}}({c}_{T-1}) & = \DiscFac \Ex_{T-1} [\PermGroFac_{T}^{-\CRRA}\Rfree \uFunc^{{c}}({c}_{T})] %\label{eq:focraw}
\\ {c}_{T-1}^{-\CRRA} & = \Rfree \DiscFac \left(\frac{1}{n_{\TranShkEmp}}\right) \sum_{i=1}^{n_{\TranShkEmp}} \PermGroFac_{T}^{-\CRRA}\left(\Rfree ({m}_{T-1}-{c}_{T-1}) + \TranShkEmp_{i}\right)^{-\CRRA} \label{eq:FOCTm1}.
\end{aligned}\end{gathered}\end{equation}
\end{verbatimwrite}
\input{./Equations/FOCTm1.tex}\unskip
\ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny Go from the first to the last equation in \eqref{eq:FOCTm1} by substituting $\uFunc(c)=c^{-\CRRA}$ and use the approximation to the integral.}}{}
\hypertarget{PlotuPrimeVSOPrime}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/PlotuPrimeVSOPrime}}
\caption{$\uFunc^{{c}}(c)$ versus $\vFunc_{T^{+}-1}^{{a}}(3-c), \vFunc_{T^{+}-1}^{{a}}(4-c), \Alt{\vFunc}_{T^{+}-1}^{{a}}(3-c), \Alt{\vFunc}_{T^{+}-1}^{{a}}(4-c)$}
\label{fig:PlotuPrimeVSOPrime}
\end{figure}
In the notebook, ``Value Function versus the First Order Condition'' completes the task of finding the values
of consumption which satisfy the first order condition in \eqref{eq:FOCTm1} using
the \texttt{brentq} function from the \texttt{scipy} module. Notice that the use of \texttt{u.prime} and \texttt{gothic.VP\_Tminus1}
is possible since they are already defined in the
\texttt{resources} and \texttt{gothic\_class} modules.
The downward-sloping curve in Figure \ref{fig:PlotuPrimeVSOPrime}
shows the value of ${c}_{T-1}^{-\CRRA}$ for our baseline parameter values
for $0 \leq {c}_{T-1} \leq 4$ (the horizontal axis). The solid
upward-sloping curve shows the value of the RHS of (\ref{eq:FOCTm1})
as a function of ${c}_{T-1}$ under the assumption that ${m}_{T-1}=3$.
Constructing this figure is rather time-consuming, because for every
value of ${c}_{T-1}$ plotted we must calculate the RHS of
(\ref{eq:FOCTm1}). The value of ${c}_{T-1}$ for which the RHS and LHS
of (\ref{eq:FOCTm1}) are equal is the optimal level of consumption
given that ${m}_{T-1}=3$, so the intersection of the downward-sloping
and the upward-sloping curves gives the optimal value of ${c}_{T-1}$.
As we can see, the two curves intersect just below ${c}_{T-1}=2$.
Similarly, the upward-sloping dashed curve shows the expected value
of the RHS of (\ref{eq:FOCTm1}) under the assumption that ${m}_{T-1}=4$,
and the intersection of this curve with $\uFunc^{{c}}({c}_{T-1})$ yields the
optimal level of consumption if ${m}_{T-1}=4$. These two curves
intersect slightly below ${c}_{T-1}=2.5$. Thus, increasing ${m}_{T-1}$
from 3 to 4 increases optimal consumption by about 0.5.
\ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny Flip back to Figure
4 to make the point that $\Alt{\vEndStge}^{{a}}$ is a step
function.}}{} Now consider the derivative of our function
$\Alt{\vFunc}_{T^{+}-1}({a}_{T-1})$. Because we have constructed
$\Alt{\vFunc}_{T^{+}-1}$ as a linear interpolation, the slope of
$\Alt{\vFunc}_{T^{+}-1}({a}_{T-1})$ between any two adjacent
points $\{\null{a}_{T-1,i},{a}_{i+1,T-1}\}$ is constant. The
level of the slope immediately below any particular gridpoint is
different, of course, from the slope above that gridpoint, a fact
which implies that the derivative of
$\Alt{\vFunc}_{T^{+}-1}({a}_{T-1})$ follows a step function.
The solid-line step function in Figure \ref{fig:PlotuPrimeVSOPrime}
depicts the actual value of
$\Alt{\vFunc}_{T^{+}-1}^{{a}}(3-{c}_{T-1})$. When we attempt to find
optimal values of ${c}_{T-1}$ given ${m}_{T-1}$ using
$\Alt{\vFunc}_{T^{+}-1}({a}_{T-1})$, the numerical optimization
routine will return the ${c}_{T-1}$ for which $\uFunc^{{c}}({c}_{T-1}) =
\Alt{\vFunc}^{{a}}_{T^{+}-1}({m}_{T-1}-{c}_{T-1})$. Thus, for
${m}_{T-1}=3$ the program will return the value of ${c}_{T-1}$ for
which the downward-sloping $\uFunc^{{c}}({c}_{T-1})$ curve intersects with the
$\Alt{\vFunc}_{T^{+}-1}^{{a}}(3-{c}_{T-1})$; as the diagram shows,
this value is exactly equal to 2. Similarly, if we ask the routine
to find the optimal ${c}_{T-1}$ for ${m}_{T-1}=4$, it finds the point
of intersection of $\uFunc^{{c}}({c}_{T-1})$ with
$\Alt{\vFunc}_{T^{+}-1}^{{a}}(4-{c}_{T-1})$; and as the diagram shows,
this intersection is only slightly above 2. Hence, this figure
illustrates why the numerical consumption function plotted earlier
returned values very close to ${c}_{T-1}=2$ for both ${m}_{T-1}=3$ and
${m}_{T-1}=4$.
We would obviously obtain much better estimates of the point of
intersection between $\uFunc^{{c}}({c}_{T-1})$ and
$\vFunc_{T^{+}-1}^{{a}}({m}_{T-1}-{c}_{T-1})$ if our estimate of
$\Alt{\vFunc}^{{a}}_{T^{+}-1}$ were not a step function. In
fact, we already know how to construct linear interpolations
to functions, so the obvious next step is to construct a
linear interpolating approximation to the \textit{expected marginal
value of end-of-period assets function} $\vEndStge^{\prime}$. That is, we calculate
\begin{equation}\begin{gathered}\begin{aligned}
\vFunc_{T^{+}-1}^{{a}}({a}_{T-1}) & = \DiscFac \Rfree \PermGroFac_{T}^{-\CRRA} \left(\frac{1}{n_{\TranShkEmp}}\right) \sum_{i=1}^{n_{\TranShkEmp}} \left(\RNrm_{T} {a}_{T-1} + \TranShkEmp_{i}\right)^{-\CRRA} \label{eq:vEndPrimeTm1}
\end{aligned}\end{gathered}\end{equation}
at the points in \texttt{aVec} yielding
$\{\{\null{a}_{T-1,1},\vFunc_{T^{+}-1,1}^{{a}}\},\{{a}_{T-1,2},\vFunc_{T^{+}-1,2}^{{a}}\}
\ldots\}$ and construct
$\Alt{\vFunc}_{T^{+}-1}^{{a}}({a}_{T-1})$ as the linear
interpolating function that fits this set of points.
\hypertarget{PlotOPRawVSFOC}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/PlotOPRawVSFOC}}
\caption{$\vFunc_{T^{+}-1}^{{a}}({a}_{T-1})$ versus $\Alt{\vFunc}_{T^{+}-1}^{{a}}({a}_{T-1})$}
\label{fig:PlotOPRawVSFOC}
\end{figure}
This is done by making a call to the \texttt{InterpolatedUnivariateSpline} function,
passing it \texttt{aVec} and \texttt{vpVec} as arguments. Note that in defining the list of values \texttt{vpVec}, we again makes use of the
predefined \texttt{gothic.VP\_Tminus1} function. These steps are the embodiment of equation~(\ref{eq:vEndPrimeTm1}), and construct the
interpolation of the expected marginal value of end-of-period assets as described above.
The results are
shown in Figure \ref{fig:PlotOPRawVSFOC}. The linear
interpolating approximation looks roughly as good (or bad) for the
\textit{marginal} value function as it was for the level of the value
function. However, Figure \ref{fig:PlotcTm1ABC} shows that the new
consumption function (long dashes) is a considerably better
approximation of the true consumption function (solid) than was the
consumption function obtained by approximating the level of the
value function (short dashes).
\hypertarget{PlotcTm1ABC}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/PlotcTm1ABC}}
\caption{$\cFunc_{T-1}({m}_{T-1})$ (solid) Versus Two Methods for Constructing $\Alt{\cFunc}_{T-1}({m}_{T-1})$}
\label{fig:PlotcTm1ABC}
\end{figure}
\hypertarget{Transformation}{}
\subsection{Transformation}\label{subsec:transformation}
Even the new-and-improved consumption function diverges notably from the true
solution, especially at lower values of ${m}$. That is because the
linear interpolation does an increasingly poor job of capturing the
nonlinearity of $\vFunc_{T^{+}-1}^{{a}}({a}_{T-1})$ at
lower and lower levels of ${a}$.
This is where we unveil our next trick. To understand the logic,
start by considering the case where $\RNrm_{T} = \DiscFac =
\PermGroFac_{T} = 1$ and there is no uncertainty
\ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny Go over this
carefully.}}{} (that is, we know for sure that income next period
will be $\TranShkEmp_{T} = 1$). The final Euler equation is then:
\begin{equation}\begin{gathered}\begin{aligned}
{c}_{T-1}^{-\CRRA} & = {c}_{T}^{-\CRRA}.
\end{aligned}\end{gathered}\end{equation}
In the case we are now considering with no uncertainty and no liquidity
constraints, the optimizing consumer does not care whether a unit of
income is scheduled to be received in the future period $T$ or the
current period $T-1$; there is perfect certainty that the income will
be received, so the consumer treats it as equivalent to a unit of
current wealth. Total resources therefore are comprised of two types:
current market resources ${m}_{T-1}$ and `human wealth' (the PDV of
future income) of $\hEnd_{T-1}=1$ (where we use the Gothic font to
signify that this is the expectation, as of the END of the period, of
the income that will be received in future periods; it does not
include current income, which has already been incorporated into
${m}_{T-1}$).
The optimal solution is to spend half of total lifetime resources in
period $T-1$ and the remainder in period $T$. Since total resources
are known with certainty to be
${m}_{T-1}+\hEnd_{T-1}= {m}_{T-1}+1$, and since
${\vFunc}_{T-1}^{{m}}({m}_{T-1}) = \uFunc^{{c}}({c}_{T-1})$ this
implies that \ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny Crucial
point: this is \textit{marginal} value function in period $T-1$,
which we were trying to approximate with a linear interpolating
function earlier.}}{}
\begin{equation}
\vFunc^{{m}}_{T-1}({m}_{T-1}) = \left(\frac{{m}_{T-1}+1}{2}\right)^{-\CRRA} \label{eq:vPLin}.
\end{equation}
Of course, this is a highly nonlinear
function. However, if we raise both sides of \eqref{eq:vPLin} to the
power $(-1/\CRRA)$ the result is a linear function:
\begin{equation}\begin{gathered}\begin{aligned}
[\vFunc^{{m}}_{T-1}({m}_{T-1})]^{-1/\CRRA} & = \frac{{m}_{T-1}+1}{2} .
\end{aligned}\end{gathered}\end{equation}
This is a specific example of a general phenomenon: A theoretical
literature cited in~\cite{ckConcavity} establishes that under
perfect certainty, if the period-by-period marginal utility function
is of the form ${c}_{t}^{-\CRRA}$, the marginal value function will be
of the form $(\gamma {m}_{t}+\zeta)^{-\CRRA}$ for some constants
$\{\gamma,\zeta\}$. This means that if we were solving the perfect
foresight problem numerically, we could always calculate a numerically
exact (because linear) interpolation. To put this in intuitive terms,
the problem we are facing is that the marginal value function is
highly nonlinear. But we have a compelling solution to that problem,
because the nonlinearity springs largely from the fact that we are raising
something to the power $-\CRRA$. In effect, we can `unwind' all of
the nonlinearity owing to that operation and the remaining
nonlinearity will not be nearly so great. Specifically, applying the foregoing insights
to the end-of-period value function $\vFunc^{{a}}_{T^{+}-1}({a}_{T-1})$, we can define
\begin{equation}\begin{gathered}\begin{aligned}
\cFunc_{T^{+}-1}({a}_{T-1}) & \equiv \left(\vFunc^{{a}}_{T^{+}-1}({a}_{T-1})\right)^{-1/\CRRA} \label{eq:cGoth}
\end{aligned}\end{gathered}\end{equation}
which would be linear in the perfect foresight case. Thus, our
procedure is to calculate the values of $\cFunc_{T^{+}-1,i}$ at each
of the ${a}_{T-1,i}$ gridpoints, with the idea that we will construct
$\Alt{\cFunc}_{T^{+}-1}$ as the interpolating function connecting
these
points. % A comparison of the result to the true consumed function is presented in figure~\ref{fig:GothVInvVSGothC}. The two solutions are quite close.
\hypertarget{The-Natural-Borrowing-Constraint-and-the-a-Lower-Bound}{}
\subsection{The `Natural' Borrowing Constraint and the $a_{T-1}$ Lower Bound} \label{subsec:LiqConstrSelfImposed}
This is the appropriate moment to ask an awkward question we have so far
neglected: How should a function like $\Alt{\cFunc}_{T^{+}-1}$
be evaluated outside the range of points spanned by
$\{{a}_{T-1,1},...,{a}_{T-1,n}\}$ for which we have calculated
the corresponding $\cFunc_{T^{+}-1,i}$ gridpoints used to produce our
linearly interpolating approximation $\Alt{\cFunc}_{T^{+}-1}$ (as described in section~\ref{subsec:LinInterp})?
The natural answer would seem to be linear extrapolation; for example, we could use
\begin{equation}\begin{gathered}\begin{aligned}
\Alt{\cFunc}_{T^{+}-1}({a}_{T-1}) & = \Alt{\cFunc}_{T^{+}-1}({a}_{T-1,1})+\Alt{\cFunc}_{T^{+}-1}^{{a}}({a}_{T-1,1})({a}_{T-1}-{a}_{T-1,1}) \label{eq:ExtrapLin}
\end{aligned}\end{gathered}\end{equation}
for values of ${a}_{T-1} < {a}_{T-1,1}$, where $\Alt{\cFunc}_{T^{+}-1}^{{a}}({a}_{T-1,1})$ is the derivative of the $\Alt{\cFunc}_{T^{+}-1}$ function at the bottommost gridpoint (see below). Unfortunately, this approach
will lead us into difficulties. To see why, consider what
happens to the true (not approximated) $\vFunc^{{a}}_{T^{+}-1}({a}_{T-1})$ as
${a}_{T-1}$ approaches the value
$\underline{a}_{T-1}=-\underline{\TranShkEmp}\RNrm_{T}^{-1}$. From
\eqref{eq:vEndPrimeTm1} we have
\begin{equation}\begin{gathered}\begin{aligned}
\lim_{{a}_{T-1} \downarrow \underline{a}_{T-1}} \vFunc^{{a}}_{T^{+}-1}({a}_{T-1})
& = \lim_{{a}_{T-1} \downarrow \underline{a}_{T-1}} \DiscFac \Rfree \PermGroFac_{T}^{-\CRRA} \left(\frac{1}{n_{\TranShkEmp}}\right) \sum_{i=1}^{n_{\TranShkEmp}} \left( {a}_{T-1} \RNrm_{T}+ \TranShkEmp_{i}\right)^{-\CRRA}.
\end{aligned}\end{gathered}\end{equation}
\providecommand{\TranShkEmpMin}{}\renewcommand{\TranShkEmpMin}{\underline{\TranShkEmp}}
But since $\TranShkEmpMin=\TranShkEmp_{1}$, exactly at
${a}_{T-1}=\underline{a}_{T-1}$ the first term in the summation would
be $(-\TranShkEmpMin+\TranShkEmp_{1})^{-\CRRA}=1/0^{\CRRA}$ which is
infinity. The reason is simple: $-\underline{a}_{T-1}$ is
the PDV, as of $T-1$, of the minimum possible realization of income in
period $T$ ($\RNrm_{T}\underline{a}_{T-1} = -\TranShkEmp_{1}$). Thus,
if the consumer borrows an amount greater than or equal to
$\underline{\TranShkEmp}\RNrm_{T}^{-1}$ (that is, if the consumer ends
$T-1$ with ${a}_{T-1} \leq -\underline{\TranShkEmp}\RNrm_{T}^{-1}$) and
then draws the worst possible income shock in period $T$, they will have
to consume zero in period $T$ (or a negative amount), which yields
$-\infty$ utility and $\infty$ marginal utility (or undefined utility
and marginal utility).
These reflections lead us to the conclusion that the consumer faces a
`self-imposed' liquidity constraint (which results from the
precautionary motive): They will never borrow an amount greater
than or equal to $\underline{\TranShkEmp}\RNrm_{T}^{-1}$ (that is,
assets will never reach the lower bound of
$\underline{a}_{T-1}$).\footnote{Another term for a constraint of this
kind is the `natural borrowing constraint.'} The constraint is
`self-imposed' in the sense that if the utility function were
different (say, Constant Absolute Risk Aversion), the consumer would
be willing to borrow more than $\underline{\TranShkEmp}\RNrm_{T}^{-1}$
because a choice of zero or negative consumption in period $T$ would
yield some finite amount of utility.\footnote{Though it is very unclear what a
proper economic interpretation of negative consumption might be --
this is an important reason why CARA utility, like quadratic utility,
is increasingly not used for serious quantitative work, though it is
still useful for teaching purposes.}
This self-imposed constraint cannot be captured well when the
$\vFunc^{{a}}_{T^{+}-1}$ function is approximated by a piecewise
linear function like $\Alt{\vFunc}^{{m}}_{T^{+}-1}$, because a
linear approximation can never reach the correct gridpoint for
$\vFunc^{{a}}_{T^{+}-1}(\underline{a}_{T-1})=\infty.$ To see what
will happen instead, note first that if we are approximating $\vFunc^{{a}}_{T^{+}-1}$ the smallest value in
\texttt{aVec} must be greater than $\underline{a}_{T-1}$
(because the expectation for any gridpoint $\leq \underline{a}_{T-1}$ is undefined). Then when the
approximating $\vFunc^{{a}}_{T^{+}-1}$ function is evaluated at
some value less than the first element in \texttt{aVec}, the
approximating function will linearly extrapolate the slope that
characterized the lowest segment of the piecewise linear approximation
(between \texttt{aVec[0]} and \texttt{aVec[1]}), a
procedure that will return a positive finite number, even if the
requested ${a}_{T-1}$ point is below $\underline{a}_{T-1}$. This means that the
precautionary saving motive is understated, and by an arbitrarily
large amount as the level of assets approaches its true theoretical
minimum $\underline{a}_{T-1}$.
The foregoing logic demonstrates that the marginal value of saving approaches infinity as ${a}_{T-1} \downarrow
\underline{a}_{T-1}=-\underline{\TranShkEmp}\RNrm_{T}^{-1}$. But this
implies that $\lim_{{a}_{T-1} \downarrow \underline{a}_{T-1}}
\cFunc_{T^{+}-1}({a}_{T-1}) = (\vFunc^{{a}}_{T^{+}-1}({a}_{T-1}))^{-1/\CRRA} = 0$;
that is, as ${a}$ approaches its minimum possible value, the
corresponding amount of ${c}$ must approach \textit{its} minimum possible value: zero.
The upshot of this discussion is a realization that all we need to do is to
augment each of the $\vec{a}_{T-1}$ and $\vec{c}_{T-1}$ vectors with an extra point so that the
first element in the list used to produce our interpolation function is
$\{{a}_{T-1,0},{c}_{T-1,0}\}=\{\underline{a}_{T-1},0.\}$. This is done in section
``The Self-Imposed `Natural' Borrowing Constraint and the $a_{T-1}$ Lower Bound'' of the notebook,
which can be seen in the defined lists
\texttt{aVecBot} and \texttt{cVec3Bot}.
\hypertarget{GothVInvVSGothC}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/GothVInvVSGothC}}
\caption{$\cFunc_{T^{+}-1}({a}_{T-1})$ versus $\Alt{\cFunc}_{T^{+}-1}({a}_{T-1})$}
\label{fig:GothVInvVSGothC}
\end{figure}
From there, we plot the lists that have been appended with the natural borrowing contraint and the associated minimal level of consumption. The subseqeunt figure\ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny True $\cEndFunc$ is solid, linear approx is dashed.}}{} \ref{fig:GothVInvVSGothC} shows the result of this procedure. The solid line calculates the exact numerical value of $\cFunc_{T^{+}-1}({a}_{T-1})$ while the dashed line is the linear interpolating approximation $\Alt{\cFunc}_{T^{+}-1}({a}_{T-1}).$ This figure illustrates the value of the transformation: The true function is close to linear, and so the linear approximation is almost indistinguishable from the true function except at the very lowest values of ${a}_{T-1}$.
Figure~\ref{fig:GothVVSGothCInv} similarly shows that when we generate
$\Alt{\Alt{\vFunc}}_{T^{+}-1}^{\prime}({a}_{T-1})$ as
$[\Alt{\cFunc}_{T^{+}-1}({a}_{T-1})]^{-\CRRA}$ (dashed line) we
obtain a \textit{much} closer approximation to the true function
$\vFunc^{{a}}_{T^{+}-1}({a}_{T-1})$ (solid line) than we did in
the previous program which did not do the
transformation (Figure~\ref{fig:PlotOPRawVSFOC}). The calculation of marginal value using the transformation is performed and the
associated figure is produced.
\hypertarget{GothVVSGothCInv}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/GothVVSGothCInv}}
\caption{$\vFunc^{{a}}_{T^{+}-1}({a}_{T-1})$ vs. $\Alt{\Alt{\vFunc}}_{T^{+}-1}^{\prime}({a}_{T-1})$ Constructed Using $\Alt{\cFunc}_{T^{+}-1}({a}_{T-1})$}
\label{fig:GothVVSGothCInv}
\end{figure}
\hypertarget{The-Method-of-Endogenous-Gridpoints}{}
\subsection{The Method of Endogenous Gridpoints}
Our solution procedure for ${c}_{T-1}$ still requires us, for each
point in $\vec{m}_{T-1}$ (\texttt{mVec} in the code), to use a
numerical rootfinding algorithm to search for the value of ${c}_{T-1}$
that solves $\uFunc^{{c}}({c}_{T-1}) =
\vFunc^{{a}}_{T^{+}-1}({m}_{T-1}-{c}_{T-1})$. Unfortunately, rootfinding
is a notoriously computation-intensive (that is, slow!) operation.
Our next trick lets us completely skip the rootfinding step. The method can be understood by noting that
any arbitrary value of ${a}_{T-1,i}$ (greater than its lower bound
value $\underline{a}_{T-1}$) will be associated with \textit{some}
marginal valuation as of the end of period $T-1$, and the further
observation that it is trivial to find the value of ${c}$ that yields
the same marginal valuation, using the first order condition,
\begin{equation}\begin{gathered}\begin{aligned}
\uFunc^{{c}}({\cNrm}_{T-1,i}) & =
\vFunc^{{a}}_{T^{+}-1}({a}_{T-1,i}) \label{eq:eulerTm1}
\\ {\cNrm}_{T-1,i} & = \uFunc^{{c}-1}(\vFunc^{{a}}_{T^{+}-1}({a}_{T-1,i}))
\\ & = (\vFunc^{{a}}_{T^{+}-1}({a}_{T-1,i}))^{-1/\CRRA}
\\ & \equiv \cFunc_{T^{+}-1}({a}_{T-1,i})
\\ & \equiv \cFunc_{T^{+}-1,i}
.
\end{aligned}\end{gathered}\end{equation}
But with mutually consistent values of ${c}_{T-1,i}$ and ${a}_{T-1,i}$ (consistent, in the sense that they are the unique optimal
values that correspond to the solution to the problem in a single state), we can
obtain the ${m}_{T-1,i}$ that corresponds to both of them from
\begin{equation}\begin{gathered}\begin{aligned}
{m}_{T-1,i} & = {\cNrm}_{T-1,i}+{a}_{T-1,i}.
\end{aligned}\end{gathered}\end{equation}
These ${m}_{T-1}$ gridpoints are ``endogenous'' in contrast to the usual solution method of
specifying some \textit{ex-ante} grid of values of ${m}_{T-1}$ and then using a rootfinding
routine to locate the corresponding optimal ${c}_{T-1}$. This routine is performed in ``Endogenous Gridpoints''
. First, the \texttt{gothic.C\_Tminus1} function is called for each of the pre-specfied
values of end-of-period assets stored in \texttt{aVec}. These values of consumption and assets
are used to produce the list of endogenous gridpoints, stored in the object
\texttt{mVec\_egm}. With the $\vec{\cFunc}_{T^{+}-1}$ values in hand, we can generate a set of ${m}_{T-1,i}$ and ${\cNrm}_{T-1,i}$
pairs that can be interpolated between in order to yield
$\Alt{\cFunc}({m}_{T-1})$ at virtually zero computational cost!\footnote{This is
the essential point of \cite{carrollEGM}.} This is done in the final line of code in this block, and the following
code block produces the graph of the interpolated consumption function using this procedure.
One might worry about whether the $\{{m},{c}\}$ points obtained in this way will provide a
good representation of the consumption function as a whole, but in
practice there are good reasons why they work well (basically, this
procedure generates a set of gridpoints that is naturally dense right
around the parts of the function with the greatest nonlinearity).
\hypertarget{PlotComparecTm1AD}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/PlotComparecTm1AD}}
\caption{$\cFunc_{T-1}({m}_{T-1})$ (solid) versus $\Alt{\cFunc}_{T-1}({m}_{T-1})$ (dashed)}
\label{fig:ComparecTm1AD}
\end{figure}
Figure~\ref{fig:ComparecTm1AD} plots the actual consumption function
${\cFunc}_{T-1}$ and the approximated consumption function $\Alt{\cFunc}_{T-1}$
derived by the method of endogenous grid points. Compared to the approximate consumption
functions illustrated in Figure~\ref{fig:PlotcTm1ABC}, $\Alt{\cFunc}_{T-1}$ is quite close
to the actual consumption function.
\ifthenelse{\boolean{MyNotes}}{\marginpar{\tiny Different transformation for $\vFunc$ than for $\vFunc^{\prime}$.}}{}