-
Notifications
You must be signed in to change notification settings - Fork 19
/
SolvingMicroDSOPs-clean.tex
1714 lines (1352 loc) · 148 KB
/
SolvingMicroDSOPs-clean.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
% Add the listed directories to the search path
% (allows easy moving of files around later)
% these paths are searched AFTER local config kpsewhich
\makeatletter
\def\input@path{{./.resources/latex/}{./.resources/texlive/}{./.resources/texmf-local/tex/latex/}{./resources/texmf-local/tex/bibtex/}{./.resources/econ-ark/}{./Code/Python/snippets/}}
\makeatother
% allow latex to find custom stuff
\documentclass[titlepage, headings=optiontotocandhead]{econark}
\newcommand{\texname}{SolvingMicroDSOPs} % Keyname for the paper
% specific to this paper
% \usepackage{econark-titlepage} % custom titlepage
% These are in various subdirectories searched by add-latex-search-paths
\usepackage{local-macros} % defns for this project
\usepackage{local-econark} % econark defns
\usepackage{llorracc-handouts} % allow references to llorracc-handouts
\usepackage{owner} % llorracc or econ-ark?
\usepackage{local-packages} % LaTeX config in ./resources/latex
% booleans control whether certain options are on or off:
% Controls for which of various variant versions to create
\provideboolean{ctwVersion}\setboolean{ctwVersion}{false}\newcommand{\ctw}{\ifthenelse{\boolean{ctwVersion}}} % {cctw}
\provideboolean{trpVersion}\setboolean{trpVersion}{false}\newcommand{\trp}{\ifthenelse{\boolean{trpVersion}}} % {trp}
% \setboolean{trpVersion}{true} % {trp}
\setboolean{trpVersion}{false} % {trp}
% Draft mode puts \labels of figs, tables, eqns in margin
\provideboolean{draftmode}\setboolean{draftmode}{true}
% \setboolean{draftmode}{false}
\newcommand{\Draft}{\ifthenelse{\boolean{draftmode}}}
\Draft{
\usepackage[left]{showlabels}
}{}
% Include or exclude Method of Moderation material
\provideboolean{MoMVersion}\setboolean{MoMVersion}{true}
%\setboolean{MoMVersion}{false}
\newcommand{\MoM}{\ifthenelse{\boolean{MoMVersion}}}
% Get extra style stuff for cctwMoM
\MoM{ % {cctw}
\usepackage{cctwMoM} % {cctw}
}{} % {cctw}
% Versions with or without permanent shocks
% Seems to be defunct - remove
\provideboolean{PermShkVersion}\setboolean{PermShkVersion}{true}
\setboolean{PermShkVersion}{false}
\newcommand{\PermShkOn}{\ifthenelse{\boolean{PermShkVersion}}}
% MPCMatch version does Hermite polynomials for the interpolation
% that match both the slope and the intercept at the gridpoints
\provideboolean{MPCMatchVersion}\setboolean{MPCMatchVersion}{true}
\newcommand{\MPCMatch}{\ifthenelse{\boolean{MPCMatchVersion}}}
% mynotes
\provideboolean{MyNotes}\setboolean{MyNotes}{true}
%\setboolean{MyNotes}{false}
% realcode
\provideboolean{realcode}\setboolean{realcode}{false}
%\setboolean{realcode}{false}
\newcommand{\ifcode}{\ifthenelse{\boolean{realcode}}}
% pseudocode
\provideboolean{pseudocode}\setboolean{pseudocode}{false}
%\setboolean{pseudocode}{false}
\newcommand{\ifpseudo}{\ifthenelse{\boolean{pseudocode}}}
% margin notes
\provideboolean{Margnote}\setboolean{Margnote}{true}
% \setboolean{Margnote}{false}
\newcommand{\ifMarg}{\ifthenelse{\boolean{Margnote}}}
% Show things that need fixing
\provideboolean{ToFix}\setboolean{ToFix}{true}
% \setboolean{ToFix}{false}
\newcommand{\Fix}{\ifthenelse{\boolean{ToFix}}}
% Show or hide the time subscripts
\provideboolean{hidetime}\setboolean{hidetime}{true}
% \setboolean{hidetime}{false}
\newcommand{\timehide}{\ifthenelse{\boolean{hidetime}}}
\provideboolean{verbon}\setboolean{verbon}{true}
\newcommand{\onverb}{\ifthenelse{\boolean{verbon}}}
\setboolean{showPageHead}{true}
% \econtexSetup sets boolean variable 'Web' to true if making html not pdf
\ifthenelse{\boolean{Web}}{ % then
\setboolean{showPageHead}{false} % no pages, so no page head, on web
}{ % else not for web
\usepackage{scrlayer-scrpage} % Package for page headers if PDF
\automark[section]{section}
\usepackage{caption} % allow suppression of appendix figures in NoAppendix PDF
}
% replace macros with their referents using demacro
% (only operative when processing doc with demacro script):
% replace only a few things that are single letter vars
\provideboolean{demacro}\setboolean{demacro}{false}
\ifthenelse{\boolean{demacro}}{}{}
% Only operative when running demacro script on document-clean
% (de-macro-do.sh script changes the name to end in -private)
\provideboolean{demacromore}\setboolean{demacromore}{false}
\ifthenelse{\boolean{demacromore}}{\usepackage{SolvingMicroDSOPs-clean-private}}{}
% Configure html links etc
\hypersetup{colorlinks=true,
pdfauthor={Christopher D. Carroll <[email protected]>},
pdftitle={Solution Methods for Microeconomic Dynamic Stochastic Optimization Problems},
pdfsubject={Dynamic Stochastic Optimization Theory; Lecture Notes},
pdfkeywords={Numerical Methods, Software, Computational Economics, Bellman},
pdfcreator = {pdflatex},
plainpages=false,
pdfpagelabels,
colorlinks=true,
citecolor=magenta
}
\bibliographystyle{econark}% Like econometrica.bst but with full names rather than initials
\begin{document}
% Sections = _sectn-
\pagenumbering{roman}
\title{\Large Solution Methods for Microeconomic \\ \Large Dynamic Stochastic Optimization Problems}
\author{\large Christopher D. Carroll\authNum}
\keywords{Dynamic Stochastic Optimization, Method of Simulated Moments, Structural Estimation, Indirect Inference}
\jelclass{E21, F41 \par
\href{https://econ-ark.org}{\includegraphics{.resources/econ-ark/PoweredByEconARK}}
}
\large
\date{\today}
\maketitle
\footnotesize
\noindent Note: The GitHub repo {\SMDSOPrepo} associated with this document contains python code that produces all results, from scratch, except for the last section on indirect inference. The numerical results have been confirmed by showing that the answers that the raw python produces correspond to the answers produced by tools available in the {\ARKurl} toolkit, more specifically those in the {\HARKrepo} which has full {\HARKdocs}. The MSM results at the end have have been superseded by tools in the {\EMDSOPrepo}.
\normalsize
\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 Python code that solves the problems described in the text.
\end{abstract}
% \ifthenelse{\boolean{Web}}{}{
\begin{footnotesize}
\begin{center}
\begin{tabbing}
\texttt{~~~~PDF:~} \= \= {\urlPDF} \\
\texttt{~Slides:~} \> \> {\urlSlides} \\
\texttt{~~~~Web:~} \> \> {\urlHTML} \\
\texttt{~~~Code:~} \> \> {\urlCode} \\
\texttt{Archive:~} \> \> {\urlRepo} \\
\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, \\
\href{mailto:[email protected]}{\texttt{[email protected]}}}
\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
\thispagestyle{empty} % don't show the page number
\ifpdf % The table of contents does not work if not in pdf mode
\tableofcontents \addtocontents{toc}{\vspace{1em}}\newpage
\fi
\newpage\pagenumbering{arabic} % start arabic numbering anew after titlepage
\thispagestyle{empty} % don't show the page number
\hypertarget{introduction}{}
\section{Introduction}\label{sec:introduction}
These lecture notes provide a gentle introduction to a particular set of solution tools for the canonical consumption-saving/portfolio allocation problem. Specifically, the notes describe and solve optimization problems for a consumer facing uninsurable idiosyncratic risk to nonfinancial income (e.g., labor or transfer income), first without and then with optimal portfolio choice,\footnote{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 various mathematical and computational techniques that, together, speed the solution by many orders of magnitude. 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. Finally, a simple example shows how to use these methods (via the statistical `method of simulated moments' (MSM for short)) to estimate structural parameters like the coefficient of relative risk aversion (\textit{a la} Gourinchas and Parker~\citeyearpar{gpLifecycle} and Cagetti~\citeyearpar{cagettiWprofiles}).
\hypertarget{the-problem}{}
\section{The Problem}\label{sec:the-problem}
The usual analysis of dynamic stochastic programming problems packs a great many events (intertemporal choice, stochastic shocks, intertemporal returns, income growth, the taking of expectations, time discounting, and more) into a complex decision in which the agent makes an optimal choice simultaneously taking all these elements into account. For the dissection here, we will be careful to break down everything that happens into distinct operations so that each element can be scrutinized and understood in isolation.
We are interested in the behavior a consumer who begins {\interval} $\prd$ with a certain amount of `capital' $\kLvl_{\prd}$, which is immediately rewarded by a return factor $\Rfree_{\prd}$ with the proceeds deposited in a \textbf{b}ank \textbf{b}alance:
\begin{equation}\begin{gathered}\begin{aligned}\label{eq:bLvl}
\bLvl_{\prd} & = \kLvl_{\prd}\Rfree_{\prd}.
\end{aligned}\end{gathered}\end{equation}
Simultaneously with the realization of the capital return, the consumer also receives noncapital income $\yLvl_{\prd}$, which is determined by multiplying the consumer's `permanent income' $\pLvl_{\prd}$ by a transitory shock $\tranShkEmp_{\prd}$:
\begin{equation}\begin{gathered}\begin{aligned}
\yLvl_{\prd} & = \pLvl_{\prd}\tranShkEmp_{\prd} \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_{\prd}$).
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_{\prd} & = \bLvl_{\prd}+\yLvl_{\prd} \label{eq:mLvl},
\end{aligned}\end{gathered}\end{equation}
available to be spent on consumption $\cLvl_{\prd}$ for a consumer subject to a liquidity constraint that requires $\cLvl \leq \mLvl$ (though we are not imposing such a constraint yet - see subsection~\ref{subsec:LiqConstrSelfImposed}). Finally we define
\begin{equation}\begin{gathered}\begin{aligned}\label{eq:aLvl}
\aLvl_{t} & = \mLvl_{t}-\cLvl_{t}
\end{aligned}\end{gathered}\end{equation}
mnemnoically as `assets-after-all-actions-are-accomplished.'
The consumer's goal is to maximize discounted utility from consumption over the rest of a lifetime ending at date $\trmT$:
% chktex-file 36
\begin{equation}\label{eq:MaxProb}
\max~\Ex_{\prd}\left[\sum_{n=0}^{\trmT-\prd}\DiscFac^{n} \uFunc(\cLvl_{\prd+n})\right].
\end{equation}
Income evolves according to:
\begin{equation}\begin{gathered}\begin{aligned}
\pLvl_{\prd+1} = \PermGroFac_{\prd+1}\pLvl_{\prd} & \text{~~ -- permanent labor income dynamics} \label{eq:permincgrow}
\\ \log ~ \tranShkEmp_{t+n} \sim ~\Nrml(-\std_{\tranShkEmp}^{2}/2,\std_{\tranShkEmp}^{2}) & \text{~~ -- lognormal transitory shocks}~\forall~n>0 .
\end{aligned}\end{gathered}\end{equation}
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{For expositional and pedagogical purposes, this equation assumes that there are no shocks to permanent income (though they are trivial to add). 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}.} 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{equation}\begin{gathered}\begin{aligned}
\vFunc_{\prd}(\mLvl_{\prd},\pLvl_{\prd}) & = \max_{\cLvl}~ \uFunc(\cLvl) + \DiscFac \Ex_{\prd}[ \vFunc_{\prd+1}(\mLvl_{\prd+1},\pLvl_{\prd+1})]\label{eq:vrecurse}
\end{aligned}\end{gathered}\end{equation}
subject to the Dynamic Budget Constraint (DBC) implicitly defined by equations~\eqref{eq:bLvl}-\eqref{eq:mLvl} and to 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_{\prd+1} & = \aLvl_{\prd}. \label{eq:transitionstate}
\end{aligned}\end{gathered}\end{equation}
%\onlyinsubfile{\input{.resources/latex/bibliography-blend}}
%\input{./.resources/latex/bibliography-blend}\end{document}\endinput % \endinput prevents any processing of subsequent stuff
\hypertarget{normalization}{}
\section{Normalization}\label{sec:normalization}
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 at all possible). In the consumption context, 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_{\prd}$ (henceforth for brevity, `permanent income.')
In the last {\interval} of life $\trmT$, there is no future value, $\vLvl_{\trmT+1} = 0$, so the optimal plan is to consume everything:
\begin{equation}\begin{gathered}\begin{aligned}
\vFuncLvl_{\trmT}(\mLvl_{\trmT},\pLvl_{\trmT}) & = \frac{\mLvl_{\trmT}^{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_{\trmT}=\mLvl_{\trmT}/\pLvl_{\trmT}$; and define $\vFunc_{\trmT}(m_{\trmT}) = \uFunc(m_{\trmT})$.\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 (\ref{eq:levelTm1}) can be rewritten as
\begin{equation}\begin{gathered}\begin{aligned}
\vFuncLvl_{\trmT}(\mLvl_{\trmT},\pLvl_{\trmT}) & = \pLvl_{\trmT}^{1-\CRRA}\frac{m_{\trmT}^{1-\CRRA}}{1-\CRRA} \\
% & = (\pLvl_{\trmT-1}\PermGroFac_{\trmT})^{1-\CRRA}\frac{{\mNrm}_{\trmT}^{1-\CRRA}}{1-\CRRA} \\
&= \pLvl_{\trmT-1}^{1-\CRRA}\PermGroFac_{\trmT}^{1-\CRRA}\vFunc_{\trmT}(m_{\trmT}). \label{eq:vT}
\end{aligned}\end{gathered}\end{equation}
Now define a new optimization problem:
\begin{equation}\begin{gathered}\begin{aligned}
\vFunc_{\prd}(m_{\prd}) & = \max_{{c}_{\prd}} ~~ \uFunc(c_{\prd})+\DiscFac \Ex_{\prd}[ \PermGroFac_{\prd+1}^{1-\CRRA}\vFunc_{\prd+1}(m_{\prd+1})] \label{eq:vNormed} \\
& \text{s.t.} \\
a_{\prd} & = m_{\prd}-c_{\prd} \\
k_{\prd+1} & = a_{\prd} \\
b_{\prd+1} & = \underbrace{\left(\Rfree/\PermGroFac_{\prd+1}\right)}_{\equiv \RNrmByG_{\prd+1}}k_{\prd+1} \\
m_{t+1} & = b_{t+1}+\tranShkEmp_{t+1},
\end{aligned}\end{gathered}\end{equation}
where division by $\PermGroFac$ in second-to-last equation yields a normalized return factor $\RNrmByG$ which is the consequence of the fact that we have divided $\prd+1$ level variables by $\pLvl_{\prd+1}=\PermGroFac_{\prd+1}\pLvl_{\prd}$.
\ifpseudo{ % pseudocode goes here
\lstinputlisting{equiprobable-make.py}\nopagebreak
}{}
Then it is easy to see that for $\prd=\trmT-1$, we can write boldface (nonnormalized) $\vFuncLvl$ as a function of $\vFunc$ (normalized value) and permanent income:
\begin{equation}\begin{gathered}\begin{aligned}
\vFuncLvl_{\prd}(\mLvl_{\prd},\pLvl_{\prd}) & = \pLvl_{\prd}^{1-\CRRA}\vFunc_{\prdt}(m_{\prdt}), \label{eq:vLvlFromvFunc}
\end{aligned}\end{gathered}\end{equation}
and so on back to all earlier periods. Hence, if we solve the problem \eqref{eq:vNormed} which has only a single state variable $m_{\prd}$, we can obtain the levels of the value function from \eqref{eq:vLvlFromvFunc}, and of consumption and all other variables from the corresponding permanent-income-normalized solution objects by multiplying each by $\pLvl_{\prd}$, e.g.\
\begin{equation*}\begin{gathered}\begin{aligned}
\cFunc_{\prd}(\mLvl_{\prd},\pLvl_{\prd})=\pLvl_{\prd}\cFunc_{\prd}(\overbrace{\mLvl_{\prd}/\pLvl_{\prd}}^{m_{\prd}}).
\end{aligned}\end{gathered}\end{equation*}
%(or, for the value function, $\vFuncLvl _{\prd}(\mLvl_{\prd},\pLvl_{\prd}) = \pLvl_{\prd}^{1-\CRRA}\vFunc_{\prd}(\mNrm_{\prd}))$.
We have thus reduced the problem from two continuous state variables to one (and thereby enormously simplified its solution).
For future reference it is useful to write \eqref{eq:vNormed} in the traditional way, by substituting $b_{\prdt+1},k_{\prdt+1},$ and $a_{\prdt}$ into $m_{t+1}$:
\begin{equation}\begin{gathered}\begin{aligned}
\vFunc_{\prdt}(m_{\prdt}) & = \max_{c} ~~ \uFunc(c)+ \DiscFac \Ex_{\prdt}[ \PermGroFac_{\prdt+1}^{1-\CRRA}\vFunc_{\prdt+1}(\overbrace{(m_{t}-c)(\Rfree/\PermGroFac_{t+1})+\tranShkEmp_{t+1}}^{m_{t+1}})] \label{eq:vusual}.
\end{aligned}\end{gathered}\end{equation}
\hypertarget{notation}{}
\section{Notation}\label{sec:notation}
\subsection{\Intervals, \Stgs, \Moves}
The problem so far assumes that the agent has only one decision problem to solve in any {\interval}. But it is increasingly common to model agents who have multiple choice {\stg}s per {\interval}; a problem might have, say, a consumption decision (call it the $\cFunc$ {\stg}), a labor supply {\stg} (call it $\labor$) and a choice of what proportion $\Shr$ of their assets to invest in a risky asset (the portfolio-choice {\stg}).
The modeler might well want to explore whether the order in which the {\stg}s are solved makes any difference, either to the substantive results or to aspects of the computational solution like speed and accuracy.
If, as in section \ref{sec:the-problem}, we hard-wire into the solution code for each {\stg} an assumption that its successor {\stg} will be something in particular (say, the consumption {\stg} assumes that the portfolio choice is next), then if we want to change the order of the {\stg}s (say, labor supply after consumption, followed by portfolio choice), we will need to re-hard-wire each of the stages to know particular things about its new successor (for example, the specifics of the distribution of the rate of return on the risky asset must be known by whatever {\stg} precedes the portfolio choice {\stg}).
But one of the cardinal insights of Bellman's (1957, ``Dynamic Programming'') original work is that \emph{everything that matters} for the solution to the current problem is encoded in a `continuation-value function.' %that incorporates \texttt{everything about the future} that is important to solution of the present stage. %This point is important for a number of reasons, but here we will focus on one problem of ignoring it. Actual solution of the maximization problem as specified in \eqref{eq:vNormed} requires the current agent to have knowledge not only of the successor value function, but also of other aspects of the problem like the distributions of the future period's stochastic shocks. So any solution to the problem that directly uses in \eqref{eq:vNormed} will need to hard-wire into itself the specifics of the successor problem.
Using Bellman's insight, we describe here a framework for isolating the {\stg} problems within a {\interval} from each other, and the {\interval} from its successors in any future {\interval}; the advantage of this is that the isolated {\stg} and {\interval} problems will then be `modular': We can solve them in any order \textit{without changing any code} (only transitions need to be rewired). After considering the {\stg}-order $[\ell,\cFunc,\Shr]$, the modeler can costlessly reorder the {\stg}s to consider, say, the order $[\ell,\Shr,\cFunc]$.\footnote{As long as the beginning-of-{\stg} and end-of-{\stg} value functions for the {\stg}s all depend on the same state variables; see the discussion in section \ref{sec:multiple-control-variables}.}
\hypertarget{moves}{}
\subsection{\Moves}\label{subsec:steps}
The key is to distinguish, within each {\stg}'s Bellman problem, three {\moves}:
\begin{enumerate}
\item \textbf{\Arrival}: Incoming state variables (e.g., $k$) are known, but any shocks associated with the period have not been realized and decision(s) have not yet been made
\item \textbf{\Decision}: The agent solves the decision problem for the period
\item \textbf{\Continuation}: After all decisions have been made, their consequences are measured by evaluation of the continuing-value function at the values of the `outgoing' state variables (sometimes called `post-state' variables).
\end{enumerate}
Notice that this specification is silent about when the stochastic shocks are realized; this may occur either before or after the decision stage. In the consumption problem we are studying, the natural choice is to assume that the shocks have been realized before the decision is made so that the consumer knows what their income has been for the period. In the portfolio problem we will examine below, the portfolio share decision must be made before the stochastic returns are realized.
% In the standard treatment in the literature, the (implicit) default assumption is that the {\move} where the agent is solving a decision problem is the unique {\move} at which the problem is defined. This is what was done above, when (for example) in \eqref{eq:vNormed} we related the value $\vFunc$ of the current decision to the expectation of the future value $\vFunc_{\prd+1}$. Here, instead, we want to encapsulate the current {\stg}'s problem as a standalone object, which is solved by taking as given an exogenously-provided continuation-value function (in our case, $\vEndStg(a)$).
When we want to refer to a specific {\move} in the {\stg} we will do so by using an indicator which identifies that {\move}. Here we use the consumption {\stg} problem described above to exemplify the usage:
\begin{center}
% \mbox{%
\begin{tabular}{r|c|c|l|l}
{\Move} & Indicator & State & Usage & Explanation \\ \hline
{\Arrival} & $ \arvl $ & $k$ & $\vBegStg(k)$ & value at entry to {\stg} (before shocks) \\
{\Decision}(s) & (blank) & $m$ & $\vMidStg(m)$ & value of {\stg}-decision (after shocks) \\
{\Continuation} & $ \cntn $ & $a$ & $\vEndStg(a)$ & value at exit (after decision) \\ \hline
\end{tabular}
% }
\end{center}
Notice that the value functions at different {\move}s of the {\stg} have distinct state variables. Only $k$ is known at the beginning of the {\stg}, and other variables take on their values with equations like $b = k \RNrmByG$ and $m = b+\tranShkEmp.$ We will refer to such within-the-{\stg} creation of variables as `{\evltns}.' So, the consumption stage problem has two {\evltns}: from $k$ to $m$ and from $m$ to $a$.
\ifpseudo{
\lstinputlisting{./Code/Python/snippets/pseudo-model-setup-prdT.py}\nopagebreak
}{}
\hypertarget{transitions}{}
\subsection{\Trnsns}\label{subsec:transitions}
In the backward-induction world of Bellman solutions, to solve the problem of a particular {\interval} we must start with an end-of-{\interval} (continuation) value function, which we designate by explicitly including the {\interval} indicator in the subscript (the $:=$ symbol denotes that the object on the right hand side is assigned to the object on the left hand side; the left object `gets' the right object):\ifMarg{\tiny needs discussion: It's made at the time of execution of Matt's link structure; but is it a pointer, a deepcopy, an algorithm, or what?}{}\normalsize
\begin{equation}\begin{gathered}\begin{aligned}
\vEndPrd(a) & \leftassign \DiscFac \vBegPrdNxt(\overbrace{a}^{=k}), \label{eq:trns-single-prd} %
\end{aligned}\end{gathered}\end{equation}
and we are not done solving the problem of {\interval} {\prd} until we have constructed a beginning-of-{\interval} value function $\vBegPrd(k)$.
Similarly, in order to solve the problem of any {\stg}, we must endow it with an end-of-{\stg} continuation-value function. For the last {\stg} in a {\interval}, the end-of-{\stg} function is taken to be end-of-{\interval} value function; in our case where there is only one {\stg}, this can be written cleanly as:
\begin{equation}\begin{gathered}\begin{aligned} \label{eq:last-stg-v-is-end-prd-v}
\vEndStg(a) \leftassign \vEndPrd(a).
\end{aligned}\end{gathered}\end{equation}
\Fix{\marginpar{\tiny pseudocode? \normalsize}}{}\normalsize
\subsection{The Decision Problem in the New Notation}\label{subsec:decision-problem}\hypertarget{decision-problem}{}
From `inside' the decision stage, the {\Decision} problem can now be written much more cleanly than in equation \eqref{eq:vNormed}:
\begin{equation}\begin{gathered}\begin{aligned}
\vFunc(m) & = \max_{c}~ \uFunc(c) + \vFunc_{_\cntn}(\overbrace{m-\cFunc}^{=a}) \label{eq:vMidStgCNrm}
\end{aligned}\end{gathered}\end{equation}
\begin{comment}
\subsection{Implementation in Python}
The code implementing the tasks outlined each of the sections to come is available in the \texttt{\href{https://econ-ark.org/materials/SolvingMicroDSOPs}{SolvingMicroDSOPs}} jupyter notebook, written in \href{https://python.org}{Python}. 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 auxilliary 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:vBegStg} - \eqref{eq:EndPrd} (and the corresponding 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 methods used to the problem in subsequent sections of this document.
\end{comment}
% Local Variables:
% eval: (setq prettify-symbols-unprettify-at-point 'right-edge)
% coding: utf-8
% End:
\hypertarget{the-usual-theory}{}
\section{The Usual Theory, and a Bit More Notation}\label{sec:the-usual-theory}
For reference and to illustrate our new notation, we will now derive the Euler equation and other standard results for the problem described above.
Since we can write value as of the end of the consumption stage as a function of $a$:
\begin{equation*}\begin{gathered}\begin{aligned}
\vEndStg(a) & \leftassign \vFunc_{\prd_\cntn}(a) \leftassign \DiscFac \vBegPrdNxt(a) = \DiscFac \Ex_{\BegPrdNxt}[\PermGroFac_{\prd+1}^{1-\CRRA}\vFunc_{\prd+1}(\overbrace{a (\Rfree / \PermGroFac_{\prd+1})+\tranShkEmp_{\prd+1}}^{m_{\prd+1}})],
\end{aligned}\end{gathered}\end{equation*}
the first order condition for \eqref{eq:vusual} with respect to $a$ (given $m_{\prd}$) is
\begin{equation}\begin{gathered}\begin{aligned}
\uFunc^{c}(m_{\prd}-a) = \vEndPrd^{a}(a) & = \Ex_{\BegPrdNxt}[\DiscFac \RNrmByG_{\prd+1}\PermGroFac_{\prd+1}^{1-\CRRA}{\vFunc}^m_{\prd+1}(m_{\prd+1})] \label{eq:upceqEvtp1}
\\ & = \Ex_{\BegPrdNxt}[\DiscFac\Rfree\phantom{._{\prd+1}}\PermGroFac_{\prd+1}^{\phantom{1}-\CRRA}{\vFunc}^{m}_{\prd+1}(m_{\prd+1})]
\end{aligned}\end{gathered}\end{equation}
and because the \handoutC{Envelope} theorem tells us that
\begin{equation}\begin{gathered}\begin{aligned}
{\vFunc}^{m}_{\prd}(m_{\prd}) & = \Ex_{\BegPrdNxt} [\DiscFac \Rfree \PermGroFac_{\prd+1}^{-\CRRA}{\vFunc}^{m}_{\prd+1}(m_{\prd+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{equation}\begin{gathered}\begin{aligned}
\uFunc^{c}(c_{\prd}) & = {\vFunc}^{m}_{\prd}(m_{\prd})\label{eq:upcteqvtp}
\end{aligned}\end{gathered}\end{equation}
and rolling forward one {\interval},
\begin{equation}\begin{gathered}\begin{aligned}
\uFunc^{c}(c_{\prd+1}) & = \vFunc^{m}_{\prd+1}({a}_{\prd}\RNrmByG_{\prd+1}+\tranShkEmp_{\prd+1}) \label{eq:upctp1EqVpxtp1}
\end{aligned}\end{gathered}\end{equation}
so that substituting the LHS in equation (\ref{eq:upceqEvtp1}) finally gives us the Euler equation for consumption:
\begin{equation}\begin{gathered}\begin{aligned}
\uFunc^{c}(c_{\prd}) & = \ExEndPrd[\DiscFac \Rfree \PermGroFac_{\prd+1}^{-\CRRA}\uFunc^{c}(c_{\prd+1})] \label{eq:cEuler}.
\end{aligned}\end{gathered}\end{equation}
We can now restate the problem \eqref{eq:vusual} with our new within-stage notation:
\begin{equation}\begin{gathered}\begin{aligned}
\vFunc(m) & = \max_{c} ~~ \uFunc(c)+ \vEndStg(m-c)
\end{aligned}\end{gathered}\end{equation}
whose first order condition with respect to $c$ is
\begin{equation}\begin{gathered}\begin{aligned}
\uFunc^{c}(c) &= \vEndStg^{a}(m-c) \label{eq:upEqbetaOp} % \label{eq:FOCnew}
\end{aligned}\end{gathered}\end{equation}
which is mathematically equivalent to the usual Euler equation for consumption.
We will revert to this formulation when we reach section~\ref{subsec:egm}.
\begin{comment}
\subsection{Implementation in Python}
The code implementing the tasks outlined each of the sections to come is available in the \texttt{\href{https://econ-ark.org/materials/SolvingMicroDSOPs}{SolvingMicroDSOPs}} jupyter notebook, written in \href{https://python.org}{Python}. 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 auxilliary 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:vBegStg} - \eqref{eq:EndPrd} (and the corresponding 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 methods used to the problem in subsequent sections of this document.
\end{comment}
% Local Variables:
% eval: (setq prettify-symbols-unprettify-at-point 'right-edge)
% End:
% coding: utf-8
\hypertarget{solving-the-next-to-last-period}{}
\hypertarget{solving-the-next}{}
\section{Solving the Next-to-Last Period}\label{sec:solving-the-next}
To reduce clutter, we now temporarily assume that $\PermGroFac_{\prd}=1$ for all $\prd$, so that the $\PermGroFac$ terms from the earlier derivations disappear, and setting $t=T$ the problem in the second-to-last period of life can now be expressed as
\begin{equation}\begin{gathered}\begin{aligned}
\vFunc_{\MidPrdLsT}(m) & = \max_{c} ~~ \uFunc(c) + \vEndPrdLsT(\overbrace{m-c}^{a})
\label{eq:vEndPrdTm1}
\end{aligned}\end{gathered}\end{equation}
where
\begin{equation*}\begin{gathered}\begin{aligned}
\vFunc_{\EndPrdLsT}(a) & \leftassign \DiscFac \vFunc_{\BegPrd}(a)
\equiv \DiscFac \Ex_{\BegPrd} \left[\PermGroFacAdjV \vFunc_{\MidPrd}(\underbrace{a \RNrmByG_{\prdT} + \tranShkEmp_{\prdT}}_{{m}_{\prdT}})\right]
\end{aligned}\end{gathered}\end{equation*}
% \begin{equation*}\begin{gathered}\begin{aligned}
% \vFunc_{\prdLsT}(\mNrm) & = \max_{\cNrm} ~~ \uFunc(\cNrm)
% + \DiscFac \Ex_{\EndPrdLsT} \left[\PermGroFacAdjV \vFunc_{\MidPrd}(\underbrace{(\mNrm-\cNrm)\RNrmByG_{\prdT} + \tranShkEmp_{\prdT}}_{{m}_{\prdT}})\right].
% \end{aligned}\end{gathered}\end{equation*}
Using (0) $\prd=\trmT$; (1) $\vFunc_{\prdT}(m)=\uFunc(m)$; (2) the definition of $\uFunc(m)$; and (3) the definition of the expectations operator, %\newcommand{\tranShkEmpDummy}{\vartheta}
\begin{equation}\begin{gathered}\begin{aligned}
\vFunc_{\BegPrd}(a) & = \PermGroFacAdjV\int_{0}^{\infty} \frac{\left(a \RNrmByG_{\prd}+ \tranShkEmpDummy\right)^{1-\CRRA}}{1-\CRRA} d\FDist(\tranShkEmpDummy) \label{eq:NumDefInt}
\end{aligned}\end{gathered}\end{equation}
where $\FDist(\tranShkEmp)$ is the cumulative distribution function for ${\tranShkEmp}$.
\ifcode{
\lstinputlisting{./Code/Python/snippets/rawsolution.py}
}{}
This maximization problem implicitly defines a `local function' $\cFunc_{\prdT-1}(m)$ that yields optimal consumption in period $\prdt-1$ for any specific numerical level of resources like $m=1.7$.% (When we need to use this function from some context outside of the local context in which it was solved, we can reference by its absolute index, $\cFunc_{\prdT-1}$).
But because there is no general analytical solution to this problem, for any given $m$ we must use numerical computational tools to find the $c$ that maximizes the expression. This is excruciatingly slow because for every potential $c$ to be considered, a definite integral over the interval $(0,\infty)$ must be calculated numerically, and numerical integration is \textit{very} slow (especially over an unbounded domain!).
\hypertarget{discretizing-the-distribution}{}
\subsection{Discretizing the Distribution}
Our first speedup 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 over $\tranShkEmp$ of a function $g(\tranShkEmp)$ by calculating its value at set of $n_{\tranShkEmp}$ points $\tranShkEmp_{i}$, each of which has an associated probability weight $w_{i}$:
\begin{equation*}\begin{gathered}\begin{aligned}
\Ex[g(\tranShkEmp)] & = \int_{\Min{\tranShkEmp}}^{\Max{\tranShkEmp}}(\tranShkEmpDummy)d\FDist(\tranShkEmpDummy) \\
& \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 we choose the one which is 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}
and when the integral is evaluated numerically for each $i$ the result is a set of values of $\tranShkEmp$ that correspond to the mean value in each of the $n$ intervals.
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.}
\hypertarget{discreteApprox}{}
\begin{figure}
\includegraphics[width=0.8\textwidth]{./Figures/discreteApprox}
\caption{Equiprobable Discrete Approximation to Lognormal Distribution $\FDist$}
\label{fig:discreteapprox}
\end{figure}
Because one of the purposes of these notes is to connect the math to the code that solves the math, we display here a brief snippet from the notebook that constructs these points.
\ifcode{
\lstinputlisting{./Code/Python/snippets/equiprobable-make.py}\nopagebreak
}{}
\begin{equation}\begin{gathered}\begin{aligned}
\vFunc_{{\prdLst}_\cntn}(a) & = \DiscFac \PermGroFacAdjV\left(\frac{1}{n_{\tranShkEmp}}\right)\sum_{i=1}^{n_{\tranShkEmp}} \frac{\left(\RNrmByG_{\prd} a + \tranShkEmp_{i}\right)^{1-\CRRA}}{1-\CRRA} \label{eq:vDiscrete}
\end{aligned}\end{gathered}\end{equation}
We now substitute our approximation \eqref{eq:vDiscrete} for $\vEndPrdLsT(a)$ in \eqref{eq:vEndPrdTm1} which is simply the sum of $n_{\tranShkEmp}$ numbers and is therefore easy to calculate (compared to the full-fledged numerical integration \eqref{eq:NumDefInt} that it replaces).
% so we can rewrite the maximization problem that defines the middle step of period {$\prdLst$} as
% \begin{equation}\begin{gathered}\begin{aligned}
% \vFunc_{\MidPrdLsT}(\mNrm) & = \max_{\cNrm}
% \left\{
% \frac{\cNrm^{1-\CRRA}}{1-\CRRA} +
% \vFunc_{\MidPrd}(\mNrm-\cNrm)
% \right\}.
% \label{eq:vEndPrdTm1}
% \end{aligned}\end{gathered}\end{equation}
\ifcode{
\lstinputlisting{./Code/Python/snippets/equiprobable-max-using.py}
}{}
\begin{comment}
In the {\SMDSOPntbk} notebook, the section ``Discretization of the Income Shock Distribution'' provides code that instantiates the \texttt{DiscreteApproximation} class defined in the \texttt{resources} module. This class creates a 7-point 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$.
A close look at the \texttt{DiscreteApproximation} class and its subclasses should convince you that the code is simply 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 depicted in \ref{fig:discreteapprox}.
\end{comment}
\hypertarget{the-approximate-consumption-and-value-functions}{}
\subsection{The Approximate Consumption and Value Functions}
Given any particular value of $m$, a numerical maximization tool can now find the $c$ that solves \eqref{eq:vEndPrdTm1} in a reasonable amount of time.
\begin{comment}
% The {\SMDSOPntbk} 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.'')
% After defining the utility function, the `natural borrowing constraint' is defined as $\Min{\aNrm}_{\prdT-1}=-\Min{\tranShkEmp}\RNrmByG_{\prdT}^{-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 prior lines of code; this is required to provide the numerical solution.
\end{comment}
The notebook code responsible for computing an estimated consumption function begins in ``Solving the Model by Value Function Maximization,'' where a vector containing a set of possible values of market resources $m$ is created (in the code, various $m$ vectors have names beginning {\mVec}; in these notes we will use {\vctrNotationDescribe} to represent vectors, so for example we can refer to our collection of $m$ points as $\vctr{m}$ with values indexed by brackets: $\vctr{m}[1]$ is the first entry in the vector, up to a last entry $\vctr{m}[-1]$; we arbitrarily (and suboptimally) pick the first five integers as our five {\mVec} gridpoints (in the code, \code{mVec\_int}= $\{0.,1.,2.,3.,4.\}$)).
% Finally, the previously computed values of optimal $\cNrm$ and the grid of market resources are combined to generate a graph of the approximated consumption function for this specific instance of the problem. To reduce the computational challenge of solving the problem, the process is evaluated only at a small number of gridpoints.
\hypertarget{an-interpolated-consumption-function}{}
\subsection{An Interpolated Consumption Function} \label{subsec:LinInterp}
This is accomplished in ``An Interpolated Consumption Function,'' which generates an interpolating function that we designate $\Aprx{\cFunc}_{\MidPrdLsT}(m)$. %When called with an $\mNrm$ that is equal to one of the points in $\code{{{\mVec}\_int}}$, $\Aprx{\cFunc}_{\prdT-1}$ returns the associated value of $\vctr{c}_{\code{\prdT-1}}$, and when called with a value of $\mNrm$ that is not exactly equal to one of the \texttt{mVec\_int}, returns the value of $\cNrm$ that reflects a linear interpolation between the $\vctr{c}_{\code{\prdT-1}}$ points associated with the two \texttt{mVec\_int} points immediately above and below $\mNrm$.
Figures \ref{fig:PlotcTm1Simple} and~\ref{fig:PlotVTm1Simple} show
plots of the constructed $\Aprx{\cFunc}_{\prdT-1}$ and $\Aprx{\vFunc}_{\prdT-1}$. While the $\Aprx{\cFunc}_{\prdT-1}$ function looks very smooth, the fact that the $\Aprx{\vFunc}_{\prdT-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_{\trmT-1}(m)$ (solid) versus $\Aprx{\cFunc}_{\trmT-1}(m)$ (dashed)}
\label{fig:PlotcTm1Simple}
\end{figure}
\hypertarget{PlotvTm1Simple}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/PlotVTm1Simple}}
\caption{$\vFunc_{\trmT-1}$ (solid) versus $\Aprx{\vFunc}_{\trmT-1}(m)$ (dashed)}
\label{fig:PlotVTm1Simple}
\end{figure}
\hypertarget{interpolating-expectations}{}
\subsection{Interpolating Expectations}
Piecewise linear `spline' interpolation as described above works well for generating a good approximation to the true optimal consumption function. However, there is a clear inefficiency in the program: Since it uses equation \eqref{eq:vEndPrdTm1}, for every value of $m$ the program must calculate the utility consequences of various possible choices of $c$ (and therefore $a_{\prdT-1}$) as it searches for the best choice.
For any given index $j$ in $\vctr{m}[j]$, as it searches for the corresponding optimal $a$, the algorithm will end up calculating $\vFunc_{\EndPrdLsT}(\tilde{a})$ for many $\tilde{a}$ values close to the optimal $a_{\prdT-1}$. Indeed, even when searching for the optimal $a$ for a \emph{different} $m$ (say $\vctr{m}[k]$ for $k \neq j$) the search process might compute $\vFunc_{\EndPrdLsT}(a)$ for an $a$ close to the correct optimal $a$ for $\vctr{m}[j]$. But if that difficult computation does not correspond to the exact solution to the $\vctr{m}[k]$ problem, it is discarded.
% (These lists contain the points of the $\vctr{\aNrm}_{\prdT-1}$ and $\vctr{v}_{\prdT-1}$ vectors, respectively.)
The notebook section ``Interpolating Expectations,'' now interpolates 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 with the remaining lines of code.
Figure~\ref{fig:PlotOTm1RawVSInt} compares the true value function to the approximation produced by following the interpolation procedure; the approximated and exact functions are of course identical at the gridpoints of $\vctr{a}$ and they appear reasonably close except in the region below $m=1$.
\hypertarget{PlotOTm1RawVSInt}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/PlotOTm1RawVSInt}}
\caption{End-Of-Period Value $\vFunc_{(\prdT-1)_\cntn}(a_{\prdT-1})$ (solid) versus $\Aprx{\vFunc}_{({\trmT-1})_\cntn}(a_{\trmT-1})$ (dashed)}
\label{fig:PlotOTm1RawVSInt}
\end{figure}
\hypertarget{PlotComparecTm1AB}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/PlotComparecTm1AB}}
\caption{$\cFunc_{\trmT-1}(m)$ (solid) versus $\Aprx{\cFunc}_{\trmT-1}(m)$ (dashed)}
\label{fig:PlotComparecTm1AB}
\end{figure}
\Fix{\marginpar{\tiny In all figs, replace gothic h with notation corresponding to the lecture notes.}}{}
Nevertheless, the consumption rule obtained when the approximating $\Aprx{\vFunc}_{(\prdT-1)_\cntn}(a_{\prdT-1})$ is used instead of $\vFunc_{(\prdT-1)_\cntn}(a_{\prdT-1})$ is surprisingly bad, as shown in figure \ref{fig:PlotComparecTm1AB}. For example, when $m$ goes from 2 to 3, $\Aprx{\cFunc}_{\prdT-1}$ goes from about 1 to about 2, yet when $m$ goes from 3 to 4, $\Aprx c$ goes from about 2 to about 2.05. The function fails even to be 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 one.
\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
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' which is assumed always to exceed feasible $c$). 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 $\trmT-1$ is:
\begin{equation}\begin{gathered}\begin{aligned}
\uFunc^{c}(c) & = \DiscFac \Ex_{\cntn(T-1)} [\PermGroFacAdjMu\Rfree \uFunc^{c}(c_{\prdT})] %\label{eq:focraw}
\\ c^{-\CRRA} & = \Rfree \DiscFac \left(\frac{1}{n_{\tranShkEmp}}\right) \sum_{i=1}^{n_{\tranShkEmp}} \PermGroFacAdjMu\left(\Rfree (m-c) + \tranShkEmp_{i}\right)^{-\CRRA} \label{eq:FOCTm1}.
\end{aligned}\end{gathered}\end{equation}
\hypertarget{PlotuPrimeVSOPrime}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/PlotuPrimeVSOPrime}}
\caption{$\uFunc^{c}(c)$ versus $\vFunc_{({\trmT-1})_\cntn}^{a}(3-c), \vFunc_{({\trmT-1})_\cntn}^{a}(4-c), \Aprx{\vFunc}_{({\trmT-1})_\cntn}^{a}(3-c), \Aprx{\vFunc}_{({\trmT-1})_\cntn}^{a}(4-c)$}
\label{fig:PlotuPrimeVSOPrime}
\end{figure}
The downward-sloping curve in Figure \ref{fig:PlotuPrimeVSOPrime}
shows the value of $c^{-\CRRA}$ for our baseline parameter values
for $0 \leq c \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$ under the assumption that $m=3$.
Constructing this figure is time-consuming, because for every
value of $c$ plotted we must calculate the RHS of
(\ref{eq:FOCTm1}). The value of $c$ for which the RHS and LHS
of (\ref{eq:FOCTm1}) are equal is the optimal level of consumption
given that $m=3$, so the intersection of the downward-sloping
and the upward-sloping curves gives the (approximated) optimal value of $c$.
As we can see, the two curves intersect just below $c=2$.
Similarly, the upward-sloping dashed curve shows the expected value
of the RHS of (\ref{eq:FOCTm1}) under the assumption that $m=4$,
and the intersection of this curve with $\uFunc^{c}(c)$ yields the
optimal level of consumption if $m=4$. These two curves
intersect slightly below $c=2.5$. Thus, increasing $m$
from 3 to 4 increases optimal consumption by about 0.5.
Now consider the derivative of our function $\Aprx{\vFunc}_{(\prdT-1)}(a_{\prdT-1})$. Because we have
constructed $\Aprx{\vFunc}_{(\prdT-1)}$ as a linear interpolation, the slope of
$\Aprx{\vFunc}_{(\prdT-1)}(a_{\prdT-1})$ between any two adjacent points
$\{\vctr{a}[i],\vctr{a}[{i+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 $\Aprx{\vFunc}_{(\prdT-1)_\cntn}(a_{\prdT-1})$ follows a step function.
The solid-line step function in Figure \ref{fig:PlotuPrimeVSOPrime} depicts the actual value of
$\Aprx{\vFunc}_{(\prdT-1)_\cntn}^{a}(3-c)$. When we attempt to find optimal values of
$c$ given $m$ using $\Aprx{\vFunc}_{(\prdT-1)_\cntn}(a_{\prdT-1})$, the numerical optimization routine will
return the $c$ for which
$\uFunc^{c}(c) = \Aprx{\vFunc}^{a}_{(\prdT-1)_\cntn}(m-c)$. Thus, for
$m=3$ the program will return the value of $c$ for which the downward-sloping
$\uFunc^{c}(c)$ curve intersects with the
$\Aprx{\vFunc}_{(\prdT-1)_\cntn}^{a}(3-c)$; as the diagram shows, this value is exactly equal to 2.
Similarly, if we ask the routine to find the optimal $c$ for $m=4$, it finds the point of
intersection of $\uFunc^{c}(c)$ with $\Aprx{\vFunc}_{(\prdT-1)_\cntn}^{a}(4-c)$; 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=2$ for both $m=3$ and $m=4$.
We would obviously obtain much better estimates of the point of intersection between $\uFunc^{c}(c)$ and $\vFunc_{(\prdT-1)_\cntn}^{a}(m-c)$ if our estimate of $\Aprx{\vFunc}^{a}_{(\prdT-1)_\cntn}$ 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} at the points in $\vctr{a}$:
\begin{equation}\begin{gathered}\begin{aligned}
\vFunc_{(\prdT-1)_\cntn}^{a}(\vctr{a}) & = \DiscFac \Rfree \PermGroFacAdjMu \left(\frac{1}{n_{\tranShkEmp}}\right) \sum_{i=1}^{n_{\tranShkEmp}} \left(\RNrmByG_{\prdT} \vctr{a} + \tranShkEmp_{i}\right)^{-\CRRA} \label{eq:vEndPrimeTm1}
\end{aligned}\end{gathered}\end{equation}
yielding $\vctr{v}{^{a}_{(\prdT-1)_\cntn}}$ (the vector of expected end-of-period-$(T-1)$ marginal values of assets corresponding to \code{aVec}), %$\{\{\vctr{\aNrm}}\code{_{\prdT-1}},\vFunc_{(\prdT-1)_\cntn}^{\aNrm}(\vctr{{\aNrm}[1]}_{\prdT-1}\},\{\vctr{\aNrm}_{(T-1)},\vFunc_{(\prdT-1)_\cntn}^{\aNrm}\}\ldots\}$
and construct
$\Aprx{\vFunc}_{(\prdT-1)_\cntn}^{a}(a_{\prdT-1})$ as the linear
interpolating function that fits this set of points.
\hypertarget{PlotOPRawVSFOC}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/PlotOPRawVSFOC}}
\caption{$\vFunc_{(\prdT-1)_\cntn}^{a}(a_{\prdT-1})$ versus $\Aprx{\vFunc}_{(\prdT-1)_\cntn}^{a}(a_{\prdT-1})$}
\label{fig:PlotOPRawVSFOC}
\end{figure}
% This is done by making a call to the \texttt{InterpolatedUnivariateSpline} function, passing it \code{aVec} and \texttt{vpVec} as arguments. Note that in defining the list of values \texttt{vpVec}, we again make 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_{\prdT-1}(m)$ (solid) Versus Two Methods for Constructing $\Aprx{\cFunc}_{\prdT-1}(m)$}
\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_{(\prdT-1)_\cntn}^{a}$ 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 $\RNrmByG_{\prdT} = \DiscFac = \PermGroFac_{\prdT} = 1$ and there is no uncertainty (that is, we know for sure that income next period will be $\tranShkEmp_{\prdT} = 1$). The final Euler equation (recall that we are still assuming that $\prd=\trmT$) is then:
\begin{equation}\begin{gathered}\begin{aligned}
c_{\prdT-1}^{-\CRRA} & = c_{\prdT}^{-\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 $\prdT$ or the current period $\prdT-1$; there is perfect certainty that the income will be received, so the consumer treats its PDV as equivalent to a unit of current wealth. Total resources available at the point when the consumption decision is made is therefore comprised of two types: current market resources $m$ and `human wealth' (the PDV of future income) of $h_{\prdT-1}=1$ (because it is the value of human wealth as of the end of the period, there is only one more period of income of 1 left).
\begin{equation}
\vFunc^{m}_{\MidPrdLsT}(m) = \left(\frac{m+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}
% \vInv^{m}_{\prdT-1}(\mNrm) \equiv
\left[\vFunc^{m}_{\MidPrdLsT}(m)\right]^{-1/\CRRA} & = \frac{m+1}{2} .
\end{aligned}\end{gathered}\end{equation}
This is a specific example of a general phenomenon: A theoretical literature discussed in~\cite{ckConcavity} establishes that under perfect certainty, if the period-by-period marginal utility function is of the form $c_{\prd}^{-\CRRA}$, the marginal value function will be of the form $(\gamma m_{\prd}+\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 the key insight in intuitive terms, the nonlinearity we are facing springs in large part from the fact 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}_{\MidPrdLsT}(a)$, we can define an `inverse marginal value' function
\begin{equation}\begin{gathered}\begin{aligned}
\vInv_{\prd_\cntn}^{a}(a) & \equiv \left(\vFunc^{a}_{\prd_\cntn}(a)\right)^{-1/\CRRA} \label{eq:cGoth}
\end{aligned}\end{gathered}\end{equation}
which would be linear in the perfect foresight case.\footnote{There is a corresponding inverse for the value function: $\vInv_{\prd_\cntn}(a_{\prd})=((1-\CRRA)\vFunc_{\prd_\cntn})^{1/(1-\CRRA)}$, and for the marginal marginal value function etc.} We then construct a piecewise-linear interpolating approximation to the $\vInv_{\prd}^{a}$ function, $\Aprx{\vInv}_{\prd_\cntn}^{a}(a_{\prd})$, and for any $a$ that falls in the range $\{\vctr{a}[1],\vctr{a}[-1]\}$ we obtain our approximation of marginal value from:
\begin{equation}\begin{gathered}\begin{aligned}
\Aprx{\vFunc}_{\prd}^{a}(a) & =
[\Aprx{\vInv}_{\prd}^{a}(a)]^{-\CRRA}
\end{aligned}\end{gathered}\end{equation}
The most interesting thing about all of this, though, is that the $\vInv^{a}_{\prd}$ function has another interpretation. Recall our point in \eqref{eq:upEqbetaOp} that $\uFunc^{c}(c_{\prd}) = \vEndStg^{a}(m_{\prd}-c_{\prd})$. Since with CRRA utility $\uFunc^{c}(c)=c^{-\CRRA}$, this can be rewritten
and inverted
\begin{equation}\begin{gathered}\begin{aligned}
(c_{\prd})^{-\CRRA} & = \vEndStg^{a}(a_{\prd})
\\ c_{\prd} & = \left(\vEndPrd^{a}(a)\right)^{-1/\CRRA}.
\end{aligned}\end{gathered}\end{equation}
What this means is that for any given $a$, if we can calculate the marginal value associated with ending the period with that $a$, then we can learn the level of $c$ that the consumer must have chosen if they ended up with that $a$ as the result of an optimal unconstrained choice. This leads us to an alternative interpretation of $\vInv^{a}$. It is the function that reveals, for any ending $a$, how much the agent must have consumed to (optimally) get to that $a$. We will therefore henceforth refer to it as the `consumed function:'
\begin{equation}\begin{gathered}\begin{aligned}
\Aprx{\cFunc}_{\prd_\cntn}(a_{\prd}) & \equiv \Aprx{\vInv}^{a}_{\prd_\cntn}(a_{\prd}) \label{eq:consumedfn}.
\end{aligned}\end{gathered}\end{equation}
%\renewcommand{\prd}{T}
Thus, for example, for period $\prdLsT$ our procedure is to calculate the vector of $\vctr{c}$ points on the consumed function:
\begin{equation}\begin{gathered}\begin{aligned}
\vctr{c} & = \cFunc_{(\prdLsT)_\cntn}(\vctr{a}) \label{eq:consumedfnvecs}
\end{aligned}\end{gathered}\end{equation}
with the idea that we will construct an approximation of the consumed function $\Aprx{\cFunc}_{(\prdLsT)_\cntn}(a)$ as the interpolating function connecting these $\{\vctr{a},\vctr{c}\}$ points.
\hypertarget{the-natural-borrowing-constraint-and-the-a-lower-bound}{}
\subsection{The Natural Borrowing Constraint and the $a_{\prdLsT}$ Lower Bound} \label{subsec:LiqConstrSelfImposed}
%\renewcommand{\prd}{T}
This is the appropriate moment to ask an awkward question: How should an interpolated, approximated `consumed' function like $\Aprx{\cFunc}_{(\prdLsT)_\cntn}(a_{\prdLsT})$ be extrapolated to return an estimated `consumed' amount when evaluated at an $a_{\prdLsT}$ outside the range spanned by $\{\vctr{a}[1],...,\vctr{a}[n]\}$?
For most canned piecewise-linear interpolation tools like \href{https://docs.scipy.org/doc/scipy/tutorial/interpolate.html}{scipy.interpolate}, when the `interpolating' function is evaluated at a point outside the provided range, the algorithm extrapolates under the assumption that the slope of the function remains constant beyond its measured boundaries (that is, the slope is assumed to be equal to the slope of nearest piecewise segment \emph{within} the interpolated range); for example, if the bottommost gridpoint is $\aVecMin = \vctratm[1]$ and the corresponding consumed level is $\cMin = \cFunc_{(\prdLsT)_\cntn}(a_1)$ we could calculate the `marginal propensity to have consumed' $\varkappa_{1}=
\Aprx{\cFunc}_{(\prdLsT)_\cntn}^{a}(\aVecMin)$ and construct the approximation as the linear extrapolation below $\vctratm[1]$ from:
\begin{equation}\begin{gathered}\begin{aligned}
\Aprx{\cFunc}_{(\prdLsT)_\cntn}(a) & \equiv \cMin + (a-\aVecMin)\varkappa_{1} \label{eq:ExtrapLin}.
\end{aligned}\end{gathered}\end{equation}
To see that this will lead us into difficulties, consider what happens to the true (not approximated) $\vFunc^{a}_{(\prdLsT)_\cntn}(a_{\prdLsT})$ as $a_{\prdLsT}$ approaches a quantity we will call the `natural borrowing constraint': $\NatBoroCnstra_{\prdLsT}=-\Min{\tranShkEmp}\RNrmByG_{\prdT}^{-1}$. From
\eqref{eq:vEndPrimeTm1} we have
\begin{equation}\begin{gathered}\begin{aligned}
\lim_{a \downarrow \NatBoroCnstra_{\prdLsT}} \vFunc^{a}_{(\prdLsT)_\cntn}(a)
& = \lim_{a \downarrow \NatBoroCnstra_{\prdLsT}} \DiscFac \Rfree \PermGroFacAdjMu \left(\frac{1}{n_{\tranShkEmp}}\right) \sum_{i=1}^{n_{\tranShkEmp}} \left( a \RNrmByG_{\prd}+ \tranShkEmp_{i}\right)^{-\CRRA}.
\end{aligned}\end{gathered}\end{equation}
But since $\Min{\tranShkEmp}=\tranShkEmp_{1}$, exactly at $a=\NatBoroCnstra_{\prdLsT}$ the first term in the summation would be $(-\Min{\tranShkEmp}+\tranShkEmp_{1})^{-\CRRA}=1/0^{\CRRA}$ which is infinity. The reason is simple: $-\NatBoroCnstra_{\prdLsT}$ is the PDV, as of $\prdLsT$, of the \emph{minimum possible realization of income} in $\prdT$ ($\RNrmByG_{\prdT}\NatBoroCnstra_{\prdLsT} = -\tranShkEmp_{1}$). Thus, if the consumer borrows an amount greater than or equal to $\Min{\tranShkEmp}\RNrmByG_{\prdT}^{-1}$ (that is, if the consumer ends $\prdLsT$ with $a_{\prdLsT} \leq -\Min{\tranShkEmp}\RNrmByG_{\prdT}^{-1}$) and then draws the worst possible income shock in period $\prdT$, they will have to consume zero in period $\prdT$, which yields $-\infty$ utility and $+\infty$ marginal utility.
As \cite{zeldesStochastic} first noticed, this means that the consumer faces a `self-imposed' (or, as above, `natural') borrowing constraint (which springs from the precautionary motive): They will never borrow an amount greater than or equal to $\Min{\tranShkEmp}\RNrmByG_{\prdT}^{-1}$ (that is, assets will never reach the lower bound of $\NatBoroCnstra_{\prdLsT}$). The constraint is `self-imposed' in the precise sense that if the utility function were different (say, Constant Absolute Risk Aversion), the consumer might be willing to borrow more than $\Min{\tranShkEmp}\RNrmByG_{\prdT}^{-1}$ because a choice of zero or negative consumption in period $\prdT$ 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.}
%\providecommand{\aMin}{\Min{\aNrm}}
This self-imposed constraint cannot be captured well when the $\vFunc^{a}_{(\prdLsT)_\cntn}$ function is approximated by a piecewise linear function like $\Aprx{\vFunc}^{m}_{(\prdLsT)_\cntn}$, because it is impossible for the linear extrapolation below $\aMin$ to correctly predict $\vFunc^{a}_{(\prdLsT)_\cntn}(\NatBoroCnstra_{\prdLsT})=\infty.$ %To see what will happen instead, note first that if we are approximating $\vFunc^{\aNrm}_{(\prdLsT)_\cntn}$ the smallest value in \code{aVec} must be greater than $\NatBoroCnstra_{\prdLsT}$ (because the expectation for any $a_{\prdLsT} \leq \NatBoroCnstra_{\prdLsT}$ is undefined).
% When the approximating $\vFunc^{\aNrm}_{(\prdLsT)_\cntn}$ function is evaluated at some value less than the first element in \code{aVec}, a piecewise linear approximating function will linearly extrapolate the slope that characterized the lowest segment of the piecewise linear approximation (between \texttt{aVec[1]} and \texttt{aVec[2]}), a procedure that will return a positive finite number, even if the requested $a_{\prdLsT}$ point is below $\NatBoroCnstra_{\prdLsT}$. 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 $\NatBoroCnstra_{\prdLsT}$.
%\renewcommand{\prd}{T}
So, the marginal value of saving approaches infinity as $a \downarrow \NatBoroCnstra_{\prdLsT}=-\Min{\tranShkEmp}\RNrmByG_{\prdT}^{-1}$. But this implies that $\lim_{a \downarrow \NatBoroCnstra_{\prdLsT}} \cFunc_{(\prdLsT)_\cntn}(a) = (\vFunc^{a}_{(\prdLsT)_\cntn}(a))^{-1/\CRRA} = 0$; that is, as $a$ approaches its `natural borrowing constraint' minimum possible value, the corresponding amount of worst-case $c$ must approach \textit{its} lower bound: zero.
The upshot is a realization that all we need to do to address these problems is to prepend each of the $\vctr{a}_{\code{\prdLsT}}$ and $\vctr{c}_{\code{\prdLsT}}$ from \eqref{eq:consumedfnvecs} with an extra point so that the first element in the mapping that produces our interpolation function is $\{\NatBoroCnstra_{\prdLsT},0.\}$. This is done in section ``The Self-Imposed `Natural' Borrowing Constraint and the $a_{\prdLsT}$ Lower Bound'' of the notebook.%which can be seen in the defined lists \texttt{aVecBot} and \texttt{cVec3Bot}.
\Fix{\marginpar{\tiny The vertical axis should be relabeled - not gothic c anymore, instead $\vInv^{a}$}}{}
\hypertarget{GothVInvVSGothC}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/GothVInvVSGothC}}
\caption{True $\vInv^{a}_{(\prdLsT)_\cntn}(a)$ vs its approximation $\Aprx{\vInv}^{a}_{(\prdLsT)_\cntn}(a)$}
\label{fig:GothVInvVSGothC}
\end{figure}
% \caption{True $\cFunc_{(\prdLsT)_\cntn}(\aNrm)$ vs its approximation $\Aprx{\cFunc}_{(\prdLsT)_\cntn}(\aNrm)$}
Figure \ref{fig:GothVInvVSGothC} shows the result. The solid line calculates the exact numerical value of the consumed function $\cFunc_{(\prdLsT)_\cntn}(a)$ while the dashed line is the linear interpolating approximation $\Aprx{\cFunc}_{(\prdLsT)_\cntn}(a).$ 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$.
Figure~\ref{fig:GothVVSGothCInv} similarly shows that when we generate $\Aprx{\Aprx{\vFunc}}_{(\prdLsT)_\cntn}^{a}(a)$ using our augmented $[\Aprx{\cFunc}_{(\prdLsT)_\cntn}(a)]^{-\CRRA}$ (dashed line) we obtain a \textit{much} closer approximation to the true marginal value function $\vFunc^{a}_{(\prdLsT)_\cntn}(a)$ (solid line) than we obtained in the previous exercise which did not do the transformation (Figure~\ref{fig:PlotOPRawVSFOC}).\footnote{The vertical axis label uses $\mathfrak{v}^{\prime}$ as an alternative notation for what in these notes we designate as $\vFunc^{a}_{\EndPrdLsT}$). This will be fixed.}
\Fix{\marginpar{\tiny fix the problem articulated in the footnote}}{}
\hypertarget{GothVVSGothCInv}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/GothVVSGothCInv}}
\caption{True $\vFunc^{a}_{(\prdLsT)_\cntn}(a)$ vs. $\Aprx{\Aprx{\vFunc}}_{(\prdLsT)_\cntn}^{a}(a)$ Constructed Using $\Aprx{\cFunc}_{(\prdLsT)_\cntn}(a)$}
\label{fig:GothVVSGothCInv}
\end{figure}
\hypertarget{the-method-of-endogenous-gridpoints}{}
\subsection{The Method of Endogenous Gridpoints (`EGM')}\label{subsec:egm}
The solution procedure above for finding $\cFunc_{\prdLsT}(m)$ still requires us, for each point in $\vctr{m}\code{_{\prdLsT}}$, to use a numerical rootfinding algorithm to search for the value of $c$ that solves $\uFunc^{c}(c) = \vFunc^{a}_{(\prdLsT)_\cntn}(m-c)$. Though sections \ref{subsec:transformation} and \ref{subsec:LiqConstrSelfImposed} developed a highly efficient and accurate procedure to calculate $\Aprx{\vFunc}^{a}_{(\prdLsT)_\cntn}$, those approximations do nothing to eliminate the need for using a rootfinding operation for calculating, for an arbitrary $m$, the optimal $c$. And rootfinding is a notoriously computation-intensive (that is, slow!) operation.
Fortunately, it turns out that there is a way to completely skip this slow rootfinding step. The method can be understood by noting that we have already calculated, for a set of arbitrary values of $\vctr{a}=\vctr{a}\code{_{\prdLsT}}$, the corresponding $\vctr{c}$ values for which this $\vctr{a}$ is optimal.
But with mutually consistent values of $\vctr{c}\code{_{\prdLsT}}$ and $\vctr{a}\code{_{\prdLsT}}$ (consistent, in the sense that they are the unique optimal values that correspond to the solution to the problem), we can obtain the $\vctr{m}\code{_{\prdLsT}}$ vector that corresponds to both of them from
\begin{equation}\begin{gathered}\begin{aligned}
\vctr{m}\code{_{\prdLsT}} & = {\vctr{c}\code{_{\prdLsT}}+\vctr{a}\code{_{\prdLsT}}}.
\end{aligned}\end{gathered}\end{equation}
\Fix{\marginpar{\tiny Rename gothic class to: EndPrd. Also, harmonize the notation in the notebook to that in the notes - for example, everwhere in the text we use cNrm=lower case letter c for normalized consumption, but for some reason it is capital C in the gothic function.}}{}
\Fix{\marginpar{\tiny fix the problem articulated in the footnote}}{}
These $m$ gridpoints are ``endogenous'' in contrast to the usual solution method of specifying some \textit{ex-ante} (exogenous) grid of values of $\vctr{m}$ and then using a rootfinding routine to locate the corresponding optimal consumption vector $\vctr{c}$.
This routine is performed in the ``Endogenous Gridpoints'' section of the notebook. First, the \texttt{gothic.C\_Tminus1} function is called for each of the pre-specfied values of end-of-period assets stored in \code{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 $\vctr{\cFunc}$ values in hand, the notebook can generate a set of $\vctr{m}\code{_{\prdLsT}}$ and ${\vctr{c}\code{_{\prdLsT}}}$ pairs that can be interpolated between in order to yield $\Aprx{\cFunc}_{\MidPrdLsT}(m)$ 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.
\hypertarget{PlotComparecTm1AD}{}
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).
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/PlotComparecTm1AD}}
\caption{$\cFunc_{\prdLsT}(m)$ (solid) versus $\Aprx{\cFunc}_{\prdLsT}(m)$ (dashed)}
\label{fig:ComparecTm1AD}
\end{figure}
Figure~\ref{fig:ComparecTm1AD} plots the actual consumption function $\cFunc_{\prdLsT}$ and the approximated consumption function $\Aprx{\cFunc}_{\prdLsT}$ derived by the method of endogenous grid points. Compared to the approximate consumption functions illustrated in Figure~\ref{fig:PlotcTm1ABC}, $\Aprx{\cFunc}_{\prdLsT}$ is quite close to the actual consumption function.
\hypertarget{improving-the-a-grid}{}
\subsection{Improving the $a$ Grid}\label{subsec:improving-the-a-grid}
Thus far, we have arbitrarily used $a$ gridpoints of $\{0.,1.,2.,3.,4.\}$ (augmented in the last subsection by $\NatBoroCnstra_{\prdLsT}$). But it has been obvious from the figures that the approximated $\Aprx{\cFunc}_{(\prdLsT)_\cntn}$ function tends to be farthest from its true value at low values of $a$. Combining this with our insight that $\NatBoroCnstra_{\prdLsT}$ is a lower bound, we are now in position to define a more deliberate method for constructing gridpoints for $a$ -- a method that yields values that are more densely spaced at low values of $a$ where the function is more nonlinear.
A pragmatic choice that works well is to find the values such that (1) the last value \textit{exceeds the lower bound} by the same amount $\bar a$ as our original maximum gridpoint (in our case, 4.); (2) we have the same number of gridpoints as before; and (3) the \textit{multi-exponential growth rate} (that is, $e^{e^{e^{...}}}$ for some number of exponentiations $n$ -- our default is 3) from each point to the next point is constant (instead of, as previously, imposing constancy of the absolute gap between points).
\hypertarget{GothVInvVSGothCEEE}{}
\begin{figure}
\centerline{\includegraphics[width=6in]{./Figures/GothVInvVSGothCEEE}}
\caption{$\cFunc_{(\prdLsT)_\cntn}(a)$ versus
$\Aprx{\cFunc}_{(\prdLsT)_\cntn}(a)$, Multi-Exponential \code{aVec}}
\label{fig:GothVInvVSGothCEE}
\end{figure}
\hypertarget{GothVVSGothCInvEEE}{}
\begin{figure}
\includegraphics[width=6in]{./Figures/GothVVSGothCInvEEE}
\caption{$\vFunc^{a}_{(\prdLsT)_\cntn}(a)$ vs.
$\Aprx{\Aprx{\vFunc}}_{(\prdLsT)_\cntn}^{a}(a)$, Multi-Exponential \code{aVec}}
\label{fig:GothVVSGothCInvEE}
\end{figure}
Section ``Improve the $\mathbb{a}_{grid}$'' begins by defining a function which takes as arguments the specifications of an initial grid of assets and returns the new grid incorporating the multi-exponential approach outlined above.
Notice that the graphs depicted in Figures~\ref{fig:GothVInvVSGothCEE} and \ref{fig:GothVVSGothCInvEE} are notably closer to their respective truths than the corresponding figures that used the original grid.
\subsection{Program Structure}
In section ``Solve for $c_t(m)$ in Multiple Periods,'' the natural and artificial borrowing constraints are combined with the endogenous gridpoints method to approximate the optimal consumption function for a specific period. Then, this function is used to compute the approximated consumption in the previous period, and this process is repeated for some specified number of periods.
The essential structure of the program is a loop that iteratively solves for consumption functions by working backward from an assumed final period, using the dictionary \texttt{cFunc\_life} to store the interpolated consumption functions up to the beginning period. Consumption in a given period is utilized to determine the endogenous gridpoints for the preceding period. This is the sense in which the computation of optimal consumption is done recursively.
For a realistic life cycle problem, it would also be necessary at a
minimum to calibrate a nonconstant path of expected income growth over the
lifetime that matches the empirical profile; allowing for such
a calibration is the reason we have included the $\{\PermGroFac\}_{\prd}^{T}$
vector in our computational specification of the problem.
\hypertarget{results}{}
\subsection{Results}
The code creates the relevant $\Aprx{\cFunc}_{\prd}(m)$ functions for any period in the horizon, at the given values of $m$. Figure \ref{fig:PlotCFuncsConverge} shows $\Aprx{\cFunc}_{T-n}(m)$ for $n=\{20,15,10,5,1\}$. At least one feature of this figure is encouraging: the consumption functions converge as the horizon extends, something that \cite{BufferStockTheory} shows must be true under certain parametric conditions that are satisfied by the baseline parameter values being used here.
\hypertarget{PlotCFuncsConverge}{}
\begin{figure}
\includegraphics[width=6in]{./Figures/PlotCFuncsConverge}
\caption{Converging $\Aprx{\cFunc}_{T-n}(m)$ Functions as $n$ Increases}
\label{fig:PlotCFuncsConverge}
\end{figure}
% %\MoM{\input{_sectn-method-of-moderation-input}}{}
\hypertarget{the-infinite-horizon}{}
\section{The Infinite Horizon}\label{sec:the-infinite-horizon}
All of the solution methods presented so far have involved period-by-period iteration from an assumed last period of life, as is appropriate for life cycle problems. However, if the parameter values for the problem satisfy certain conditions (detailed in \cite{BufferStockTheory}), the consumption rules (and the rest of the problem) will converge to a fixed rule as the horizon (remaining lifetime) gets large, as illustrated in Figure~\ref{fig:PlotCFuncsConverge}. Furthermore, Deaton~\citeyearpar{deatonLiqConstr}, Carroll~\citeyearpar{carroll:brookings,carrollBSLCPIH} and others have argued that the `buffer-stock' saving behavior that emerges under some further restrictions on parameter values is a good approximation of the behavior of typical consumers over much of the lifetime. Methods for finding the converged functions are therefore of interest, and are dealt with in this section.
Of course, the simplest such method is to solve the problem as
specified above for a large number of periods. This is feasible, but
there are much faster methods.
\hypertarget{convergence}{}
\subsection{Convergence}\label{subsec:convergence}
In solving an infinite-horizon problem, it is necessary to have some
metric that determines when to stop because a solution that is `good
enough' has been found.
A natural metric is defined by the unique `target' level of wealth that \cite{BufferStockTheory} proves
will exist in problems of this kind \href{https://llorracc.github.io/BufferStockTheory#GICNrm}{under certain conditions}: The $\mTrgNrm$ such that
\begin{equation}
\Ex_t [{m}_{\prd+1}/m_t] = 1 \mbox{~if~} m_t = \mTrgNrm \label{eq:mTrgNrmet}
\end{equation}
where the accent is meant to signify that this is the value
that other $m$'s `point to.'
Given a consumption rule $\cFunc(m)$ it is straightforward to find
the corresponding $\mTrgNrm$. So for our problem, a solution is declared
to have converged if the following criterion is met:
$\left|\mTrgNrm_{\prd+1}-\mTrgNrm_{\prd}\right| < \epsilon$, where $\epsilon$ is
a very small number and defines our degree of convergence tolerance.
Similar criteria can obviously be specified for other problems.
However, it is always wise to plot successive function differences and
to experiment a bit with convergence criteria to verify that the
function has converged for all practical purposes.
\begin{comment} % at suggestion of WW, this section was removed as unnecessary for the current model, which solves for the converged rule very fast
\subsection{The Last Period}
For the last period of a finite-horizon lifetime, in the absence of a
bequest motive it is obvious that the optimal policy is to spend
everything. However, in an infinite-horizon problem there is no last
period, and the policy of spending everything is obviously very far
from optimal. Generally speaking, it is much better to start off with
a `last-period' consumption rule and value function equal to those
corresponding to the infinite-horizon solution to the perfect
foresight problem (assuming such a solution is known).
For the perfect foresight infinite horizon consumption problem,
the solution is
\begin{equation}\begin{gathered}\begin{aligned}
\bar{\cFunc}(m_{\prd}) & = \overbrace{(1-\Rfree^{-1}(\Rfree
\DiscFac)^{1/\CRRA})}^{\equiv
\Min{\MPC}}\left[{m}_{\prd}-1+\left(\frac{1}{1-1/\Rfree}\right)\right]
\label{eq:pfinfhorc}
\end{aligned}\end{gathered}\end{equation}
where $\Min{\MPC}$ is the MPC in the
infinite-horizon perfect foresight problem. In our baseline problem,
we set $\PermGroFac = \pLvl_{\prd} = 1$. It is straightforward to show that the
infinite-horizon perfect-foresight value function and marginal value
function are given by
\begin{equation}\begin{gathered}\begin{aligned}
\bar{\vFunc}(m_{\prd})
& = \left(\frac{\bar{\cFunc}(m_{\prd})^{1-\CRRA}}{
(1-\CRRA)\Min{\MPC} }\right)
\\ \bar{\vFunc}^{m}(m_{\prd}) & = (\bar{\cFunc}(m_{\prd}))^{-\CRRA}
\\ \Opt{\vFunc}^{m}(a_{\prd}) & = \DiscFac \Rfree \PermGroFac_{\prd+1}^{-\CRRA} \bar{\vFunc}^{m}(\RNrmByG_{\prd+1} a_{\prd}+1).
\end{aligned}\end{gathered}\end{equation}
\end{comment}
\begin{comment}% At suggestion of WW this section was deleted because the technique is obvious and can be captured by the footnote that has been added
\subsection{Coarse Then Fine \code{aVec} }