Skip to content

Commit

Permalink
clean up notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlujan91 committed Jul 11, 2024
1 parent 1b68bf6 commit 31baea5
Show file tree
Hide file tree
Showing 48 changed files with 768 additions and 610 deletions.
24 changes: 13 additions & 11 deletions examples/Calibration/Income_calibrations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
"Created on Sun Jan 3 10:50:02 2021\n",
"\"\"\"Created on Sun Jan 3 10:50:02 2021\n",
"\n",
"@author: Mateo\n",
"\"\"\"\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"from HARK.Calibration.Income.IncomeTools import (\n",
" parse_income_spec,\n",
" find_profile,\n",
" Cagetti_income,\n",
" CGM_income,\n",
" find_profile,\n",
" parse_income_spec,\n",
")\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# What year to use as the base monetary year?\n",
"# (pick 1992 as it is used by both of the papers we are comparing)\n",
"adjust_infl_to = 1992"
Expand Down Expand Up @@ -58,19 +57,22 @@
" label = spec[0]\n",
"\n",
" params = parse_income_spec(\n",
" age_min=age_min, age_max=age_max, adjust_infl_to=adjust_infl_to, **spec[1]\n",
" age_min=age_min,\n",
" age_max=age_max,\n",
" adjust_infl_to=adjust_infl_to,\n",
" **spec[1],\n",
" )\n",
" MeanY = find_profile(params[\"PermGroFac\"], params[\"P0\"])\n",
"\n",
" plt.plot(ages, MeanY, label=label)\n",
"\n",
"plt.title(\n",
" \"Mean paths of permanent income calibrations in\\n\"\n",
" + \"Cocco, Gomes & Maenhout (2005)\"\n",
" + \"Cocco, Gomes & Maenhout (2005)\",\n",
")\n",
"plt.xlabel(\"Age\")\n",
"plt.ylabel(\n",
" \"Mean Permanent Income,\\n\" + \"Thousands of {} U.S. dollars\".format(adjust_infl_to)\n",
" \"Mean Permanent Income,\\n\" + f\"Thousands of {adjust_infl_to} U.S. dollars\",\n",
")\n",
"plt.legend()\n",
"plt.show()"
Expand Down Expand Up @@ -122,7 +124,7 @@
"plt.title(\"Mean paths of permanent income calibrations in\\n\" + \"Cagetti (2003)\")\n",
"plt.xlabel(\"Age\")\n",
"plt.ylabel(\n",
" \"Mean Permanent Income,\\n\" + \"Thousands of {} U.S. dollars\".format(adjust_infl_to)\n",
" \"Mean Permanent Income,\\n\" + f\"Thousands of {adjust_infl_to} U.S. dollars\",\n",
")\n",
"plt.legend()\n",
"plt.show()"
Expand Down
31 changes: 19 additions & 12 deletions examples/Calibration/Life_Cycle_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
"metadata": {},
"outputs": [],
"source": [
"from HARK.ConsumptionSaving.ConsIndShockModel import (\n",
" IndShockConsumerType,\n",
" init_lifecycle,\n",
")\n",
"from copy import copy\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"\n",
"from HARK.Calibration.Income.IncomeTools import (\n",
" CGM_income,\n",
" parse_income_spec,\n",
" parse_time_params,\n",
" CGM_income,\n",
")\n",
"\n",
"from HARK.Calibration.life_tables.us_ssa.SSATools import parse_ssa_life_table\n",
"from HARK.Calibration.SCF.WealthIncomeDist.SCFDistTools import (\n",
" income_wealth_dists_from_scf,\n",
")\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"from copy import copy\n",
"from HARK.ConsumptionSaving.ConsIndShockModel import (\n",
" IndShockConsumerType,\n",
" init_lifecycle,\n",
")\n",
"from HARK.utilities import plot_funcs"
]
},
Expand Down Expand Up @@ -54,13 +54,20 @@
"\n",
"# Initial distribution of wealth and permanent income\n",
"dist_params = income_wealth_dists_from_scf(\n",
" base_year=adjust_infl_to, age=birth_age, education=education, wave=1995\n",
" base_year=adjust_infl_to,\n",
" age=birth_age,\n",
" education=education,\n",
" wave=1995,\n",
")\n",
"\n",
"# We need survival probabilities only up to death_age-1, because survival\n",
"# probability at death_age is 1.\n",
"liv_prb = parse_ssa_life_table(\n",
" female=True, cross_sec=True, year=2004, min_age=birth_age, max_age=death_age - 1\n",
" female=True,\n",
" cross_sec=True,\n",
" year=2004,\n",
" min_age=birth_age,\n",
" max_age=death_age - 1,\n",
")\n",
"\n",
"# Parameters related to the number of periods implied by the calibration\n",
Expand Down Expand Up @@ -258,7 +265,7 @@
"plt.plot(AgeMeans.Age, AgeMeans.Cons, label=\"Consumption\")\n",
"plt.legend()\n",
"plt.xlabel(\"Age\")\n",
"plt.ylabel(\"Thousands of {} USD\".format(adjust_infl_to))\n",
"plt.ylabel(f\"Thousands of {adjust_infl_to} USD\")\n",
"plt.title(\"Variable Medians Conditional on Survival\")\n",
"plt.grid()"
]
Expand Down
13 changes: 7 additions & 6 deletions examples/Calibration/SCF_distributions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
"Created on Mon Jan 18 13:57:50 2021\n",
"\"\"\"Created on Mon Jan 18 13:57:50 2021\n",
"\n",
"@author: Mateo\n",
"\"\"\"\n",
"\n",
"from itertools import product, starmap\n",
"\n",
"import pandas as pd\n",
"import seaborn as sns\n",
"\n",
"from HARK.Calibration.SCF.WealthIncomeDist.SCFDistTools import (\n",
" income_wealth_dists_from_scf,\n",
")\n",
"import seaborn as sns\n",
"from itertools import product, starmap\n",
"import pandas as pd\n",
"\n",
"# List the education levels and years\n",
"educ_lvls = [\"NoHS\", \"HS\", \"College\"]\n",
Expand All @@ -41,7 +42,7 @@
"base_year, age, education, year = list(zip(*params))\n",
"\n",
"frame = pd.DataFrame(\n",
" {\"base_year\": base_year, \"age\": age, \"education\": education, \"wave\": year}\n",
" {\"base_year\": base_year, \"age\": age, \"education\": education, \"wave\": year},\n",
")\n",
"\n",
"results = list(starmap(income_wealth_dists_from_scf, params))\n",
Expand Down
10 changes: 5 additions & 5 deletions examples/Calibration/Sabelhaus_Song_var_profiles.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
"Created on Thu Jan 14 16:44:09 2021\n",
"\"\"\"Created on Thu Jan 14 16:44:09 2021\n",
"\n",
"@author: Mateo\n",
"\n",
Expand All @@ -22,9 +21,10 @@
"\"\"\"\n",
"\n",
"import matplotlib.pyplot as plt\n",
"from HARK.Calibration.Income.IncomeTools import sabelhaus_song_var_profile\n",
"import numpy as np\n",
"\n",
"from HARK.Calibration.Income.IncomeTools import sabelhaus_song_var_profile\n",
"\n",
"# Set up ages and cohorts at which we will get the variances\n",
"age_min = 27\n",
"age_max = 54\n",
Expand Down Expand Up @@ -84,7 +84,7 @@
" plt.plot(\n",
" variances[i][\"Age\"],\n",
" np.power(variances[i][\"TranShkStd\"], 2),\n",
" label=\"Tran. {} cohort\".format(coh_label),\n",
" label=f\"Tran. {coh_label} cohort\",\n",
" )\n",
"\n",
"plt.legend()\n",
Expand All @@ -96,7 +96,7 @@
" plt.plot(\n",
" variances[i][\"Age\"],\n",
" np.power(variances[i][\"PermShkStd\"], 2),\n",
" label=\"Perm. {} cohort\".format(coh_label),\n",
" label=f\"Perm. {coh_label} cohort\",\n",
" )\n",
"\n",
"plt.legend()"
Expand Down
397 changes: 202 additions & 195 deletions examples/Calibration/US_SSA_life_tables.ipynb

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/ConsBequestModel/example_TerminalBequest.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
" parse_income_spec,\n",
" parse_time_params,\n",
")\n",
"from HARK.ConsumptionSaving.ConsBequestModel import (\n",
" BequestWarmGlowConsumerType,\n",
" init_warm_glow_terminal_only,\n",
")\n",
"from HARK.Calibration.life_tables.us_ssa.SSATools import parse_ssa_life_table\n",
"from HARK.Calibration.SCF.WealthIncomeDist.SCFDistTools import (\n",
" income_wealth_dists_from_scf,\n",
")\n",
"from HARK.ConsumptionSaving.ConsBequestModel import (\n",
" BequestWarmGlowConsumerType,\n",
" init_warm_glow_terminal_only,\n",
")\n",
"from HARK.utilities import plot_funcs"
]
},
Expand Down
8 changes: 4 additions & 4 deletions examples/ConsBequestModel/example_TerminalBequestPort.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
" parse_income_spec,\n",
" parse_time_params,\n",
")\n",
"from HARK.ConsumptionSaving.ConsBequestModel import (\n",
" BequestWarmGlowPortfolioType,\n",
" init_portfolio_bequest,\n",
")\n",
"from HARK.Calibration.life_tables.us_ssa.SSATools import parse_ssa_life_table\n",
"from HARK.Calibration.SCF.WealthIncomeDist.SCFDistTools import (\n",
" income_wealth_dists_from_scf,\n",
")\n",
"from HARK.ConsumptionSaving.ConsBequestModel import (\n",
" BequestWarmGlowPortfolioType,\n",
" init_portfolio_bequest,\n",
")\n",
"from HARK.utilities import plot_funcs"
]
},
Expand Down
8 changes: 4 additions & 4 deletions examples/ConsBequestModel/example_WarmGlowBequest.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
" parse_income_spec,\n",
" parse_time_params,\n",
")\n",
"from HARK.ConsumptionSaving.ConsBequestModel import (\n",
" BequestWarmGlowConsumerType,\n",
" init_warm_glow,\n",
")\n",
"from HARK.Calibration.life_tables.us_ssa.SSATools import parse_ssa_life_table\n",
"from HARK.Calibration.SCF.WealthIncomeDist.SCFDistTools import (\n",
" income_wealth_dists_from_scf,\n",
")\n",
"from HARK.ConsumptionSaving.ConsBequestModel import (\n",
" BequestWarmGlowConsumerType,\n",
" init_warm_glow,\n",
")\n",
"from HARK.utilities import plot_funcs"
]
},
Expand Down
8 changes: 4 additions & 4 deletions examples/ConsBequestModel/example_WarmGlowBequestPort.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
" parse_income_spec,\n",
" parse_time_params,\n",
")\n",
"from HARK.ConsumptionSaving.ConsBequestModel import (\n",
" BequestWarmGlowPortfolioType,\n",
" init_portfolio_bequest,\n",
")\n",
"from HARK.Calibration.life_tables.us_ssa.SSATools import parse_ssa_life_table\n",
"from HARK.Calibration.SCF.WealthIncomeDist.SCFDistTools import (\n",
" income_wealth_dists_from_scf,\n",
")\n",
"from HARK.ConsumptionSaving.ConsBequestModel import (\n",
" BequestWarmGlowPortfolioType,\n",
" init_portfolio_bequest,\n",
")\n",
"from HARK.utilities import plot_funcs"
]
},
Expand Down
8 changes: 6 additions & 2 deletions examples/ConsBequestModel/example_WealthPortfolio.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"cycles = 0\n",
"port_agent = PortfolioConsumerType(cycles=cycles)\n",
"wealth_agent = WealthPortfolioConsumerType(\n",
" cycles=cycles, WealthShare=0.5, WealthShift=0.0\n",
" cycles=cycles,\n",
" WealthShare=0.5,\n",
" WealthShift=0.0,\n",
")"
]
},
Expand Down Expand Up @@ -152,7 +154,9 @@
],
"source": [
"plot_funcs(\n",
" [wealth_agent.solution[0].ShareFuncAdj, port_agent.solution[0].ShareFuncAdj], 0, 100\n",
" [wealth_agent.solution[0].ShareFuncAdj, port_agent.solution[0].ShareFuncAdj],\n",
" 0,\n",
" 100,\n",
")"
]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/ConsIndShockModel/Finite Cyclical Test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"from HARK.ConsumptionSaving.ConsIndShockModel import IndShockConsumerType\n",
"from HARK.utilities import plot_funcs\n",
"\n",
"mystr = lambda number: \"{:.4f}\".format(number)"
"mystr = lambda number: f\"{number:.4f}\""
]
},
{
Expand Down
11 changes: 7 additions & 4 deletions examples/ConsIndShockModel/IndShockConsumerType.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
"outputs": [],
"source": [
"# Initial imports and notebook setup, click arrow to show\n",
"from HARK.ConsumptionSaving.ConsIndShockModel import IndShockConsumerType\n",
"from HARK.utilities import plot_funcs_der, plot_funcs\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"mystr = lambda number: \"{:.4f}\".format(number)"
"from HARK.ConsumptionSaving.ConsIndShockModel import IndShockConsumerType\n",
"from HARK.utilities import plot_funcs, plot_funcs_der\n",
"\n",
"mystr = lambda number: f\"{number:.4f}\""
]
},
{
Expand Down Expand Up @@ -318,7 +319,9 @@
"plot_funcs(IndShockExample.solution[0].cFunc, IndShockExample.solution[0].mNrmMin, 5)\n",
"print(\"Marginal propensity to consume for an idiosyncratic shocks consumer type:\")\n",
"plot_funcs_der(\n",
" IndShockExample.solution[0].cFunc, IndShockExample.solution[0].mNrmMin, 5\n",
" IndShockExample.solution[0].cFunc,\n",
" IndShockExample.solution[0].mNrmMin,\n",
" 5,\n",
")"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/ConsIndShockModel/KinkedRconsumerType.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"import numpy as np\n",
"\n",
"from HARK.ConsumptionSaving.ConsIndShockModel import KinkedRconsumerType\n",
"from HARK.utilities import plot_funcs_der, plot_funcs\n",
"from HARK.utilities import plot_funcs, plot_funcs_der\n",
"\n",
"mystr = lambda number: \"{:.4f}\".format(number)"
"mystr = lambda number: f\"{number:.4f}\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/ConsIndShockModel/PerfForesightConsumerType.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"from HARK.ConsumptionSaving.ConsIndShockModel import PerfForesightConsumerType\n",
"from HARK.utilities import plot_funcs\n",
"\n",
"mystr = lambda number: \"{:.4f}\".format(number)"
"mystr = lambda number: f\"{number:.4f}\""
]
},
{
Expand Down
9 changes: 5 additions & 4 deletions examples/ConsNewKeynesianModel/Jacobian_Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
},
"outputs": [],
"source": [
"import time\n",
"\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from HARK.ConsumptionSaving.ConsNewKeynesianModel import (\n",
" NewKeynesianConsumerType,\n",
")\n",
"\n",
"import time\n",
"import matplotlib.pyplot as plt"
")"
]
},
{
Expand Down
Loading

0 comments on commit 31baea5

Please sign in to comment.