{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "
\n", " \n", " \"QuantEcon\"\n", " \n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Default Risk and Income Fluctuations" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Contents\n", "\n", "- [Default Risk and Income Fluctuations](#Default-Risk-and-Income-Fluctuations) \n", " - [Overview](#Overview) \n", " - [Structure](#Structure) \n", " - [Equilibrium](#Equilibrium) \n", " - [Computation](#Computation) \n", " - [Results](#Results) \n", " - [Exercises](#Exercises) \n", " - [Solutions](#Solutions) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In addition to what’s in Anaconda, this lecture will need the following libraries:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": true }, "outputs": [], "source": [ "!pip install --upgrade quantecon" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Overview\n", "\n", "This lecture computes versions of Arellano’s [[Are08]](https://python-programming.quantecon.org/zreferences.html#arellano2008default) model of sovereign\n", "default.\n", "\n", "The model describes interactions among default risk, output, and an equilibrium interest rate that\n", "includes a premium for endogenous default risk.\n", "\n", "The decision maker is a government of a small open economy that borrows from risk-neutral foreign\n", "creditors.\n", "\n", "The foreign lenders must be compensated for default risk.\n", "\n", "The government borrows and lends abroad in order to smooth the consumption of its citizens.\n", "\n", "The government repays its debt only if it wants to, but declining to pay has adverse consequences.\n", "\n", "The interest rate on government debt adjusts in response to the state-dependent default probability\n", "chosen by government.\n", "\n", "The model yields outcomes that help interpret sovereign default experiences, including\n", "\n", "- countercyclical interest rates on sovereign debt \n", "- countercyclical trade balances \n", "- high volatility of consumption relative to output \n", "\n", "\n", "Notably, long recessions caused by bad draws in the income process increase the government’s\n", "incentive to default.\n", "\n", "This can lead to\n", "\n", "- spikes in interest rates \n", "- temporary losses of access to international credit markets \n", "- large drops in output, consumption, and welfare \n", "- large capital outflows during recessions \n", "\n", "\n", "Such dynamics are consistent with experiences of many countries.\n", "\n", "Let’s start with some imports:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import quantecon as qe\n", "import random\n", "\n", "from numba import jit, int64, float64\n", "from numba.experimental import jitclass\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Structure\n", "\n", "In this section we describe the main features of the model." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Output, Consumption and Debt\n", "\n", "A small open economy is endowed with an exogenous stochastically fluctuating potential output\n", "stream $ \\{y_t\\} $.\n", "\n", "Potential output is realized only in periods in which the government honors its sovereign debt.\n", "\n", "The output good can be traded or consumed.\n", "\n", "The sequence $ \\{y_t\\} $ is described by a Markov process with stochastic density kernel\n", "$ p(y, y') $.\n", "\n", "Households within the country are identical and rank stochastic consumption streams according to\n", "\n", "\n", "\n", "$$\n", "\\mathbb E \\sum_{t=0}^{\\infty} \\beta^t u(c_t) \\tag{1}\n", "$$\n", "\n", "Here\n", "\n", "- $ 0 < \\beta < 1 $ is a time discount factor \n", "- $ u $ is an increasing and strictly concave utility function \n", "\n", "\n", "Consumption sequences enjoyed by households are affected by the government’s decision to borrow or\n", "lend internationally.\n", "\n", "The government is benevolent in the sense that its aim is to maximize [(1)](#equation-utility).\n", "\n", "The government is the only domestic actor with access to foreign credit.\n", "\n", "Because household are averse to consumption fluctuations, the government will try to smooth\n", "consumption by borrowing from (and lending to) foreign creditors." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Asset Markets\n", "\n", "The only credit instrument available to the government is a one-period bond traded in international credit markets.\n", "\n", "The bond market has the following features\n", "\n", "- The bond matures in one period and is not state contingent. \n", "- A purchase of a bond with face value $ B' $ is a claim to $ B' $ units of the\n", " consumption good next period. \n", "- To purchase $ B' $ next period costs $ q B' $ now, or, what is equivalent. \n", "- For selling $ -B' $ units of next period goods the seller earns $ - q B' $ of today’s\n", " goods. \n", " - If $ B' < 0 $, then $ -q B' $ units of the good are received in the current period,\n", " for a promise to repay $ -B' $ units next period. \n", " - There is an equilibrium price function $ q(B', y) $ that makes $ q $ depend on both\n", " $ B' $ and $ y $. \n", "\n", "\n", "Earnings on the government portfolio are distributed (or, if negative, taxed) lump sum to\n", "households.\n", "\n", "When the government is not excluded from financial markets, the one-period national budget\n", "constraint is\n", "\n", "\n", "\n", "$$\n", "c = y + B - q(B', y) B' \\tag{2}\n", "$$\n", "\n", "Here and below, a prime denotes a next period value or a claim maturing next period.\n", "\n", "To rule out Ponzi schemes, we also require that $ B \\geq -Z $ in every period.\n", "\n", "- $ Z $ is chosen to be sufficiently large that the constraint never binds in equilibrium. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Financial Markets\n", "\n", "Foreign creditors\n", "\n", "- are risk neutral \n", "- know the domestic output stochastic process $ \\{y_t\\} $ and observe\n", " $ y_t, y_{t-1}, \\ldots, $ at time $ t $ \n", "- can borrow or lend without limit in an international credit market at a constant international\n", " interest rate $ r $ \n", "- receive full payment if the government chooses to pay \n", "- receive zero if the government defaults on its one-period debt due \n", "\n", "\n", "When a government is expected to default next period with probability $ \\delta $, the expected\n", "value of a promise to pay one unit of consumption next period is $ 1 - \\delta $.\n", "\n", "Therefore, the discounted expected value of a promise to pay $ B $ next period is\n", "\n", "\n", "\n", "$$\n", "q = \\frac{1 - \\delta}{1 + r} \\tag{3}\n", "$$\n", "\n", "Next we turn to how the government in effect chooses the default probability $ \\delta $." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Government’s Decisions\n", "\n", "At each point in time $ t $, the government chooses between\n", "\n", "1. defaulting \n", "1. meeting its current obligations and purchasing or selling an optimal quantity of one-period\n", " sovereign debt \n", "\n", "\n", "Defaulting means declining to repay all of its current obligations.\n", "\n", "If the government defaults in the current period, then consumption equals current output.\n", "\n", "But a sovereign default has two consequences:\n", "\n", "1. Output immediately falls from $ y $ to $ h(y) $, where $ 0 \\leq h(y) \\leq y $. \n", " - It returns to $ y $ only after the country regains access to international credit\n", " markets. \n", "1. The country loses access to foreign credit markets. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Reentering International Credit Market\n", "\n", "While in a state of default, the economy regains access to foreign credit in each subsequent\n", "period with probability $ \\theta $." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Equilibrium\n", "\n", "Informally, an equilibrium is a sequence of interest rates on its sovereign debt, a stochastic\n", "sequence of government default decisions and an implied flow of household consumption such that\n", "\n", "1. Consumption and assets satisfy the national budget constraint. \n", "1. The government maximizes household utility taking into account \n", " - the resource constraint \n", " - the effect of its choices on the price of bonds \n", " - consequences of defaulting now for future net output and future borrowing and lending\n", " opportunities \n", "1. The interest rate on the government’s debt includes a risk-premium sufficient to make foreign\n", " creditors expect on average to earn the constant risk-free international interest rate. \n", "\n", "\n", "To express these ideas more precisely, consider first the choices of the government, which\n", "\n", "1. enters a period with initial assets $ B $, or what is the same thing, initial debt to be\n", " repaid now of $ -B $ \n", "1. observes current output $ y $, and \n", "1. chooses either \n", " 1. to default, or \n", " 1. to pay $ -B $ and set next period’s debt due to $ -B' $ \n", "\n", "\n", "In a recursive formulation,\n", "\n", "- state variables for the government comprise the pair $ (B, y) $ \n", "- $ v(B, y) $ is the optimum value of the government’s problem when at the beginning of a\n", " period it faces the choice of whether to honor or default \n", "- $ v_c(B, y) $ is the value of choosing to pay obligations falling due \n", "- $ v_d(y) $ is the value of choosing to default \n", "\n", "\n", "$ v_d(y) $ does not depend on $ B $ because, when access to credit is eventually regained,\n", "net foreign assets equal $ 0 $.\n", "\n", "Expressed recursively, the value of defaulting is\n", "\n", "$$\n", "v_d(y) = u(h(y)) +\n", " \\beta \\int \\left\\{\n", " \\theta v(0, y') + (1 - \\theta) v_d(y')\n", " \\right\\}\n", " p(y, y') dy'\n", "$$\n", "\n", "The value of paying is\n", "\n", "$$\n", "v_c(B, y) = \\max_{B' \\geq -Z}\n", " \\left\\{\n", " u(y - q(B', y) B' + B) +\n", " \\beta \\int v(B', y') p(y, y') dy'\n", " \\right\\}\n", "$$\n", "\n", "The three value functions are linked by\n", "\n", "$$\n", "v(B, y) = \\max\\{ v_c(B, y), v_d(y) \\}\n", "$$\n", "\n", "The government chooses to default when\n", "\n", "$$\n", "v_c(B, y) < v_d(y)\n", "$$\n", "\n", "and hence given $ B' $ the probability of default next period is\n", "\n", "\n", "\n", "$$\n", "\\delta(B', y) := \\int \\mathbb 1\\{v_c(B', y') < v_d(y') \\} p(y, y') dy' \\tag{4}\n", "$$\n", "\n", "Given zero profits for foreign creditors in equilibrium, we can combine [(3)](#equation-epc) and [(4)](#equation-delta)\n", "to pin down the bond price function:\n", "\n", "\n", "\n", "$$\n", "q(B', y) = \\frac{1 - \\delta(B', y)}{1 + r} \\tag{5}\n", "$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Definition of Equilibrium\n", "\n", "An *equilibrium* is\n", "\n", "- a pricing function $ q(B',y) $, \n", "- a triple of value functions $ (v_c(B, y), v_d(y), v(B,y)) $, \n", "- a decision rule telling the government when to default and when to pay as a function of the state\n", " $ (B, y) $, and \n", "- an asset accumulation rule that, conditional on choosing not to default, maps $ (B,y) $ into\n", " $ B' $ \n", "\n", "\n", "such that\n", "\n", "- The three Bellman equations for $ (v_c(B, y), v_d(y), v(B,y)) $ are satisfied \n", "- Given the price function $ q(B',y) $, the default decision rule and the asset accumulation\n", " decision rule attain the optimal value function $ v(B,y) $, and \n", "- The price function $ q(B',y) $ satisfies equation [(5)](#equation-bondprice) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Computation\n", "\n", "Let’s now compute an equilibrium of Arellano’s model.\n", "\n", "The equilibrium objects are the value function $ v(B, y) $, the associated\n", "default decision rule, and the pricing function $ q(B', y) $.\n", "\n", "We’ll use our code to replicate Arellano’s results.\n", "\n", "After that we’ll perform some additional simulations.\n", "\n", "We use a slightly modified version of the algorithm recommended by Arellano.\n", "\n", "- The appendix to [[Are08]](https://python-programming.quantecon.org/zreferences.html#arellano2008default) recommends value function iteration until\n", " convergence, updating the price, and then repeating. \n", "- Instead, we update the bond price at every value function iteration step. \n", "\n", "\n", "The second approach is faster and the two different procedures deliver very similar results.\n", "\n", "Here is a more detailed description of our algorithm:\n", "\n", "1. Guess a value function $ v(B, y) $ and price function $ q(B', y) $. \n", "1. At each pair $ (B, y) $, \n", " - update the value of defaulting $ v_d(y) $. \n", " - update the value of continuing $ v_c(B, y) $. \n", "1. Update the value function $ v(B, y) $, the default rule, the implied ex ante default\n", " probability, and the price function. \n", "1. Check for convergence. If converged, stop – if not, go to step 2. \n", "\n", "\n", "We use simple discretization on a grid of asset holdings and income levels.\n", "\n", "The output process is discretized using [Tauchen’s quadrature method](https://github.com/QuantEcon/QuantEcon.py/blob/master/quantecon/markov/approximation.py).\n", "\n", "As we have in other places, we will accelerate our code using Numba.\n", "\n", "We start by defining the data structure that will help us compile the class\n", "(for more information on why we do this, see the [lecture on numba](https://python-programming.quantecon.org/numba.html).)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Define the data information for the jitclass\n", "arellano_data = [\n", " ('B', float64[:]), ('P', float64[:, :]), ('y', float64[:]),\n", " ('β', float64), ('γ', float64), ('r', float64),\n", " ('ρ', float64), ('η', float64), ('θ', float64),\n", " ('def_y', float64[:])\n", "]\n", "\n", "# Define utility function\n", "@jit(nopython=True)\n", "def u(c, γ):\n", " return c**(1-γ)/(1-γ)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We then define our `jitclass` that will store various parameters and contain the code that can apply the Bellman operators and determine the savings policy given prices and value functions" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "@jitclass(arellano_data)\n", "class Arellano_Economy:\n", " \"\"\"\n", " Arellano 2008 deals with a small open economy whose government\n", " invests in foreign assets in order to smooth the consumption of\n", " domestic households. Domestic households receive a stochastic\n", " path of income.\n", "\n", " Parameters\n", " ----------\n", " B : vector(float64)\n", " A grid for bond holdings\n", " P : matrix(float64)\n", " The transition matrix for a country's output\n", " y : vector(float64)\n", " The possible output states\n", " β : float\n", " Time discounting parameter\n", " γ : float\n", " Risk-aversion parameter\n", " r : float\n", " int lending rate\n", " ρ : float\n", " Persistence in the income process\n", " η : float\n", " Standard deviation of the income process\n", " θ : float\n", " Probability of re-entering financial markets in each period\n", " \"\"\"\n", "\n", " def __init__(\n", " self, B, P, y,\n", " β=0.953, γ=2.0, r=0.017,\n", " ρ=0.945, η=0.025, θ=0.282\n", " ):\n", "\n", " # Save parameters\n", " self.B, self.P, self.y = B, P, y\n", " self.β, self.γ, self.r, = β, γ, r\n", " self.ρ, self.η, self.θ = ρ, η, θ\n", "\n", " # Compute the mean output\n", " self.def_y = np.minimum(0.969 * np.mean(y), y)\n", "\n", " def bellman_default(self, iy, EVd, EV):\n", " \"\"\"\n", " The RHS of the Bellman equation when the country is in a\n", " defaulted state on their debt\n", " \"\"\"\n", " # Unpack certain parameters for simplification\n", " β, γ, θ = self.β, self.γ, self.θ\n", "\n", " # Compute continuation value\n", " zero_ind = len(self.B) // 2\n", " cont_value = θ * EV[iy, zero_ind] + (1 - θ) * EVd[iy]\n", "\n", " return u(self.def_y[iy], γ) + β*cont_value\n", "\n", " def bellman_nondefault(self, iy, iB, q, EV, iB_tp1_star=-1):\n", " \"\"\"\n", " The RHS of the Bellman equation when the country is not in a\n", " defaulted state on their debt\n", " \"\"\"\n", " # Unpack certain parameters for simplification\n", " β, γ, θ = self.β, self.γ, self.θ\n", " B, y = self.B, self.y\n", "\n", " # Compute the RHS of Bellman equation\n", " if iB_tp1_star < 0:\n", " iB_tp1_star = self.compute_savings_policy(iy, iB, q, EV)\n", " c = max(y[iy] - q[iy, iB_tp1_star]*B[iB_tp1_star] + B[iB], 1e-14)\n", "\n", " return u(c, γ) + β*EV[iy, iB_tp1_star]\n", "\n", " def compute_savings_policy(self, iy, iB, q, EV):\n", " \"\"\"\n", " Finds the debt/savings that maximizes the value function\n", " for a particular state given prices and a value function\n", " \"\"\"\n", " # Unpack certain parameters for simplification\n", " β, γ, θ = self.β, self.γ, self.θ\n", " B, y = self.B, self.y\n", "\n", " # Compute the RHS of Bellman equation\n", " current_max = -1e14\n", " iB_tp1_star = 0\n", " for iB_tp1, B_tp1 in enumerate(B):\n", " c = max(y[iy] - q[iy, iB_tp1]*B[iB_tp1] + B[iB], 1e-14)\n", " m = u(c, γ) + β*EV[iy, iB_tp1]\n", "\n", " if m > current_max:\n", " iB_tp1_star = iB_tp1\n", " current_max = m\n", "\n", " return iB_tp1_star" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can now write a function that will use this class to compute the solution to our model" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "@jit(nopython=True)\n", "def solve(model, tol=1e-8, maxiter=10_000):\n", " \"\"\"\n", " Given an Arellano_Economy type, this function computes the optimal\n", " policy and value functions\n", " \"\"\"\n", " # Unpack certain parameters for simplification\n", " β, γ, r, θ = model.β, model.γ, model.r, model.θ\n", " B = np.ascontiguousarray(model.B)\n", " P, y = np.ascontiguousarray(model.P), np.ascontiguousarray(model.y)\n", " nB, ny = B.size, y.size\n", "\n", " # Allocate space\n", " iBstar = np.zeros((ny, nB), int64)\n", " default_prob = np.zeros((ny, nB))\n", " default_states = np.zeros((ny, nB))\n", " q = np.ones((ny, nB)) * 0.95\n", " Vd = np.zeros(ny)\n", " Vc, V, Vupd = np.zeros((ny, nB)), np.zeros((ny, nB)), np.zeros((ny, nB))\n", "\n", " it = 0\n", " dist = 10.0\n", " while (it < maxiter) and (dist > tol):\n", "\n", " # Compute expectations used for this iteration\n", " EV = P@V\n", " EVd = P@Vd\n", "\n", " for iy in range(ny):\n", " # Update value function for default state\n", " Vd[iy] = model.bellman_default(iy, EVd, EV)\n", "\n", " for iB in range(nB):\n", " # Update value function for non-default state\n", " iBstar[iy, iB] = model.compute_savings_policy(iy, iB, q, EV)\n", " Vc[iy, iB] = model.bellman_nondefault(iy, iB, q, EV, iBstar[iy, iB])\n", "\n", " # Once value functions are updated, can combine them to get\n", " # the full value function\n", " Vd_compat = np.reshape(np.repeat(Vd, nB), (ny, nB))\n", " Vupd[:, :] = np.maximum(Vc, Vd_compat)\n", "\n", " # Can also compute default states and update prices\n", " default_states[:, :] = 1.0 * (Vd_compat > Vc)\n", " default_prob[:, :] = P @ default_states\n", " q[:, :] = (1 - default_prob) / (1 + r)\n", "\n", " # Check tolerance etc...\n", " dist = np.max(np.abs(Vupd - V))\n", " V[:, :] = Vupd[:, :]\n", " it += 1\n", "\n", " return V, Vc, Vd, iBstar, default_prob, default_states, q" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and, finally, we write a function that will allow us to simulate the economy once we have the\n", "policy functions" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "def simulate(model, T, default_states, iBstar, q, y_init=None, B_init=None):\n", " \"\"\"\n", " Simulates the Arellano 2008 model of sovereign debt\n", "\n", " Parameters\n", " ----------\n", " model: Arellano_Economy\n", " An instance of the Arellano model with the corresponding parameters\n", " T: integer\n", " The number of periods that the model should be simulated\n", " default_states: array(float64, 2)\n", " A matrix of 0s and 1s that denotes whether the country was in\n", " default on their debt in that period (default = 1)\n", " iBstar: array(float64, 2)\n", " A matrix which specifies the debt/savings level that a country holds\n", " during a given state\n", " q: array(float64, 2)\n", " A matrix that specifies the price at which a country can borrow/save\n", " for a given state\n", " y_init: integer\n", " Specifies which state the income process should start in\n", " B_init: integer\n", " Specifies which state the debt/savings state should start\n", "\n", " Returns\n", " -------\n", " y_sim: array(float64, 1)\n", " A simulation of the country's income\n", " B_sim: array(float64, 1)\n", " A simulation of the country's debt/savings\n", " q_sim: array(float64, 1)\n", " A simulation of the price required to have an extra unit of\n", " consumption in the following period\n", " default_sim: array(bool, 1)\n", " A simulation of whether the country was in default or not\n", " \"\"\"\n", " # Find index i such that Bgrid[i] is approximately 0\n", " zero_B_index = np.searchsorted(model.B, 0.0)\n", "\n", " # Set initial conditions\n", " in_default = False\n", " max_y_default = 0.969 * np.mean(model.y)\n", " if y_init == None:\n", " y_init = np.searchsorted(model.y, model.y.mean())\n", " if B_init == None:\n", " B_init = zero_B_index\n", "\n", " # Create Markov chain and simulate income process\n", " mc = qe.MarkovChain(model.P, model.y)\n", " y_sim_indices = mc.simulate_indices(T+1, init=y_init)\n", "\n", " # Allocate memory for remaining outputs\n", " Bi = B_init\n", " B_sim = np.empty(T)\n", " y_sim = np.empty(T)\n", " q_sim = np.empty(T)\n", " default_sim = np.empty(T, dtype=bool)\n", "\n", " # Perform simulation\n", " for t in range(T):\n", " yi = y_sim_indices[t]\n", "\n", " # Fill y/B for today\n", " if not in_default:\n", " y_sim[t] = model.y[yi]\n", " else:\n", " y_sim[t] = np.minimum(model.y[yi], max_y_default)\n", " B_sim[t] = model.B[Bi]\n", " default_sim[t] = in_default\n", "\n", " # Check whether in default and branch depending on that state\n", " if not in_default:\n", " if default_states[yi, Bi] > 1e-4:\n", " in_default=True\n", " Bi_next = zero_B_index\n", " else:\n", " Bi_next = iBstar[yi, Bi]\n", " else:\n", " Bi_next = zero_B_index\n", " if np.random.rand() < model.θ:\n", " in_default=False\n", "\n", " # Fill in states\n", " q_sim[t] = q[yi, Bi_next]\n", " Bi = Bi_next\n", "\n", " return y_sim, B_sim, q_sim, default_sim" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Results\n", "\n", "Let’s start by trying to replicate the results obtained in [[Are08]](https://python-programming.quantecon.org/zreferences.html#arellano2008default).\n", "\n", "In what follows, all results are computed using Arellano’s parameter values.\n", "\n", "The values can be seen in the `__init__` method of the `Arellano_Economy` shown above.\n", "\n", "- For example, `r=0.017` matches the average quarterly rate on a 5 year US treasury over the\n", " period 1983–2001. \n", "\n", "\n", "Details on how to compute the figures are reported as solutions to the exercises.\n", "\n", "The first figure shows the bond price schedule and replicates Figure 3 of Arellano, where\n", "$ y_L $ and $ Y_H $ are particular below average and above average values of output\n", "$ y $.\n", "\n", "\n", "\n", " \n", "- $ y_L $ is 5% below the mean of the $ y $ grid values \n", "- $ y_H $ is 5% above the mean of the $ y $ grid values \n", "\n", "\n", "The grid used to compute this figure was relatively coarse (`ny, nB = 21, 251`) in order to\n", "match Arrelano’s findings.\n", "\n", "Here’s the same relationships computed on a finer grid (`ny, nB = 51, 551`)\n", "\n", "\n", "\n", " \n", "In either case, the figure shows that\n", "\n", "- Higher levels of debt (larger $ -B' $) induce larger discounts on the face value, which\n", " correspond to higher interest rates. \n", "- Lower income also causes more discounting, as foreign creditors anticipate greater likelihood\n", " of default. \n", "\n", "\n", "The next figure plots value functions and replicates the right hand panel of Figure 4 of\n", "[[Are08]](https://python-programming.quantecon.org/zreferences.html#arellano2008default).\n", "\n", "\n", "\n", " \n", "We can use the results of the computation to study the default probability $ \\delta(B', y) $\n", "defined in [(4)](#equation-delta).\n", "\n", "The next plot shows these default probabilities over $ (B', y) $ as a heat map.\n", "\n", "\n", "\n", " \n", "As anticipated, the probability that the government chooses to default in the following period\n", "increases with indebtedness and falls with income.\n", "\n", "Next let’s run a time series simulation of $ \\{y_t\\} $, $ \\{B_t\\} $ and $ q(B_{t+1}, y_t) $.\n", "\n", "The grey vertical bars correspond to periods when the economy is excluded from financial markets because of a past default.\n", "\n", "\n", "\n", " \n", "One notable feature of the simulated data is the nonlinear response of interest rates.\n", "\n", "Periods of relative stability are followed by sharp spikes in the discount rate on government debt." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercises\n", "\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 1\n", "\n", "To the extent that you can, replicate the figures shown above\n", "\n", "- Use the parameter values listed as defaults in the `__init__` method of the `Arellano_Economy`. \n", "- The time series will of course vary depending on the shock draws. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Solutions\n", "\n", "Compute the value function, policy and equilibrium prices" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "β, γ, r = 0.953, 2.0, 0.017\n", "ρ, η, θ = 0.945, 0.025, 0.282\n", "ny = 21\n", "nB = 251\n", "Bgrid = np.linspace(-0.45, 0.45, nB)\n", "mc = qe.markov.tauchen(ρ, η, 0, 3, ny)\n", "ygrid, P = np.exp(mc.state_values), mc.P\n", "\n", "ae = Arellano_Economy(\n", " Bgrid, P, ygrid, β=β, γ=γ, r=r, ρ=ρ, η=η, θ=θ\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "V, Vc, Vd, iBstar, default_prob, default_states, q = solve(ae)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compute the bond price schedule as seen in figure 3 of Arellano (2008)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Create \"Y High\" and \"Y Low\" values as 5% devs from mean\n", "high, low = np.mean(ae.y) * 1.05, np.mean(ae.y) * .95\n", "iy_high, iy_low = (np.searchsorted(ae.y, x) for x in (high, low))\n", "\n", "fig, ax = plt.subplots(figsize=(10, 6.5))\n", "ax.set_title(\"Bond price schedule $q(y, B')$\")\n", "\n", "# Extract a suitable plot grid\n", "x = []\n", "q_low = []\n", "q_high = []\n", "for i in range(nB):\n", " b = ae.B[i]\n", " if -0.35 <= b <= 0: # To match fig 3 of Arellano\n", " x.append(b)\n", " q_low.append(q[iy_low, i])\n", " q_high.append(q[iy_high, i])\n", "ax.plot(x, q_high, label=\"$y_H$\", lw=2, alpha=0.7)\n", "ax.plot(x, q_low, label=\"$y_L$\", lw=2, alpha=0.7)\n", "ax.set_xlabel(\"$B'$\")\n", "ax.legend(loc='upper left', frameon=False)\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Draw a plot of the value functions" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Create \"Y High\" and \"Y Low\" values as 5% devs from mean\n", "high, low = np.mean(ae.y) * 1.05, np.mean(ae.y) * .95\n", "iy_high, iy_low = (np.searchsorted(ae.y, x) for x in (high, low))\n", "\n", "fig, ax = plt.subplots(figsize=(10, 6.5))\n", "ax.set_title(\"Value Functions\")\n", "ax.plot(ae.B, V[iy_high], label=\"$y_H$\", lw=2, alpha=0.7)\n", "ax.plot(ae.B, V[iy_low], label=\"$y_L$\", lw=2, alpha=0.7)\n", "ax.legend(loc='upper left')\n", "ax.set(xlabel=\"$B$\", ylabel=\"$V(y, B)$\")\n", "ax.set_xlim(ae.B.min(), ae.B.max())\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Draw a heat map for default probability" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "xx, yy = ae.B, ae.y\n", "zz = default_prob\n", "\n", "# Create figure\n", "fig, ax = plt.subplots(figsize=(10, 6.5))\n", "hm = ax.pcolormesh(xx, yy, zz)\n", "cax = fig.add_axes([.92, .1, .02, .8])\n", "fig.colorbar(hm, cax=cax)\n", "ax.axis([xx.min(), 0.05, yy.min(), yy.max()])\n", "ax.set(xlabel=\"$B'$\", ylabel=\"$y$\", title=\"Probability of Default\")\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plot a time series of major variables simulated from the model" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide-output": false }, "outputs": [], "source": [ "T = 250\n", "\n", "np.random.seed(42)\n", "y_vec, B_vec, q_vec, default_vec = simulate(ae, T, default_states, iBstar, q)\n", "\n", "# Pick up default start and end dates\n", "start_end_pairs = []\n", "i = 0\n", "while i < len(default_vec):\n", " if default_vec[i] == 0:\n", " i += 1\n", " else:\n", " # If we get to here we're in default\n", " start_default = i\n", " while i < len(default_vec) and default_vec[i] == 1:\n", " i += 1\n", " end_default = i - 1\n", " start_end_pairs.append((start_default, end_default))\n", "\n", "plot_series = (y_vec, B_vec, q_vec)\n", "titles = 'output', 'foreign assets', 'bond price'\n", "\n", "fig, axes = plt.subplots(len(plot_series), 1, figsize=(10, 12))\n", "fig.subplots_adjust(hspace=0.3)\n", "\n", "for ax, series, title in zip(axes, plot_series, titles):\n", " # Determine suitable y limits\n", " s_max, s_min = max(series), min(series)\n", " s_range = s_max - s_min\n", " y_max = s_max + s_range * 0.1\n", " y_min = s_min - s_range * 0.1\n", " ax.set_ylim(y_min, y_max)\n", " for pair in start_end_pairs:\n", " ax.fill_between(pair, (y_min, y_min), (y_max, y_max),\n", " color='k', alpha=0.3)\n", " ax.grid()\n", " ax.plot(range(T), series, lw=2, alpha=0.7)\n", " ax.set(title=title, xlabel=\"time\")\n", "\n", "plt.show()" ] } ], "metadata": { "date": 1624431169.7652407, "filename": "arellano.rst", "kernelspec": { "display_name": "Python", "language": "python3", "name": "python3" }, "next_doc": { "link": "matsuyama", "title": "Globalization and Cycles" }, "prev_doc": { "link": "rob_markov_perf", "title": "Robust Markov Perfect Equilibrium" }, "title": "Default Risk and Income Fluctuations" }, "nbformat": 4, "nbformat_minor": 2 }