{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Draw Shock Grid\n\nIn this example, we draw shock grids.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Author: Fan Wang (fanwangecon.github.io)\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport pyfan.gen.rand.randgrid as pyfan_gen_rand"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Shared parameters\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fl_mu = 0\nfl_sd = 1\nit_draws = 25\nit_seed = 123\nfl_lower_sd = -2\nfl_higher_sd = 2"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Type 0 Shock draw\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "it_draw_type = 0\nar_shock_t0 = \\\n    pyfan_gen_rand.ar_draw_random_normal(fl_mu, fl_sd, it_draws,\n                                         it_seed, it_draw_type,\n                                         fl_lower_sd, fl_higher_sd)\nprint('it_draw_type=0')\nprint(ar_shock_t0)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Type 1 Shock draw\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "it_draw_type = 1\nar_shock_t1 = \\\n    pyfan_gen_rand.ar_draw_random_normal(fl_mu, fl_sd, it_draws,\n                                         it_seed, it_draw_type,\n                                         fl_lower_sd, fl_higher_sd)\nprint('it_draw_type=1')\nprint(ar_shock_t1)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Type 2 Shock draw\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "it_draw_type = 2\nar_shock_t2 = \\\n    pyfan_gen_rand.ar_draw_random_normal(fl_mu, fl_sd, it_draws,\n                                         it_seed, it_draw_type,\n                                         fl_lower_sd, fl_higher_sd)\nprint('it_draw_type=2')\nprint(ar_shock_t2)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Draw Shocks Jointly\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, ax = plt.subplots()\n# Graph\nar_it_x_grid = np.arange(1, it_draws + 1)\nax.plot(ar_it_x_grid, ar_shock_t0,\n                     color='blue', linestyle='dashed', marker='x',\n                     label='Type 0: Bounded Shock Draws')\nax.scatter(ar_it_x_grid, ar_shock_t1,\n                     color='red',\n                     label='Type 1: Quantile Points')\nax.plot(ar_it_x_grid, ar_shock_t2,\n                     color='black', marker='d',\n                     label='Type 3: Sorted Bounded Shock Draws')\n# Labeling\nax.legend(loc='upper left')\nplt.ylabel('Shock Values')\nplt.xlabel('Shock Draw Points')\nplt.title('Shock, Sorted and Bounded Shocks, Quantile Points')\nplt.grid()\nplt.show()"
      ]
    }
  ],
  "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.8.5"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}