Skip to content

Commit

Permalink
Minor polish.
Browse files Browse the repository at this point in the history
  • Loading branch information
akshayshanker committed Oct 16, 2024
1 parent afb628e commit 88fe518
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions examples/ConsNewKeynesianModel/KS-HARK-presentation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"source": [
"### Steady State Capital \n",
"\n",
"Find steady state capital (`K_ss`) and productivity (`Z`) implied by the firm's first order condition and the above steady state values of labor (`L_ss`), the real interest rate (`r_ss`) and output (`Y_ss`). "
"Find steady state capital (`K_ss`) and productivity (`Z`) implied by the firm's first order condition, aggregate resource constraint and the above steady state values of labor (`L_ss`), the real interest rate (`r_ss`) and output (`Y_ss`). "
]
},
{
Expand Down Expand Up @@ -133,9 +133,10 @@
" Y_ss = calibration['Y_ss'] \n",
"\n",
" K, Z = X\n",
" # all RHS have to be 0\n",
"\n",
" # Firms first order condition and aggregate resource constraint\n",
" f = [\n",
" alpha * Z * (K / L_ss) ** (alpha - 1) - delta - r_ss, # r = MPK\n",
" alpha * Z * (K / L_ss) ** (alpha - 1) - delta - r_ss, # r_ss = MPK\n",
" Z * K**alpha * L_ss ** (1 - alpha) - Y_ss, # Y = Z*F(K,L)\n",
" ]\n",
"\n",
Expand Down Expand Up @@ -249,7 +250,6 @@
"source": [
"print(\"--------------------------------------+------------\")\n",
"print(f\"Steady state capital | {K_ss:.4f}\")\n",
"print(f\"Steady state productivity | {Z_ss:.4f}\")\n",
"print(f\"Steady state output | {Y_ss:.4f}\")\n",
"print(f\"Steady state real interest rate | {r_ss:.4f}\")\n",
"print(f\"Steady state wage | {w_ss:.4f}\")\n",
Expand All @@ -263,13 +263,15 @@
"source": [
"## HARK agent\n",
"\n",
"HARK represents solving agent problems where aggregate variables can affect an agent's income process as instances of `NewKeynesianConsumerType`, a subclass of `AgentType` (see [A Gentle Introduction to HARK](https://docs.econ-ark.org/examples/Gentle-Intro/Gentle-Intro-To-HARK.html)).\n",
"HARK represents agent problems where aggregate variables can affect an individual income process as instances of `NewKeynesianConsumerType`, a subclass of `AgentType` (see [A Gentle Introduction to HARK](https://docs.econ-ark.org/examples/Gentle-Intro/Gentle-Intro-To-HARK.html)).\n",
"\n",
"Instances of the `NewKeynesianConsumerType` class contain functions that solve policy functions of optimizing agents and compute Jacobian matrices in response to a policy shocks using the [SSJ toolkit](https://github.com/shade-econ/sequence-jacobian). \n",
"\n",
"**_NOTE:_** `NewKeynesianConsumerType` is still a microeconomic agent solving an income fluctuation problem. The only difference from [`IndShockConsumerType`](https://docs.econ-ark.org/examples/HowWeSolveIndShockConsumerType/HowWeSolveIndShockConsumerType.html) is that additional aggregate labour income variables are passed to the agent's income process. This allows the agent's problem to be defined within a general equilibrium framework such as (but not restricted to) HANK. \n",
"\n",
"**_NOTE:_** Researchers can also create their own agent types by subclassing `AgentType`. See [HARK's documentation](https://docs.econ-ark.org/examples/HowWeSolveIndShockConsumerType/HowWeSolveIndShockConsumerType.html) for more information.\n",
"\n",
"We now create an instance of an agent; first specify the agent's parameters in a dictionary. To start, we use a discount factor of 0.98."
"To create an instance of `NewKeynesianConsumerType`, first specify parameters in a dictionary. To start, we use a discount factor of 0.98."
]
},
{
Expand Down Expand Up @@ -311,7 +313,7 @@
" \"IncUnempRet\": 0.0, # \"Unemployment\" benefits when retired\n",
" \"T_retire\": 0.0, # Period of retirement (0 --> no retirement)\n",
" \n",
" # General equilibrium parameters \n",
" # Aggregates affecting the agent's decision \n",
" \"Rfree\": (1 + r_ss), # Interest factor for assets faced by agents \n",
" \"wage\": [w_ss], # Wage rate faced by agents \n",
" \"tax_rate\": [0], # set to 0.0 because we are going to assume that labor here is actually after tax income\n",
Expand Down Expand Up @@ -339,8 +341,6 @@
"id": "3be9593e",
"metadata": {},
"source": [
"Instances of the `NewKeynesianConsumerType` class contain functions that solve policy functions of optimizing agents and compute Jacobian matrices in response to a policy shocks using the [SSJ toolkit](https://github.com/shade-econ/sequence-jacobian). \n",
"\n",
"Let's create a temporary instance of a `NewKeynesianConsumerType` agent."
]
},
Expand Down Expand Up @@ -387,7 +387,7 @@
"source": [
"### Steady State Assets \n",
"\n",
"We can find `discFac` which clears the asset market given steady state capital demand by the firm of `K_ss`. "
"Since we are interested in computing a steady state equilibrium, we find `discFac` such that `A_ss` clears the asset market given that `K_ss` is the steady state firm capital demand. "
]
},
{
Expand Down Expand Up @@ -498,9 +498,9 @@
"source": [
"# Computing Jacobians using SSJ\n",
"\n",
"With the steady state agent in hand, we can compute the Jacobians of the steady state HANK agent's policy functions with respect to the aggregate state variables!\n",
"With the steady state agent in hand, we can compute the Jacobians of the steady state HANK agent's policy with respect to the aggregate state variables.\n",
"\n",
"The `calc_jacobian` method of our HANK agent computes the Jacobians of the steady state aggregate consumption (`CJACW`) and assets (`AJACW`) with respect to a pertubation of the specified variable.\n",
"The `calc_jacobian` method of our `NewKeynesianConsumerType` agent computes the Jacobians of the steady state aggregate consumption (`CJACW`) and assets (`AJACW`) with respect to a pertubation of a specified variable.\n",
"\n",
"Recall `CJACW[s,t]` is the time $t$ response to a shock at time $s$. \n",
"\n",
Expand Down Expand Up @@ -561,15 +561,15 @@
}
],
"source": [
"plt.plot(CJACW.T[0], label = \"s =0\")\n",
"plt.plot(CJACW.T[0], label = \"s=0\")\n",
"plt.plot(CJACW.T[20], label = 's=20')\n",
"plt.plot(CJACW.T[50], label = 's=50')\n",
"plt.plot(CJACW.T[100], label = 's=100')\n",
"plt.xlim(-2, 300)\n",
"plt.plot(np.arange(300), np.zeros(300), color=\"k\")\n",
"plt.title(\"Consumption Jacobian Wage\")\n",
"plt.xlabel(\"quarters\")\n",
"plt.ylabel(\"C response\")\n",
"plt.title(\"Consumption Jacobian (Wage) \")\n",
"plt.xlabel(\"Quarters\")\n",
"plt.ylabel(\"Consumption response\")\n",
"plt.legend()\n",
"plt.show()"
]
Expand Down Expand Up @@ -603,6 +603,14 @@
"print(f\"Time taken to compute return factor Jacobians: {time.time() - start:.3f} seconds\")"
]
},
{
"cell_type": "markdown",
"id": "311a3a60",
"metadata": {},
"source": [
"Here is an example where we shock the return factor. "
]
},
{
"cell_type": "code",
"execution_count": 17,
Expand Down Expand Up @@ -633,9 +641,9 @@
"plt.plot(CJACR.T[50], label = 's=50')\n",
"plt.plot(CJACR.T[100], label = 's=100')\n",
"plt.plot(np.arange(300), np.zeros(300), color=\"k\")\n",
"plt.title(\"Consumption Jacobian interest rate\")\n",
"plt.xlabel(\"quarters\")\n",
"plt.ylabel(\"C response\")\n",
"plt.title(\"Consumption Jacobian (Return Factor)\")\n",
"plt.xlabel(\"Quarters\")\n",
"plt.ylabel(\"Consumption response\")\n",
"plt.show()"
]
},
Expand Down

0 comments on commit 88fe518

Please sign in to comment.