Skip to content

Commit

Permalink
tracking bug in bequest portfolio consumer model check
Browse files Browse the repository at this point in the history
  • Loading branch information
dedwar65 committed Jan 25, 2024
1 parent 638c5ca commit 501eb2a
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 145 deletions.
91 changes: 91 additions & 0 deletions examples/ConsBequestModel/example.ConsPortfolioComp.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from HARK.ConsumptionSaving.ConsPortfolioModel import (\n",
" PortfolioConsumerType,\n",
" init_portfolio,\n",
")\n",
"from HARK.ConsumptionSaving.ConsBequestModel import BequestWarmGlowPortfolioType\n",
"\n",
"from HARK.ConsumptionSaving.ConsIndShockModel import (\n",
" init_idiosyncratic_shocks\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"port_type = PortfolioConsumerType(**init_portfolio)\n",
"port_type.cycles = 0\n",
"port_type.solve()"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'PortfolioSolution' object has no attribute 'cFunc'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[21], line 7\u001b[0m\n\u001b[1;32m 4\u001b[0m beq_type\u001b[38;5;241m.\u001b[39mTermBeqFac \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m\n\u001b[1;32m 5\u001b[0m beq_type\u001b[38;5;241m.\u001b[39mBeqFac \u001b[38;5;241m=\u001b[39m [\u001b[38;5;241m0\u001b[39m]\n\u001b[0;32m----> 7\u001b[0m \u001b[43mbeq_type\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msolve\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/mambaforge/envs/hark/lib/python3.9/site-packages/HARK/core.py:519\u001b[0m, in \u001b[0;36mAgentType.solve\u001b[0;34m(self, verbose)\u001b[0m\n\u001b[1;32m 513\u001b[0m \u001b[38;5;66;03m# Ignore floating point \"errors\". Numpy calls it \"errors\", but really it's excep-\u001b[39;00m\n\u001b[1;32m 514\u001b[0m \u001b[38;5;66;03m# tions with well-defined answers such as 1.0/0.0 that is np.inf, -1.0/0.0 that is\u001b[39;00m\n\u001b[1;32m 515\u001b[0m \u001b[38;5;66;03m# -np.inf, np.inf/np.inf is np.nan and so on.\u001b[39;00m\n\u001b[1;32m 516\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m np\u001b[38;5;241m.\u001b[39merrstate(\n\u001b[1;32m 517\u001b[0m divide\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mignore\u001b[39m\u001b[38;5;124m\"\u001b[39m, over\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mignore\u001b[39m\u001b[38;5;124m\"\u001b[39m, under\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mignore\u001b[39m\u001b[38;5;124m\"\u001b[39m, invalid\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mignore\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 518\u001b[0m ):\n\u001b[0;32m--> 519\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpre_solve\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# Do pre-solution stuff\u001b[39;00m\n\u001b[1;32m 520\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msolution \u001b[38;5;241m=\u001b[39m solve_agent(\n\u001b[1;32m 521\u001b[0m \u001b[38;5;28mself\u001b[39m, verbose\n\u001b[1;32m 522\u001b[0m ) \u001b[38;5;66;03m# Solve the model by backward induction\u001b[39;00m\n\u001b[1;32m 523\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpost_solve()\n",
"File \u001b[0;32m~/mambaforge/envs/hark/lib/python3.9/site-packages/HARK/ConsumptionSaving/ConsPortfolioModel.py:188\u001b[0m, in \u001b[0;36mPortfolioConsumerType.pre_solve\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 186\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpre_solve\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[1;32m 187\u001b[0m AgentType\u001b[38;5;241m.\u001b[39mpre_solve(\u001b[38;5;28mself\u001b[39m)\n\u001b[0;32m--> 188\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mupdate_solution_terminal\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/mambaforge/envs/hark/lib/python3.9/site-packages/HARK/ConsumptionSaving/ConsBequestModel.py:141\u001b[0m, in \u001b[0;36mBequestWarmGlowPortfolioType.update_solution_terminal\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 138\u001b[0m BequestWarmGlowConsumerType\u001b[38;5;241m.\u001b[39mupdate_solution_terminal(\u001b[38;5;28mself\u001b[39m)\n\u001b[1;32m 140\u001b[0m \u001b[38;5;66;03m# Consume all market resources: c_T = m_T\u001b[39;00m\n\u001b[0;32m--> 141\u001b[0m cFuncAdj_terminal \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msolution_terminal\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcFunc\u001b[49m\n\u001b[1;32m 142\u001b[0m cFuncFxd_terminal \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mlambda\u001b[39;00m m, s: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msolution_terminal\u001b[38;5;241m.\u001b[39mcFunc(m)\n\u001b[1;32m 144\u001b[0m \u001b[38;5;66;03m# Risky share is irrelevant-- no end-of-period assets; set to zero\u001b[39;00m\n",
"\u001b[0;31mAttributeError\u001b[0m: 'PortfolioSolution' object has no attribute 'cFunc'"
]
}
],
"source": [
"beq_type = BequestWarmGlowPortfolioType(\n",
" **init_portfolio)\n",
"\n",
"beq_type.TermBeqFac = 1\n",
"beq_type.BeqFac = [0]\n",
"\n",
"beq_type.solve()\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "hark",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
148 changes: 3 additions & 145 deletions examples/ConsBequestModel/example_ConsIndShockComp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,78 +18,7 @@
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"GPFRaw = 0.984539 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"GPFNrm = 0.993777 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"GPFAggLivPrb = 0.964848 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Thorn = APF = 0.994384 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"PermGroFacAdj = 1.000611 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"uInvEpShkuInv = 0.990704 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"VAF = 0.932054 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"WRPF = 0.213705 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"DiscFacGPFNrmMax = 0.972061 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"DiscFacGPFAggLivPrbMax = 1.010600 \n"
]
}
],
"outputs": [],
"source": [
"beq_agent = BequestWarmGlowConsumerType(\n",
" **init_idiosyncratic_shocks, TermBeqFac=0.0, BeqFac=0.0\n",
Expand All @@ -102,78 +31,7 @@
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"GPFRaw = 0.984539 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"GPFNrm = 0.993777 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"GPFAggLivPrb = 0.964848 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Thorn = APF = 0.994384 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"PermGroFacAdj = 1.000611 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"uInvEpShkuInv = 0.990704 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"VAF = 0.932054 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"WRPF = 0.213705 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"DiscFacGPFNrmMax = 0.972061 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"DiscFacGPFAggLivPrbMax = 1.010600 \n"
]
}
],
"outputs": [],
"source": [
"ind_agent = IndShockConsumerType(**init_idiosyncratic_shocks)\n",
"ind_agent.cycles = 0\n",
Expand Down Expand Up @@ -227,7 +85,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.9.18"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 501eb2a

Please sign in to comment.