From 9b593656673f9aa6ca6274c311a99c649485986c Mon Sep 17 00:00:00 2001 From: llorracc Date: Sat, 27 Feb 2021 18:35:17 -0500 Subject: [PATCH] script update of DemARKs to new ConsIndShockModel.py check_conditions etc --- ...ternative-Combos-Of-Parameter-Values.ipynb | 2 +- .../Alternative-Combos-Of-Parameter-Values.py | 2 +- notebooks/ChangeLiqConstr.ipynb | 6 +- notebooks/ChangeLiqConstr.md | 2 +- notebooks/ChangeLiqConstr.py | 6 +- notebooks/FisherTwoPeriod.ipynb | 2 +- notebooks/FisherTwoPeriod.py | 2 +- ...tle-Intro-To-HARK-Buffer-Stock-Model.ipynb | 58 +++++++++---------- ...Gentle-Intro-To-HARK-Buffer-Stock-Model.py | 10 ++-- ...ntle-Intro-To-HARK-PerfForesightCRRA.ipynb | 14 ++--- .../Gentle-Intro-To-HARK-PerfForesightCRRA.py | 57 +++++++++--------- notebooks/KeynesFriedmanModigliani.ipynb | 2 +- notebooks/KeynesFriedmanModigliani.py | 2 +- notebooks/LifeCycleModelTheoryVsData.ipynb | 6 +- notebooks/LifeCycleModelTheoryVsData.py | 4 +- ...C-Out-of-Credit-vs-MPC-Out-of-Income.ipynb | 8 +-- .../MPC-Out-of-Credit-vs-MPC-Out-of-Income.py | 8 +-- ...o-Implications-of-Very-Impatient-HHs.ipynb | 4 +- ...acro-Implications-of-Very-Impatient-HHs.py | 2 +- .../Nondurables-During-Great-Recession.ipynb | 4 +- .../Nondurables-During-Great-Recession.py | 4 +- .../PerfForesightCRRA-Approximation.ipynb | 2 +- notebooks/PerfForesightCRRA-Approximation.py | 2 +- notebooks/PerfForesightCRRA-SavingRate.ipynb | 2 +- notebooks/PerfForesightCRRA-SavingRate.py | 2 +- .../TractableBufferStock-Interactive.ipynb | 2 +- notebooks/TractableBufferStock-Interactive.py | 2 +- 27 files changed, 109 insertions(+), 108 deletions(-) diff --git a/notebooks/Alternative-Combos-Of-Parameter-Values.ipynb b/notebooks/Alternative-Combos-Of-Parameter-Values.ipynb index c9855538..0712ada4 100644 --- a/notebooks/Alternative-Combos-Of-Parameter-Values.ipynb +++ b/notebooks/Alternative-Combos-Of-Parameter-Values.ipynb @@ -60,7 +60,7 @@ "from copy import deepcopy\n", "\n", "import HARK # Prevents import error from Demos repo\n", - "from HARK.utilities import plotFuncs" + "from HARK.utilities import plot_funcs" ] }, { diff --git a/notebooks/Alternative-Combos-Of-Parameter-Values.py b/notebooks/Alternative-Combos-Of-Parameter-Values.py index a272ae6c..7a429216 100644 --- a/notebooks/Alternative-Combos-Of-Parameter-Values.py +++ b/notebooks/Alternative-Combos-Of-Parameter-Values.py @@ -91,7 +91,7 @@ from copy import deepcopy import HARK # Prevents import error from Demos repo -from HARK.utilities import plotFuncs +from HARK.utilities import plot_funcs # %% {"code_folding": [0, 4]} # Import IndShockConsumerType diff --git a/notebooks/ChangeLiqConstr.ipynb b/notebooks/ChangeLiqConstr.ipynb index 8d142362..e14f1af0 100644 --- a/notebooks/ChangeLiqConstr.ipynb +++ b/notebooks/ChangeLiqConstr.ipynb @@ -27,7 +27,7 @@ "source": [ "from copy import deepcopy\n", "from HARK.ConsumptionSaving.ConsIndShockModel import KinkedRconsumerType\n", - "from HARK.utilities import plotFuncsDer, plotFuncs\n", + "from HARK.utilities import plot_funcs_der, plot_funcs\n", "mystr = lambda number : \"{:.4f}\".format(number)\n", "\n", "import matplotlib.pyplot as plt" @@ -67,7 +67,7 @@ "# Plot the results \n", "plt.ylabel('Consumption c')\n", "plt.xlabel('Market Resources m')\n", - "plotFuncs([KinkyExample.solution[0].cFunc],KinkyExample.solution[0].mNrmMin,5)" + "plot_funcs([KinkyExample.solution[0].cFunc],KinkyExample.solution[0].mNrmMin,5)" ] }, { @@ -121,7 +121,7 @@ "KinkyExampleTighten.solve()\n", "\n", "# Compare the two functions\n", - "plotFuncs([KinkyExample.solution[0].cFunc,KinkyExampleTighten.solution[0].cFunc],KinkyExampleTighten.solution[0].mNrmMin,5)" + "plot_funcs([KinkyExample.solution[0].cFunc,KinkyExampleTighten.solution[0].cFunc],KinkyExampleTighten.solution[0].mNrmMin,5)" ] }, { diff --git a/notebooks/ChangeLiqConstr.md b/notebooks/ChangeLiqConstr.md index 0d47cd0d..4d5c0343 100644 --- a/notebooks/ChangeLiqConstr.md +++ b/notebooks/ChangeLiqConstr.md @@ -18,4 +18,4 @@ notebooks: dashboards: --- -What Happens To the Consumption Function When A Liquidity Constraint is Tightened? \ No newline at end of file +What Happens To the Consumption Function When A Liquidity Constraint is Tightened? diff --git a/notebooks/ChangeLiqConstr.py b/notebooks/ChangeLiqConstr.py index 0767a0a8..b9deca50 100644 --- a/notebooks/ChangeLiqConstr.py +++ b/notebooks/ChangeLiqConstr.py @@ -39,7 +39,7 @@ # + {"code_folding": [0]} from copy import deepcopy from HARK.ConsumptionSaving.ConsIndShockModel import KinkedRconsumerType -from HARK.utilities import plotFuncsDer, plotFuncs +from HARK.utilities import plot_funcs_der, plot_funcs mystr = lambda number : "{:.4f}".format(number) import matplotlib.pyplot as plt @@ -60,7 +60,7 @@ # Plot the results plt.ylabel('Consumption c') plt.xlabel('Market Resources m') -plotFuncs([KinkyExample.solution[0].cFunc],KinkyExample.solution[0].mNrmMin,5) +plot_funcs([KinkyExample.solution[0].cFunc],KinkyExample.solution[0].mNrmMin,5) # - # 'Market Resources' $M$ is the total amount of money (assets plus current income) available to the consumer when the consumption decision is made. Lower case $m = M/P$ is the ratio of $M$ to permanent income. Likewise, $c = C/P$ is the ratio of consumption to permanent income. @@ -87,7 +87,7 @@ KinkyExampleTighten.solve() # Compare the two functions -plotFuncs([KinkyExample.solution[0].cFunc,KinkyExampleTighten.solution[0].cFunc],KinkyExampleTighten.solution[0].mNrmMin,5) +plot_funcs([KinkyExample.solution[0].cFunc,KinkyExampleTighten.solution[0].cFunc],KinkyExampleTighten.solution[0].mNrmMin,5) # - # ### Discussion diff --git a/notebooks/FisherTwoPeriod.ipynb b/notebooks/FisherTwoPeriod.ipynb index 5477887c..6de7a50f 100644 --- a/notebooks/FisherTwoPeriod.ipynb +++ b/notebooks/FisherTwoPeriod.ipynb @@ -23,7 +23,7 @@ "import numpy as np\n", "\n", "from HARK.ConsumptionSaving.ConsIndShockModel import PerfForesightConsumerType\n", - "from HARK.utilities import plotFuncsDer, plotFuncs\n", + "from HARK.utilities import plot_funcs_der, plot_funcs\n", "mystr = lambda number : \"{:.3f}\".format(number)\n", "\n", "from ipywidgets import interact, interactive, fixed, interact_manual\n", diff --git a/notebooks/FisherTwoPeriod.py b/notebooks/FisherTwoPeriod.py index 006cfbcb..92c4084f 100644 --- a/notebooks/FisherTwoPeriod.py +++ b/notebooks/FisherTwoPeriod.py @@ -54,7 +54,7 @@ import numpy as np from HARK.ConsumptionSaving.ConsIndShockModel import PerfForesightConsumerType -from HARK.utilities import plotFuncsDer, plotFuncs +from HARK.utilities import plot_funcs_der, plot_funcs mystr = lambda number : "{:.3f}".format(number) from ipywidgets import interact, interactive, fixed, interact_manual diff --git a/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.ipynb b/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.ipynb index 2239a708..3f42f473 100644 --- a/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.ipynb +++ b/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.ipynb @@ -30,7 +30,7 @@ "import HARK \n", "from copy import deepcopy\n", "mystr = lambda number : \"{:.4f}\".format(number)\n", - "from HARK.utilities import plotFuncs" + "from HARK.utilities import plot_funcs" ] }, { @@ -192,13 +192,13 @@ " 'addToTimeVary',\n", " 'assignParameters',\n", " 'cFunc_terminal_',\n", - " 'checkAIC',\n", - " 'checkCondition',\n", - " 'checkConditions',\n", + " 'check_AIC',\n", + " 'check_condition',\n", + " 'check_conditions',\n", " 'checkElementsOfTimeVaryAreLists',\n", - " 'checkFHWC',\n", - " 'checkGICPF',\n", - " 'checkRIC',\n", + " 'check_FHWC',\n", + " 'check_GIC',\n", + " 'check_RIC',\n", " 'checkRestrictions',\n", " 'clearHistory',\n", " 'cycles',\n", @@ -557,16 +557,16 @@ "name": "stderr", "output_type": "stream", "text": [ - "GPFPF = 0.984539 \n", - "GPFInd = 0.993777 \n", - "GPFAgg = 0.964848 \n", + "GPFRaw = 0.984539 \n", + "GPFNrm = 0.993777 \n", + "GPFAggLivPrb = 0.964848 \n", "Thorn = APF = 0.994384 \n", "PermGroFacAdj = 1.000611 \n", "uInvEpShkuInv = 0.990704 \n", - "FVAF = 0.932054 \n", + "VAF = 0.932054 \n", "WRPF = 0.213705 \n", - "DiscFacGPFIndMax = 0.972061 \n", - "DiscFacGPFAggMax = 1.010600 \n" + "DiscFacGPFNrmMax = 0.972061 \n", + "DiscFacGPFAggLivPrbMax = 1.010600 \n" ] }, { @@ -713,8 +713,8 @@ } ], "source": [ - "# plotFuncs([list],min,max) takes a [list] of functions and plots their values over a range from min to max\n", - "plotFuncs([IndShockExample.solution[0].cFunc,IndShockExample.solution_terminal.cFunc],0.,10.)" + "# plot_funcs([list],min,max) takes a [list] of functions and plots their values over a range from min to max\n", + "plot_funcs([IndShockExample.solution[0].cFunc,IndShockExample.solution_terminal.cFunc],0.,10.)" ] }, { @@ -739,16 +739,16 @@ "name": "stderr", "output_type": "stream", "text": [ - "GPFPF = 0.984539 \n", - "GPFInd = 1.021965 \n", - "GPFAgg = 0.964848 \n", + "GPFRaw = 0.984539 \n", + "GPFNrm = 1.021965 \n", + "GPFAggLivPrb = 0.964848 \n", "Thorn = APF = 0.994384 \n", "PermGroFacAdj = 0.973012 \n", "uInvEpShkuInv = 0.963379 \n", - "FVAF = 0.906347 \n", + "VAF = 0.906347 \n", "WRPF = 0.213705 \n", - "DiscFacGPFIndMax = 0.919178 \n", - "DiscFacGPFAggMax = 1.010600 \n" + "DiscFacGPFNrmMax = 0.919178 \n", + "DiscFacGPFAggLivPrbMax = 1.010600 \n" ] } ], @@ -790,7 +790,7 @@ "\n", "Perhaps the most interesting such condition is the [\"Growth Impatience Condition\"](http://econ.jhu.edu/people/ccarroll/Papers/BufferStockTheory/#GIC): If this condition is satisfied, the consumer's optimal behavior is to aim to achieve a \"target\" value of $m$, to serve as a precautionary buffer against income shocks.\n", "\n", - "The tests can be invoked using the `checkConditions()` method:" + "The tests can be invoked using the `check_conditions()` method:" ] }, { @@ -802,21 +802,21 @@ "name": "stderr", "output_type": "stream", "text": [ - "GPFPF = 0.984539 \n", - "GPFInd = 0.993777 \n", - "GPFAgg = 0.964848 \n", + "GPFRaw = 0.984539 \n", + "GPFNrm = 0.993777 \n", + "GPFAggLivPrb = 0.964848 \n", "Thorn = APF = 0.994384 \n", "PermGroFacAdj = 1.000611 \n", "uInvEpShkuInv = 0.990704 \n", - "FVAF = 0.932054 \n", + "VAF = 0.932054 \n", "WRPF = 0.213705 \n", - "DiscFacGPFIndMax = 0.972061 \n", - "DiscFacGPFAggMax = 1.010600 \n" + "DiscFacGPFNrmMax = 0.972061 \n", + "DiscFacGPFAggLivPrbMax = 1.010600 \n" ] } ], "source": [ - "IndShockExample.checkConditions(verbose=True)" + "IndShockExample.check_conditions(verbose=True)" ] } ], diff --git a/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.py b/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.py index e405db16..f6ceeda7 100644 --- a/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.py +++ b/notebooks/Gentle-Intro-To-HARK-Buffer-Stock-Model.py @@ -44,7 +44,7 @@ import HARK from copy import deepcopy mystr = lambda number : "{:.4f}".format(number) -from HARK.utilities import plotFuncs +from HARK.utilities import plot_funcs # %% [markdown] # ## The Consumer's Problem with Transitory and Permanent Shocks @@ -219,8 +219,8 @@ IndShockExample.solve(verbose=True) # Verbose prints progress as solution proceeds # %% -# plotFuncs([list],min,max) takes a [list] of functions and plots their values over a range from min to max -plotFuncs([IndShockExample.solution[0].cFunc,IndShockExample.solution_terminal.cFunc],0.,10.) +# plot_funcs([list],min,max) takes a [list] of functions and plots their values over a range from min to max +plot_funcs([IndShockExample.solution[0].cFunc,IndShockExample.solution_terminal.cFunc],0.,10.) # %% [markdown] # ## Changing Constructed Attributes @@ -253,7 +253,7 @@ # # Perhaps the most interesting such condition is the ["Growth Impatience Condition"](http://econ.jhu.edu/people/ccarroll/Papers/BufferStockTheory/#GIC): If this condition is satisfied, the consumer's optimal behavior is to aim to achieve a "target" value of $m$, to serve as a precautionary buffer against income shocks. # -# The tests can be invoked using the `checkConditions()` method: +# The tests can be invoked using the `check_conditions()` method: # %% -IndShockExample.checkConditions(verbose=True) +IndShockExample.check_conditions(verbose=True) diff --git a/notebooks/Gentle-Intro-To-HARK-PerfForesightCRRA.ipynb b/notebooks/Gentle-Intro-To-HARK-PerfForesightCRRA.ipynb index 78002ec2..5972eb07 100644 --- a/notebooks/Gentle-Intro-To-HARK-PerfForesightCRRA.ipynb +++ b/notebooks/Gentle-Intro-To-HARK-PerfForesightCRRA.ipynb @@ -39,7 +39,7 @@ "import HARK \n", "from copy import deepcopy\n", "mystr = lambda number : \"{:.4f}\".format(number)\n", - "from HARK.utilities import plotFuncs" + "from HARK.utilities import plot_funcs" ] }, { @@ -220,7 +220,7 @@ ], "source": [ "mPlotTop=10\n", - "plotFuncs(PFexample.solution[0].cFunc,0.,mPlotTop)" + "plot_funcs(PFexample.solution[0].cFunc,0.,mPlotTop)" ] }, { @@ -259,7 +259,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Yikes! Let's take a look at the bottom of the consumption function. In the cell below, set the bounds of the $\\texttt{plotFuncs}$ function to display down to the lowest defined value of the consumption function." + "Yikes! Let's take a look at the bottom of the consumption function. In the cell below, set the bounds of the $\\texttt{plot_funcs}$ function to display down to the lowest defined value of the consumption function." ] }, { @@ -284,7 +284,7 @@ "# YOUR FIRST HANDS-ON EXERCISE!\n", "# Fill in the value for \"mPlotBottom\" to plot the consumption function from the point where it is zero.\n", "mPlotBottom = 0. # You should replace 0. with the correct answer \n", - "plotFuncs(PFexample.solution[0].cFunc,mPlotBottom,mPlotTop)" + "plot_funcs(PFexample.solution[0].cFunc,mPlotBottom,mPlotTop)" ] }, { @@ -334,14 +334,14 @@ "NewExample.DiscFac = 0.90\n", "NewExample.solve()\n", "mPlotBottom = NewExample.solution[0].mNrmMin\n", - "plotFuncs([PFexample.solution[0].cFunc,NewExample.solution[0].cFunc],mPlotBottom,mPlotTop)" + "plot_funcs([PFexample.solution[0].cFunc,NewExample.solution[0].cFunc],mPlotBottom,mPlotTop)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "(Note that you can pass a list of functions to $\\texttt{plotFuncs}$ as the first argument rather than just a single function. Lists are written inside of [square brackets].)\n", + "(Note that you can pass a list of functions to $\\texttt{plot_funcs}$ as the first argument rather than just a single function. Lists are written inside of [square brackets].)\n", "\n", "Let's try to deal with the \"problem\" of massive human wealth by making another consumer who has essentially no future income. We can almost eliminate human wealth by making the permanent income growth factor $\\textit{very}$ small.\n", "\n", @@ -373,7 +373,7 @@ "# your lines here!\n", "\n", "# Compare the old and new consumption functions\n", - "plotFuncs([PFexample.solution[0].cFunc,NewExample.solution[0].cFunc],0.,10.)" + "plot_funcs([PFexample.solution[0].cFunc,NewExample.solution[0].cFunc],0.,10.)" ] }, { diff --git a/notebooks/Gentle-Intro-To-HARK-PerfForesightCRRA.py b/notebooks/Gentle-Intro-To-HARK-PerfForesightCRRA.py index 837029de..143c2ba1 100644 --- a/notebooks/Gentle-Intro-To-HARK-PerfForesightCRRA.py +++ b/notebooks/Gentle-Intro-To-HARK-PerfForesightCRRA.py @@ -34,7 +34,7 @@ # # It does not go "into the weeds" - we have hidden some code cells that do boring things that you don't need to digest on your first experience with HARK. Our aim is to convey a feel for how the toolkit works. # -# For the benfit of readers for whom this is your first experience with Python, we have put important Python concepts in **boldface**. +# For the benfit of readers for whom this is your first experience with Python, we have put important Python concepts in **boldface**. # # For those for whom this is the first time they have used a Jupyter notebook, we have put Jupyter instructions in _italics_. Only cursory definitions (if any) are provided here. If you want to learn more, there are many online Python and Jupyter tutorials. @@ -45,13 +45,14 @@ # The most common problem beginners have is to execute a cell before all its predecessors # If you do this, you can restart the kernel (see the "Kernel" menu above) and start over # %matplotlib inline +from HARK.ConsumptionSaving.ConsIndShockModel import PerfForesightConsumerType +from HARK.utilities import plot_funcs import matplotlib.pyplot as plt import numpy as np -import HARK +import HARK from copy import deepcopy -mystr = lambda number : "{:.4f}".format(number) -from HARK.utilities import plotFuncs +def mystr(number): return "{:.4f}".format(number) # %% [markdown] # ## Your First HARK Model: Perfect Foresight @@ -75,15 +76,14 @@ # HARK represents agents solving this type of problem as **instances** of the **class** $\texttt{PerfForesightConsumerType}$, a **subclass** of $\texttt{AgentType}$. To make agents of this class, we must import the class itself into our workspace. (Run the cell below in order to do this). # %% -from HARK.ConsumptionSaving.ConsIndShockModel import PerfForesightConsumerType # %% [markdown] -# The $\texttt{PerfForesightConsumerType}$ class contains within itself the python code that constructs the solution for the perfect foresight model we are studying here, as specifically articulated in [these lecture notes](http://econ.jhu.edu/people/ccarroll/public/lecturenotes/consumption/PerfForesightCRRA/). +# The $\texttt{PerfForesightConsumerType}$ class contains within itself the python code that constructs the solution for the perfect foresight model we are studying here, as specifically articulated in [these lecture notes](http://econ.jhu.edu/people/ccarroll/public/lecturenotes/consumption/PerfForesightCRRA/). # # To create an instance of $\texttt{PerfForesightConsumerType}$, we simply 'call the class'; that is, we invoke it in a way that looks like the way other programming languages evaluate a function, passing as arguments the specific parameter values we want it to have. In the hidden cell below, we define a **dictionary** named $\texttt{PF_dictionary}$ with these parameter values: # # | Param | Description | Code | Value | -# | :---: | --- | --- | --- | +# | :---: | --- | --- | --- | # | $\rho$ | Relative risk aversion | $\texttt{CRRA}$ | 2.5 | # | $\beta$ | Discount factor | $\texttt{DiscFac}$ | 0.96 | # | $R$ | Risk free interest factor | $\texttt{Rfree}$ | 1.03 | @@ -93,17 +93,18 @@ # # For now, don't worry about the specifics of dictionaries. All you need to know is that a dictionary lets us pass many arguments wrapped up in one simple data structure. + # %% {"code_folding": [0]} # This cell defines a parameter dictionary. You can expand it if you want to see what that looks like. PF_dictionary = { - 'CRRA' : 2.5, - 'DiscFac' : 0.96, - 'Rfree' : 1.03, - 'LivPrb' : [0.98], - 'PermGroFac' : [1.01], - 'T_cycle' : 1, - 'cycles' : 0, - 'AgentCount' : 10000 + 'CRRA': 2.5, + 'DiscFac': 0.96, + 'Rfree': 1.03, + 'LivPrb': [0.98], + 'PermGroFac': [1.01], + 'T_cycle': 1, + 'cycles': 0, + 'AgentCount': 10000 } # To those curious enough to open this hidden cell, you might notice that we defined @@ -114,11 +115,11 @@ # Let's make an **object** named $\texttt{PFexample}$ which is an **instance** of the $\texttt{PerfForesightConsumerType}$ class. The object $\texttt{PFexample}$ will bundle together the abstract mathematical description of the solution embodied in $\texttt{PerfForesightConsumerType}$, and the specific set of parameter values defined in $\texttt{PF_dictionary}$. Such a bundle is created passing $\texttt{PF_dictionary}$ to the class $\texttt{PerfForesightConsumerType}$: # %% -PFexample = PerfForesightConsumerType(**PF_dictionary) +PFexample = PerfForesightConsumerType(**PF_dictionary) # the asterisks ** basically say "here come some arguments" to PerfForesightConsumerType # %% [markdown] -# In $\texttt{PFexample}$, we now have _defined_ the problem of a particular infinite horizon perfect foresight consumer who knows how to solve this problem. +# In $\texttt{PFexample}$, we now have _defined_ the problem of a particular infinite horizon perfect foresight consumer who knows how to solve this problem. # # ## Solving an Agent's Problem # @@ -130,7 +131,7 @@ PFexample.solve() # %% [markdown] -# Running the $\texttt{solve}$ method creates the **attribute** of $\texttt{PFexample}$ named $\texttt{solution}.$ In fact, every subclass of $\texttt{AgentType}$ works the same way: The class definition contains the abstract algorithm that knows how to solve the model, but to obtain the particular solution for a specific instance (paramterization/configuration), that instance must be instructed to $\texttt{solve()}$ its problem. +# Running the $\texttt{solve}$ method creates the **attribute** of $\texttt{PFexample}$ named $\texttt{solution}.$ In fact, every subclass of $\texttt{AgentType}$ works the same way: The class definition contains the abstract algorithm that knows how to solve the model, but to obtain the particular solution for a specific instance (paramterization/configuration), that instance must be instructed to $\texttt{solve()}$ its problem. # # The $\texttt{solution}$ attribute is always a _list_ of solutions to a sequence of single period solutions of the problem. In the case of an infinite horizon model like the one here, there is just one element in that list -- the solution to all periods of the infinite horizon problem. (In a life cycle model, there would be a list of solutions, one for each age). The consumption function stored as the first element (element 0) of the solution list can be retrieved by: @@ -138,19 +139,19 @@ PFexample.solution[0].cFunc # %% [markdown] -# One of the results proven in the associated [the lecture notes](http://econ.jhu.edu/people/ccarroll/public/lecturenotes/consumption/PerfForesightCRRA/) is that, for the specific problem defined above, there is a solution in which the _ratio_ $c = C/P$ is a linear function of the _ratio_ of market resources to permanent income, $m = M/P$. +# One of the results proven in the associated [the lecture notes](http://econ.jhu.edu/people/ccarroll/public/lecturenotes/consumption/PerfForesightCRRA/) is that, for the specific problem defined above, there is a solution in which the _ratio_ $c = C/P$ is a linear function of the _ratio_ of market resources to permanent income, $m = M/P$. # # This is why $\texttt{cFunc}$ can be represented by a linear interpolation. It can be plotted using the command below: # # %% -mPlotTop=10 -plotFuncs(PFexample.solution[0].cFunc,0.,mPlotTop) +mPlotTop = 10 +plot_funcs(PFexample.solution[0].cFunc, 0., mPlotTop) # %% [markdown] # The figure illustrates one of the surprising features of the perfect foresight model: A person with zero money should be spending at a rate more than double their income ($\texttt{cFunc}(0.) \approx 2.08$). What gives? # -# The answer is that we have not incorporated any constraint that would prevent the agent from borrowing against the entire PDV of future earnings -- human wealth. +# The answer is that we have not incorporated any constraint that would prevent the agent from borrowing against the entire PDV of future earnings -- human wealth. # # How much is that? An equivalent question is: What's the minimum value of $m_t$ where the consumption function is defined (that is, where the consumer has a positive expected _total wealth_ (the sum of human and nonuman wealth)? Let's check: @@ -161,13 +162,13 @@ print("This agent's consumption function is defined down to m_t = " + str(mMinimum)) # %% [markdown] -# Yikes! Let's take a look at the bottom of the consumption function. In the cell below, set the bounds of the $\texttt{plotFuncs}$ function to display down to the lowest defined value of the consumption function. +# Yikes! Let's take a look at the bottom of the consumption function. In the cell below, set the bounds of the `plot_funcs` function to display down to the lowest defined value of the consumption function. # %% # YOUR FIRST HANDS-ON EXERCISE! # Fill in the value for "mPlotBottom" to plot the consumption function from the point where it is zero. -mPlotBottom = 0. # You should replace 0. with the correct answer -plotFuncs(PFexample.solution[0].cFunc,mPlotBottom,mPlotTop) +mPlotBottom = 0. # You should replace 0. with the correct answer +plot_funcs(PFexample.solution[0].cFunc, mPlotBottom, mPlotTop) # %% [markdown] # ## Changing Agent Parameters @@ -184,10 +185,10 @@ NewExample.DiscFac = 0.90 NewExample.solve() mPlotBottom = NewExample.solution[0].mNrmMin -plotFuncs([PFexample.solution[0].cFunc,NewExample.solution[0].cFunc],mPlotBottom,mPlotTop) +plot_funcs([PFexample.solution[0].cFunc, NewExample.solution[0].cFunc], mPlotBottom, mPlotTop) # %% [markdown] -# (Note that you can pass a list of functions to $\texttt{plotFuncs}$ as the first argument rather than just a single function. Lists are written inside of [square brackets].) +# (Note that you can pass a list of functions to `plot_funcs` as the first argument rather than just a single function. Lists are written inside of [square brackets].) # # Let's try to deal with the "problem" of massive human wealth by making another consumer who has essentially no future income. We can almost eliminate human wealth by making the permanent income growth factor $\textit{very}$ small. # @@ -200,7 +201,7 @@ # your lines here! # Compare the old and new consumption functions -plotFuncs([PFexample.solution[0].cFunc,NewExample.solution[0].cFunc],0.,10.) +plot_funcs([PFexample.solution[0].cFunc, NewExample.solution[0].cFunc], 0., 10.) # %% [markdown] # Now $\texttt{NewExample}$'s consumption function has the same slope (MPC) as $\texttt{PFexample}$, but it emanates from (almost) zero-- he has basically no future income to borrow against! diff --git a/notebooks/KeynesFriedmanModigliani.ipynb b/notebooks/KeynesFriedmanModigliani.ipynb index 5fbb6274..00577c8f 100644 --- a/notebooks/KeynesFriedmanModigliani.ipynb +++ b/notebooks/KeynesFriedmanModigliani.ipynb @@ -35,7 +35,7 @@ "import pandas_datareader.data as web\n", "\n", "from HARK.ConsumptionSaving.ConsIndShockModel import PerfForesightConsumerType\n", - "from HARK.utilities import plotFuncsDer, plotFuncs" + "from HARK.utilities import plot_funcs_der, plot_funcs" ] }, { diff --git a/notebooks/KeynesFriedmanModigliani.py b/notebooks/KeynesFriedmanModigliani.py index 272c8122..3fb23ecf 100644 --- a/notebooks/KeynesFriedmanModigliani.py +++ b/notebooks/KeynesFriedmanModigliani.py @@ -78,7 +78,7 @@ import pandas_datareader.data as web from HARK.ConsumptionSaving.ConsIndShockModel import PerfForesightConsumerType -from HARK.utilities import plotFuncsDer, plotFuncs +from HARK.utilities import plot_funcs_der, plot_funcs # %% [markdown] diff --git a/notebooks/LifeCycleModelTheoryVsData.ipynb b/notebooks/LifeCycleModelTheoryVsData.ipynb index a4450f59..3c7318a3 100644 --- a/notebooks/LifeCycleModelTheoryVsData.ipynb +++ b/notebooks/LifeCycleModelTheoryVsData.ipynb @@ -14,7 +14,7 @@ "\n", "For example, some papers have tabulated information about the **growth rate** of assets at different ages over the life cycle. \n", "\n", - "The default parameters of the HARK life cycle model have not been optmized to match features of the Norwegian data; a first step in a real \"structural\" estimation would be to use Norwegian calibrate the inputs to the model (like the profile of income, and the magnitude of income shocks, over the life cycle), and then to find the values of parameters like the time preference rate that allow the model to fit the data best. (See [SolvingMicroDSOPs](https://econ.jhu.edu/people/ccarroll/SolvingMicroDSOPs) for how this can be done, and search for the corresponding HARK content using [our documentation](https://hark.readthedocs.io))." + "The default parameters of the HARK life cycle model have not been optmized to match features of the Norwegian data; a first step in a real \"structural\" estimation would be to use Norwegian calibrate the inputs to the model (like the profile of income, and the magnitude of income shocks, over the life cycle), and then to find the values of parameters like the time preference rate that allow the model to fit the data best. (See [SolvingMicroDSOPs](https://www.econ2.jhu.edu/people/ccarroll/SolvingMicroDSOPs) for how this can be done, and search for the corresponding HARK content using [our documentation](https://hark.readthedocs.io))." ] }, { @@ -29,7 +29,7 @@ "# Initial imports and notebook setup, click arrow to show\n", "\n", "import HARK.ConsumptionSaving.ConsIndShockModel as cShksModl # The consumption-saving micro model\n", - "from HARK.utilities import plotFuncsDer, plotFuncs # Some tools\n", + "from HARK.utilities import plot_funcs_der, plot_funcs # Some tools\n", "import pandas as pd \n", "\n", "import numpy as np" @@ -267,7 +267,7 @@ "\n", "print('Consumption as a function of market resources while working:')\n", "mMin = min([LifeCyclePop.solution[t].mNrmMin for t in range(LifeCyclePop.T_cycle)])\n", - "plotFuncs(LifeCyclePop.cFunc[:LifeCyclePop.T_retire],mMin,5)" + "plot_funcs(LifeCyclePop.cFunc[:LifeCyclePop.T_retire],mMin,5)" ] }, { diff --git a/notebooks/LifeCycleModelTheoryVsData.py b/notebooks/LifeCycleModelTheoryVsData.py index 75a39cfd..c444d165 100644 --- a/notebooks/LifeCycleModelTheoryVsData.py +++ b/notebooks/LifeCycleModelTheoryVsData.py @@ -71,7 +71,7 @@ # Initial imports and notebook setup, click arrow to show import HARK.ConsumptionSaving.ConsIndShockModel as cShksModl # The consumption-saving micro model -from HARK.utilities import plotFuncsDer, plotFuncs # Some tools +from HARK.utilities import plot_funcs_der, plot_funcs # Some tools import pandas as pd import numpy as np @@ -248,7 +248,7 @@ print('Consumption as a function of market resources while working:') mMin = min([LifeCyclePop.solution[t].mNrmMin for t in range(LifeCyclePop.T_cycle)]) -plotFuncs(LifeCyclePop.cFunc[:LifeCyclePop.T_retire],mMin,5) +plot_funcs(LifeCyclePop.cFunc[:LifeCyclePop.T_retire],mMin,5) # %% {"code_folding": []} diff --git a/notebooks/MPC-Out-of-Credit-vs-MPC-Out-of-Income.ipynb b/notebooks/MPC-Out-of-Credit-vs-MPC-Out-of-Income.ipynb index c0bb557a..5bf974ef 100644 --- a/notebooks/MPC-Out-of-Credit-vs-MPC-Out-of-Income.ipynb +++ b/notebooks/MPC-Out-of-Credit-vs-MPC-Out-of-Income.ipynb @@ -301,7 +301,7 @@ "## Now, plot the functions we want\n", "%matplotlib inline\n", "# Import a useful plotting function from HARK.utilities\n", - "from HARK.utilities import plotFuncs\n", + "from HARK.utilities import plot_funcs\n", "import pylab as plt # We need this module to change the y-axis on the graphs\n", "\n", "\n", @@ -309,7 +309,7 @@ "x_max = 10.\n", "\n", "\n", - "# Note that plotFuncs takes four arguments: (1) a list of the arguments to plot,\n", + "# Note that plot_funcs takes four arguments: (1) a list of the arguments to plot,\n", "# (2) the lower bound for the plots, (3) the upper bound for the plots, and (4) keywords to pass\n", "# to the legend for the plot.\n", "\n", @@ -318,7 +318,7 @@ "# by a tiny amount\n", "print('The XtraCredit consumption function allows the consumer to spend a tiny bit more') \n", "print('The difference is so small that the baseline is obscured by the XtraCredit solution') \n", - "plotFuncs([BaselineExample.solution[0].cFunc,XtraCreditExample.solution[0].cFunc],\n", + "plot_funcs([BaselineExample.solution[0].cFunc,XtraCreditExample.solution[0].cFunc],\n", " BaselineExample.solution[0].mNrmMin,x_max,\n", " legend_kwds = {'loc': 'upper left', 'labels': [\"Baseline\",\"XtraCredit\"]})\n", "\n", @@ -326,7 +326,7 @@ "# Plot the MPCs to compare them\n", "print('MPC out of Credit v MPC out of Income')\n", "plt.ylim([0.,1.2])\n", - "plotFuncs([FirstDiffMPC_Credit,FirstDiffMPC_Income],\n", + "plot_funcs([FirstDiffMPC_Credit,FirstDiffMPC_Income],\n", " BaselineExample.solution[0].mNrmMin,x_max,\n", " legend_kwds = {'labels': [\"MPC out of Credit\",\"MPC out of Income\"]})" ] diff --git a/notebooks/MPC-Out-of-Credit-vs-MPC-Out-of-Income.py b/notebooks/MPC-Out-of-Credit-vs-MPC-Out-of-Income.py index 7ec38799..31e9d110 100644 --- a/notebooks/MPC-Out-of-Credit-vs-MPC-Out-of-Income.py +++ b/notebooks/MPC-Out-of-Credit-vs-MPC-Out-of-Income.py @@ -179,7 +179,7 @@ def FirstDiffMPC_Credit(x): ## Now, plot the functions we want # %matplotlib inline # Import a useful plotting function from HARK.utilities -from HARK.utilities import plotFuncs +from HARK.utilities import plot_funcs import pylab as plt # We need this module to change the y-axis on the graphs @@ -187,7 +187,7 @@ def FirstDiffMPC_Credit(x): x_max = 10. -# Note that plotFuncs takes four arguments: (1) a list of the arguments to plot, +# Note that plot_funcs takes four arguments: (1) a list of the arguments to plot, # (2) the lower bound for the plots, (3) the upper bound for the plots, and (4) keywords to pass # to the legend for the plot. @@ -196,7 +196,7 @@ def FirstDiffMPC_Credit(x): # by a tiny amount print('The XtraCredit consumption function allows the consumer to spend a tiny bit more') print('The difference is so small that the baseline is obscured by the XtraCredit solution') -plotFuncs([BaselineExample.solution[0].cFunc,XtraCreditExample.solution[0].cFunc], +plot_funcs([BaselineExample.solution[0].cFunc,XtraCreditExample.solution[0].cFunc], BaselineExample.solution[0].mNrmMin,x_max, legend_kwds = {'loc': 'upper left', 'labels': ["Baseline","XtraCredit"]}) @@ -204,6 +204,6 @@ def FirstDiffMPC_Credit(x): # Plot the MPCs to compare them print('MPC out of Credit v MPC out of Income') plt.ylim([0.,1.2]) -plotFuncs([FirstDiffMPC_Credit,FirstDiffMPC_Income], +plot_funcs([FirstDiffMPC_Credit,FirstDiffMPC_Income], BaselineExample.solution[0].mNrmMin,x_max, legend_kwds = {'labels': ["MPC out of Credit","MPC out of Income"]}) diff --git a/notebooks/Micro-and-Macro-Implications-of-Very-Impatient-HHs.ipynb b/notebooks/Micro-and-Macro-Implications-of-Very-Impatient-HHs.ipynb index 496423db..a235c716 100644 --- a/notebooks/Micro-and-Macro-Implications-of-Very-Impatient-HHs.ipynb +++ b/notebooks/Micro-and-Macro-Implications-of-Very-Impatient-HHs.ipynb @@ -17,7 +17,7 @@ "source": [ "## Introduction\n", "\n", - "Buffer stock saving models of the kind implemented in $\\texttt{ConsIndShockType}$ say that, if a standard ['Growth Impatience Condition'](https://econ.jhu.edu/people/ccarroll/papers/BufferStockTheory/#Growth-Modified-Conditions), holds:\n", + "Buffer stock saving models of the kind implemented in $\\texttt{ConsIndShockType}$ say that, if a standard ['Growth Impatience Condition'](https://www.econ2.jhu.edu/people/ccarroll/papers/BufferStockTheory/#Growth-Modified-Conditions), holds:\n", "\n", "\\begin{eqnarray}\n", "\\newcommand{\\Rfree}{\\mathsf{R}}\\newcommand{\\DiscFac}{\\beta}\\newcommand{\\PermGroFac}{\\Gamma}\\newcommand{\\PermShk}{\\psi}\\newcommand{\\CRRA}{\\rho}\n", @@ -58,7 +58,7 @@ "from copy import deepcopy\n", "\n", "import HARK # Prevents import error from Demos repo\n", - "from HARK.utilities import plotFuncs\n", + "from HARK.utilities import plot_funcs\n", "\n", "\n", "Generator=False # Is this notebook the master or is it generated?\n", diff --git a/notebooks/Micro-and-Macro-Implications-of-Very-Impatient-HHs.py b/notebooks/Micro-and-Macro-Implications-of-Very-Impatient-HHs.py index debb704c..09c4cf8b 100644 --- a/notebooks/Micro-and-Macro-Implications-of-Very-Impatient-HHs.py +++ b/notebooks/Micro-and-Macro-Implications-of-Very-Impatient-HHs.py @@ -68,7 +68,7 @@ from copy import deepcopy import HARK # Prevents import error from Demos repo -from HARK.utilities import plotFuncs +from HARK.utilities import plot_funcs Generator=False # Is this notebook the master or is it generated? diff --git a/notebooks/Nondurables-During-Great-Recession.ipynb b/notebooks/Nondurables-During-Great-Recession.ipynb index c54073ef..7b0c16b4 100644 --- a/notebooks/Nondurables-During-Great-Recession.ipynb +++ b/notebooks/Nondurables-During-Great-Recession.ipynb @@ -31,7 +31,7 @@ "from copy import deepcopy\n", "\n", "import HARK # Prevents import error from Demos repo\n", - "from HARK.utilities import plotFuncs" + "from HARK.utilities import plot_funcs" ] }, { @@ -416,7 +416,7 @@ "plt.ylim(-20.,5.)\n", "plt.hlines(TargetChangeInC,perm_min,perm_max)\n", "# The expression below shows the power of python\n", - "plotFuncs([calcConsChangeAfterPermShkChange],perm_min,perm_max,N=num_points)" + "plot_funcs([calcConsChangeAfterPermShkChange],perm_min,perm_max,N=num_points)" ] }, { diff --git a/notebooks/Nondurables-During-Great-Recession.py b/notebooks/Nondurables-During-Great-Recession.py index 9cf53c5e..b5d74270 100644 --- a/notebooks/Nondurables-During-Great-Recession.py +++ b/notebooks/Nondurables-During-Great-Recession.py @@ -74,7 +74,7 @@ from copy import deepcopy import HARK # Prevents import error from Demos repo -from HARK.utilities import plotFuncs +from HARK.utilities import plot_funcs # %% [markdown] # ### There Was a Big Drop in Consumption ... @@ -318,7 +318,7 @@ def calcConsChangeAfterUnempPrbChange(newVals): plt.ylim(-20.,5.) plt.hlines(TargetChangeInC,perm_min,perm_max) # The expression below shows the power of python -plotFuncs([calcConsChangeAfterPermShkChange],perm_min,perm_max,N=num_points) +plot_funcs([calcConsChangeAfterPermShkChange],perm_min,perm_max,N=num_points) # %% [markdown] # The figure shows that if people's beliefs about the standard deviation of permanent shocks to their incomes had changed from 0.06 (the default value) to about 0.012, the model would predict an immediate drop in consumption spending of about the magnitude seen in 2008. diff --git a/notebooks/PerfForesightCRRA-Approximation.ipynb b/notebooks/PerfForesightCRRA-Approximation.ipynb index c5bdfd95..bf3a49f1 100644 --- a/notebooks/PerfForesightCRRA-Approximation.ipynb +++ b/notebooks/PerfForesightCRRA-Approximation.ipynb @@ -25,7 +25,7 @@ "import HARK \n", "from copy import deepcopy\n", "mystr = lambda number : \"{:.4f}\".format(number)\n", - "from HARK.utilities import plotFuncs\n", + "from HARK.utilities import plot_funcs\n", "\n", "# These last two will make our charts look nice\n", "plt.style.use('seaborn-darkgrid')\n", diff --git a/notebooks/PerfForesightCRRA-Approximation.py b/notebooks/PerfForesightCRRA-Approximation.py index f8749b2a..32d76b48 100644 --- a/notebooks/PerfForesightCRRA-Approximation.py +++ b/notebooks/PerfForesightCRRA-Approximation.py @@ -39,7 +39,7 @@ import HARK from copy import deepcopy mystr = lambda number : "{:.4f}".format(number) -from HARK.utilities import plotFuncs +from HARK.utilities import plot_funcs # These last two will make our charts look nice plt.style.use('seaborn-darkgrid') diff --git a/notebooks/PerfForesightCRRA-SavingRate.ipynb b/notebooks/PerfForesightCRRA-SavingRate.ipynb index 576bf3cb..c25ed5c9 100644 --- a/notebooks/PerfForesightCRRA-SavingRate.ipynb +++ b/notebooks/PerfForesightCRRA-SavingRate.ipynb @@ -22,7 +22,7 @@ "import HARK \n", "from copy import deepcopy\n", "mystr = lambda number : \"{:.4f}\".format(number)\n", - "from HARK.utilities import plotFuncs\n", + "from HARK.utilities import plot_funcs\n", "\n", "# These last two will make our charts look nice\n", "plt.style.use('seaborn-darkgrid')\n", diff --git a/notebooks/PerfForesightCRRA-SavingRate.py b/notebooks/PerfForesightCRRA-SavingRate.py index 96c523ce..6a8c5ff9 100644 --- a/notebooks/PerfForesightCRRA-SavingRate.py +++ b/notebooks/PerfForesightCRRA-SavingRate.py @@ -37,7 +37,7 @@ import HARK from copy import deepcopy mystr = lambda number : "{:.4f}".format(number) -from HARK.utilities import plotFuncs +from HARK.utilities import plot_funcs # These last two will make our charts look nice plt.style.use('seaborn-darkgrid') diff --git a/notebooks/TractableBufferStock-Interactive.ipynb b/notebooks/TractableBufferStock-Interactive.ipynb index 8a465579..c3f98003 100644 --- a/notebooks/TractableBufferStock-Interactive.ipynb +++ b/notebooks/TractableBufferStock-Interactive.ipynb @@ -40,7 +40,7 @@ "\n", "from ipywidgets import interact, interactive, fixed, interact_manual\n", "import ipywidgets as widgets\n", - "from HARK.utilities import plotFuncs" + "from HARK.utilities import plot_funcs" ] }, { diff --git a/notebooks/TractableBufferStock-Interactive.py b/notebooks/TractableBufferStock-Interactive.py index c5f13f57..78a1b5f0 100644 --- a/notebooks/TractableBufferStock-Interactive.py +++ b/notebooks/TractableBufferStock-Interactive.py @@ -52,7 +52,7 @@ from ipywidgets import interact, interactive, fixed, interact_manual import ipywidgets as widgets -from HARK.utilities import plotFuncs +from HARK.utilities import plot_funcs # %% {"code_folding": [0]} # Import the model from the toolkit