{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### DEMDP01b\n", "# Timber Harvesting -- using cubic splines" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from compecon import NLP, demo, BasisSpline\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "price = 1.0 # price of biomass\n", "kappa = 0.2 # clearcut-replant cost\n", "smax = 0.5 # stand carrying capacity\n", "gamma = 0.1 # biomass growth parameter\n", "delta = 0.9 # discount factor" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Code the growth function" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## SOLUTION\n", "\n", "### Code the approximant and the residual" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Value function" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Conditional value functions" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Residual" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Solve collocation equation" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Compute critical biomass" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## ANALYSIS" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Compute refined state grid" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ss = np.linspace(0,smax,1000)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Plot Conditional Value Functions" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig1 =demo.figure('Conditional Value Functions','Biomass','Value of Stand')\n", "plt.plot(ss,vhat0(ss),label='Grow')\n", "plt.plot(ss,vhat1(ss),label='Clear-Cut')\n", "plt.legend()\n", "\n", "vcrit = vhat(scrit)\n", "ymin = plt.ylim()[0]\n", "plt.vlines(scrit, ymin,vcrit,'grey',linestyles='--')\n", "demo.annotate(scrit,ymin,'$s^*$',ms=10)\n", "demo.bullet(scrit,vcrit)\n", "print(f'Optimal Biomass Harvest Level = {scrit:.4f}') " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Plot Value Function Residual" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig2 = demo.figure('Bellman Equation Residual', 'Biomass', 'Percent Residual')\n", "plt.plot(ss, 100*resid(cc,ss) / vhat(ss))\n", "plt.hlines(0,0,smax,linestyles='--')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Compute ergodic mean annual harvest " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s = h(0)\n", "for n in range(100):\n", " if s > scrit: break\n", " s = h(s)\n", " \n", "print(f'Ergodic Mean Annual Harvest = {s/n:.4f} after {n+1} iterations') " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#demo.savefig([fig1,fig2])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }