Skip to content

Instantly share code, notes, and snippets.

@sglyon
Last active July 7, 2017 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sglyon/e68d7d55287672b5b4d4dfeaa40178e1 to your computer and use it in GitHub Desktop.
Save sglyon/e68d7d55287672b5b4d4dfeaa40178e1 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [
{
"data": {
"text/html": [
"<p> edited manually </p>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"using Dolang, Dolo, PlotlyJS"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# The Dolo Modeling Framework\n",
"\n",
"**Spencer Lyon**\n",
"\n",
"JuliaCon 2017"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Outline\n",
"\n",
"- Bio\n",
"- Three packages:\n",
" - Dolang.jl: manipulation/compilation of symbolic mathematical expresssions\n",
" - Dolo.jl: rational expectations modeling\n",
" - Dyno.jl: prototype Dynare in Julia\n",
"- Will talk more about tools than economics -- catch me after if you want to talk econ!"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Bio\n",
"\n",
"- 4+ years into PhD in Economics at NYU Stern\n",
"- Live with wife and 3 kids in NYC (UWS)\n",
"- Lead developer/core member of [QuantEcon](https://quantecon.org/) (wrote [Julia libs](https://github.com/QuantEcon?language=julia)/bulit [lecture site](https://lectures.quantecon.org/jl/index.html)\n",
"- Varying activity in Julia community over the last 3 years\n",
" - Authored packages: QuantEcon, PlotlyJS, BasisMatrices, IterationManagers, ...\n",
" - Contributions: Plots, Blink, DSGE, Interpolations, NLsolve, atom-language-julia, ...\n",
" - Help Stefan and Jared Lander run the NYC Julia meetup group"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Dolang.jl\n",
"\n",
"- What is Dolang? Toolbox for working with mathematical objects in symbolic form\n",
"- Symbolic manipulation\n",
" - Substitutions\n",
" - Shifting time periods\n",
" - Symbol extraction\n",
"- Compiler\n",
" - Flexible: multiple methods, allocating/mutating, derivatives, ...\n",
" - Smart: `@generated` symbolic differentiation\n",
"- Used as a building block for DSLs and similar libraries"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Basics: Symbolic manipulation\n",
"\n",
"- These are primitives used to build compiler..."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Dolang.normalize(:x) = :_x_\n",
"Dolang.normalize($(Expr(:quote, :(x + y)))) = :(_x_ + _y_)\n",
"Dolang.normalize($(Expr(:quote, :(x(1))))) = :_x__1_\n",
"Dolang.normalize($(Expr(:quote, :(x(0))))) = :_x__0_\n",
"Dolang.normalize($(Expr(:quote, :(x(-1))))) = :_x_m1_\n"
]
}
],
"source": [
"using Dolang\n",
"@show Dolang.normalize(:x) # symbols\n",
"@show Dolang.normalize(:(x + y)) # expressions with symbols\n",
"@show Dolang.normalize(:(x(1))) # notion of timing\n",
"@show Dolang.normalize(:(x(0))) # current period \n",
"@show Dolang.normalize(:(x(-1))); # previous period"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Dolang.time_shift($(Expr(:quote, :(x + y + z))), 1) = :(x + y + z)\n",
"Dolang.time_shift($(Expr(:quote, :(x(0) + y(1) + z))), 0) = :(x(0) + y(1) + z)\n",
"Dolang.time_shift($(Expr(:quote, :(x(0) + y(1) + z))), 1) = :(x(1) + y(2) + z)\n",
"Dolang.time_shift($(Expr(:quote, :(x(0) + y(1) + z))), -1) = :(x(-1) + y(0) + z)\n"
]
}
],
"source": [
"# time_shift: shift all _timed variables_ by an integer\n",
"@show Dolang.time_shift(:(x + y + z), 1)\n",
"@show Dolang.time_shift(:(x(0) + y(1) + z), 0)\n",
"@show Dolang.time_shift(:(x(0) + y(1) + z), 1)\n",
"@show Dolang.time_shift(:(x(0) + y(1) + z), -1);"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
":(a + (2a) / a)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# csubs: _recursively_ substitue subexpressions\n",
"d = Dict(:b => :(c/a), :c => :(2a))\n",
"csubs(:(a + b), d)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [
{
"data": {
"text/plain": [
":(a + (c(0) + d(1)) + (c(1) + d(2)))"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# interaction with timing\n",
"d2 = Dict(:b => :(c(0) + d(1)))\n",
"csubs(:(a + b(0) + b(1)), d2)"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"### Other functions:\n",
"\n",
"- `steady_state`: shift all timed symbols to time 0\n",
"- `list_symbols`: list all timed and untimed symbols\n",
"- `list_variables`: list all timed symbols\n",
"- `list_parameters`: list all untimed symbols\n",
"- `subs`: direct expression substitution (non-recursive)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Compiler\n",
"\n",
"- Compiles `equations`, `variables` and `parameters` into Julia functions\n",
"- Various methods for each function\n",
" - Allocating\n",
" - Mutating\n",
" - Partially or fully vectorized (similar to broadcasting)\n",
"- Produces \"smart\" `@generated` functions that compile analytical derivatives at runtime"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### Basic Examples\n",
"\n",
"- Compiler implemented as methods on `FunctionFactory` type"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"FunctionFactory\n",
" name: myfun\n",
" # of equations: 2\n",
" # of args: 6\n",
" # of params: 1\n",
" Has targets?: true\n"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"eqs = [\n",
" :(foo(0) = log(a(0))+b(0)/x(-1)),\n",
" :(ping(0) = c(1)+u*d(1))\n",
"]\n",
"defs = Dict(:x=>:(a(0)/(1-c(1))))\n",
"args = [(:a, -1), (:a, 0), (:b, 0), (:c, 0), (:c, 1), (:d, 1)]\n",
"params = [:u]\n",
"targets = [(:foo, 0), (:ping, 0)]\n",
"\n",
"ff = FunctionFactory(\n",
" eqs, args, params, targets=targets, defs=defs, funname=:myfun\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/html": [
"5 methods for generic function <b>myfun</b>:<ul><li> myfun(::<b>Type{Dolang.Der{0}}</b>, V::<b>AbstractArray{T,1} where T</b>, p)</li> <li> myfun<i>{D}</i>(::<b>Type{Dolang.Der{D}}</b>, V::<b>AbstractArray{T,1} where T</b>, p)</li> <li> myfun(V::<b>AbstractArray{T,1} where T</b>, p)</li> <li> myfun(::<b>Type{Dolang.Der{0}}</b>, V::<b>AbstractArray</b>, p)</li> <li> myfun(V::<b>AbstractArray</b>, p)</li> </ul>"
],
"text/plain": [
"# 5 methods for generic function \"myfun\":\n",
"myfun(::Type{Dolang.Der{0}}, V::AbstractArray{T,1} where T, p) in Main\n",
"myfun(::Type{Dolang.Der{D}}, V::AbstractArray{T,1} where T, p) where D in Main\n",
"myfun(V::AbstractArray{T,1} where T, p) in Main\n",
"myfun(::Type{Dolang.Der{0}}, V::AbstractArray, p) in Main\n",
"myfun(V::AbstractArray, p) in Main"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# `make_function` produces code (a Julia Expr) for \n",
"# evaluating our function\n",
"code = make_function(ff) \n",
"\n",
"# need to evaluate it to make function callable\n",
"# could also save to a file and `include` it elsewhere\n",
"eval(code) \n",
"methods(myfun)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/html": [
"5 methods for generic function <b>myfun!</b>:<ul><li> myfun!(::<b>Type{Dolang.Der{0}}</b>, out, V::<b>AbstractArray{T,1} where T</b>, p)</li> <li> myfun!<i>{D}</i>(::<b>Type{Dolang.Der{D}}</b>, out, V::<b>AbstractArray{T,1} where T</b>, p)</li> <li> myfun!(out, V::<b>AbstractArray{T,1} where T</b>, p)</li> <li> myfun!(::<b>Type{Dolang.Der{0}}</b>, out, V::<b>AbstractArray</b>, p)</li> <li> myfun!(out, V::<b>AbstractArray</b>, p)</li> </ul>"
],
"text/plain": [
"# 5 methods for generic function \"myfun!\":\n",
"myfun!(::Type{Dolang.Der{0}}, out, V::AbstractArray{T,1} where T, p) in Main\n",
"myfun!(::Type{Dolang.Der{D}}, out, V::AbstractArray{T,1} where T, p) where D in Main\n",
"myfun!(out, V::AbstractArray{T,1} where T, p) in Main\n",
"myfun!(::Type{Dolang.Der{0}}, out, V::AbstractArray, p) in Main\n",
"myfun!(out, V::AbstractArray, p) in Main"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# methods for mutating version\n",
"methods(myfun!)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"2-element Array{Float64,1}:\n",
" 0.249624\n",
" 3.55 "
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# evaluation\n",
"V = [1.5, 2.5, 1.0, 2.0, 3.0, 1.1]\n",
"p = [0.5]\n",
"myfun(V, p)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2×2 Array{Float64,2}:\n",
" 0.249624 3.55\n",
" 0.249624 3.55"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# vectorized\n",
"myfun([V V]', p) "
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"@allocated(myfun!(out, V, p)) = 0\n"
]
},
{
"data": {
"text/plain": [
"2-element Array{Float64,1}:\n",
" 0.249624\n",
" 3.55 "
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# mutating\n",
"out = zeros(2)\n",
"myfun!(out, V, p) # eval once to jit\n",
"@show @allocated myfun!(out, V, p)\n",
"out"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"2×6 Array{Float64,2}:\n",
" 0.444444 0.4 -0.666667 -0.666667 0.0 0.0\n",
" 0.0 0.0 0.0 0.0 1.0 0.5"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Jacobian (first derivative matrix)\n",
"myfun(Der{1}, V, p)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0.344998 seconds (142.66 k allocations: 7.587 MiB)\n",
" 0.000012 seconds (17 allocations: 2.109 KiB)\n"
]
},
{
"data": {
"text/plain": [
"2×36 SparseMatrixCSC{Float64,Int64} with 8 stored entries:\n",
" [1 , 1] = -0.592593\n",
" [1 , 3] = 0.444444\n",
" [1 , 4] = 0.444444\n",
" [1 , 8] = -0.16\n",
" [1 , 13] = 0.444444\n",
" [1 , 16] = -0.666667\n",
" [1 , 19] = 0.444444\n",
" [1 , 21] = -0.666667"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# second derivative.\n",
"@time myfun(Der{2}, V, p)\n",
"@time myfun(Der{2}, V, p)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Notice time for first call is much slower\n",
"- 2 reasons:\n",
" 1. Actually doing symbolic differentiation upon first call\n",
" 2. Typical jit compilation cost for first evaluation"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0.473450 seconds (205.77 k allocations: 10.211 MiB, 1.74% gc time)\n",
" 0.000011 seconds (13 allocations: 3.688 KiB)\n"
]
},
{
"data": {
"text/plain": [
"2-element Array{Dict{NTuple{10,Int64},Float64},1}:\n",
" Dict((2, 2, 2, 2, 2, 2, 2, 2, 2, 2)=>-38.0507,(1, 1, 1, 1, 1, 1, 1, 1, 1, 3)=>6292.89,(1, 1, 1, 1, 1, 1, 1, 1, 1, 4)=>6292.89,(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)=>-41952.6,(1, 1, 1, 1, 1, 1, 1, 1, 3, 4)=>-1048.82)\n",
" Dict{NTuple{10,Int64},Float64}() "
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 10th derivative \n",
"@time myfun(Der{10}, V, p)\n",
"@time myfun(Der{10}, V, p)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### Example with dispatch arg\n",
"\n",
"- Can optionally specify a type to drive dispatch\n",
"- Allows you to define multiple methods for same function"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/html": [
"10 methods for generic function <b>myfun</b>:<ul><li> myfun(::<b>Type{Dolang.Der{0}}</b>, V::<b>AbstractArray{T,1} where T</b>, p)</li> <li> myfun<i>{D}</i>(::<b>Type{Dolang.Der{D}}</b>, V::<b>AbstractArray{T,1} where T</b>, p)</li> <li> myfun(V::<b>AbstractArray{T,1} where T</b>, p)</li> <li> myfun(::<b>Type{Dolang.Der{0}}</b>, V::<b>AbstractArray</b>, p)</li> <li> myfun(V::<b>AbstractArray</b>, p)</li> <li> myfun(::<b>Type{Dolang.Der{0}}</b>, dispatch::<b>Int64</b>, V::<b>AbstractArray{T,1} where T</b>, p)</li> <li> myfun<i>{D}</i>(::<b>Type{Dolang.Der{D}}</b>, dispatch::<b>Int64</b>, V::<b>AbstractArray{T,1} where T</b>, p)</li> <li> myfun(dispatch::<b>Int64</b>, V::<b>AbstractArray{T,1} where T</b>, p)</li> <li> myfun(::<b>Type{Dolang.Der{0}}</b>, dispatch::<b>Int64</b>, V::<b>AbstractArray</b>, p)</li> <li> myfun(dispatch::<b>Int64</b>, V::<b>AbstractArray</b>, p)</li> </ul>"
],
"text/plain": [
"# 10 methods for generic function \"myfun\":\n",
"myfun(::Type{Dolang.Der{0}}, V::AbstractArray{T,1} where T, p) in Main\n",
"myfun(::Type{Dolang.Der{D}}, V::AbstractArray{T,1} where T, p) where D in Main\n",
"myfun(V::AbstractArray{T,1} where T, p) in Main\n",
"myfun(::Type{Dolang.Der{0}}, V::AbstractArray, p) in Main\n",
"myfun(V::AbstractArray, p) in Main\n",
"myfun(::Type{Dolang.Der{0}}, dispatch::Int64, V::AbstractArray{T,1} where T, p) in Main\n",
"myfun(::Type{Dolang.Der{D}}, dispatch::Int64, V::AbstractArray{T,1} where T, p) where D in Main\n",
"myfun(dispatch::Int64, V::AbstractArray{T,1} where T, p) in Main\n",
"myfun(::Type{Dolang.Der{0}}, dispatch::Int64, V::AbstractArray, p) in Main\n",
"myfun(dispatch::Int64, V::AbstractArray, p) in Main"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"eqs = [\n",
" :(sin(x(0)) + exp(2*x(1))),\n",
" :(y(0) / (2 * (1 - β))),\n",
"]\n",
"# NOTE: Arguments can be pre-normalized and contain unicode\n",
"args = [(:x, 0), (:y, 0), (:x, 1)]\n",
"params = [:β]\n",
"code = make_function(FunctionFactory(Int, eqs, args, params, funname=:myfun))\n",
"eval(code)\n",
"\n",
"# notice new methods that require passing an Int\n",
"methods(myfun)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"2-element Array{Float64,1}:\n",
" 4.95303\n",
" 125.0 "
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"V = [π, 5.0, 0.8]\n",
"p = [0.98] \n",
"myfun(1, V, p)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/html": [
"true"
],
"text/plain": [
"true"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# actual integer doesn't matter\n",
"myfun(42, V, p) == myfun(rand(Int), V, p)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### Example with grouped arguments\n",
"\n",
"- We can also construct functions that take multiple vector arguments"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/html": [
"5 methods for generic function <b>grouped_args</b>:<ul><li> grouped_args(::<b>Type{Dolang.Der{0}}</b>, a::<b>AbstractArray{T,1} where T</b>, b::<b>AbstractArray{T,1} where T</b>, p)</li> <li> grouped_args<i>{D}</i>(::<b>Type{Dolang.Der{D}}</b>, a::<b>AbstractArray{T,1} where T</b>, b::<b>AbstractArray{T,1} where T</b>, p)</li> <li> grouped_args(a::<b>AbstractArray{T,1} where T</b>, b::<b>AbstractArray{T,1} where T</b>, p)</li> <li> grouped_args(::<b>Type{Dolang.Der{0}}</b>, a::<b>AbstractArray</b>, b::<b>AbstractArray</b>, p)</li> <li> grouped_args(a::<b>AbstractArray</b>, b::<b>AbstractArray</b>, p)</li> </ul>"
],
"text/plain": [
"# 5 methods for generic function \"grouped_args\":\n",
"grouped_args(::Type{Dolang.Der{0}}, a::AbstractArray{T,1} where T, b::AbstractArray{T,1} where T, p) in Main\n",
"grouped_args(::Type{Dolang.Der{D}}, a::AbstractArray{T,1} where T, b::AbstractArray{T,1} where T, p) where D in Main\n",
"grouped_args(a::AbstractArray{T,1} where T, b::AbstractArray{T,1} where T, p) in Main\n",
"grouped_args(::Type{Dolang.Der{0}}, a::AbstractArray, b::AbstractArray, p) in Main\n",
"grouped_args(a::AbstractArray, b::AbstractArray, p) in Main"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"eqs = [\n",
" :(sin(x(0)) + exp(2*x(1))),\n",
" :(y(0) / (2 * (1 - β))),\n",
"]\n",
"args = Dict(\n",
" :a => [(:x, 0), (:y, 0)],\n",
" :b => [(:x, 1)]\n",
")\n",
"params = [:β]\n",
"ff2 = FunctionFactory(eqs, args, params, funname=:grouped_args)\n",
"eval(make_function(ff2))\n",
"\n",
"# notice we have args [a, b, p] -- not just [V, p]\n",
"methods(grouped_args) "
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"2-element Array{Float64,1}:\n",
" 4.95303\n",
" 125.0 "
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = [π, 5.0]\n",
"b = [0.8]\n",
"p = [0.98]\n",
"grouped_args(a, b, p)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"2×2 Array{Float64,2}:\n",
" 4.95303 125.0\n",
" 4.11156 150.0"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# partially vectorized (b is repeated for each row of a)\n",
"# similar to broadcasting\n",
"grouped_args([a a+1]', b, p)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0.486266 seconds (226.63 k allocations: 12.029 MiB, 1.85% gc time)\n",
" 0.000010 seconds (7 allocations: 400 bytes)\n"
]
},
{
"data": {
"text/plain": [
"([-1.0 0.0; 0.0 25.0], [9.90606; 0.0])"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# only first derivatives -- note doing differentiation at runtime still\n",
"@time grouped_args(Der{1}, a, b, p)\n",
"@time grouped_args(Der{1}, a, b, p)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### Implementation detail\n",
"\n",
"- How to do symbolic derivatives at runtime?\n",
"- Where to store symbolic data so it is available when derivatives are asked for?\n",
"- We know `FunctionFactory` has all data/knows how to do derivatives..."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"- Solution: _Embed_ instance of `FunctionFactory` in body of `@generated` function"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
":(@generated function anon{D}(::Dolang.TDer{D}, V::AbstractVector, p)\n",
" ff = Dolang.FunctionFactory{Array{Tuple{Symbol,Int64},1},Array{Symbol,1},Dict{Symbol,Any},DataType}(Expr[:(_a_ + _b__0_)], Tuple{Symbol,Int64}[(:b, 0)], Symbol[:a], Symbol[], Dict{Symbol,Any}(), :anon, Dolang.SkipArg, Dolang.IncidenceTable(Dict(1=>Dict(:b=>Set([0]))), Dict(:b=>Set([0])), Dict(0=>Set(Symbol[:b]))))\n",
" Dolang.func_body(ff, Der{D})\n",
" end)"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ff_simple = FunctionFactory([:(a + b(0))], [(:b, 0)], [:a])\n",
"make_function(ff_simple).args[1]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Two lines: (1) embed `ff` and (2) call `Dolang.func_body` with ff\n",
"- Tips:\n",
" - `@generated` functions see _types_ of arguments and return `Expr`s\n",
" - `Dolang.func_body` returns an `Expr` for evaluating the body of the function"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Dolo.jl\n",
"\n",
"- What is Dolo? A library for working with rational expectations models\n",
"- Two main components\n",
" 1. A _language_ for describing models via their key equations\n",
" 2. A reference implementation of various global, non-linear solution algorithms\n",
" - Time iteration (basic, direct, improved)\n",
" - Value function iteration\n",
" - Parameterized expectations\n",
" - Perfect foresight\n",
" - Perturbation (linear)\n",
"- So far no focus on performance, but plan to have algorithms be more efficient than most hand coded\n",
" - Already doing pretty well\n",
" - Optimistic about Julia letting us do this\n",
"- Leverages Dolang as a compiler"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### Why (or, how is it unique)?\n",
"\n",
"- 100% Julia with permissive license ==> easier to use in industry/government settings\n",
"- Models usually written in mathematical notation in YAML files (see example)\n",
" - Match notation used in papers/on whiteboard\n",
" - Separate model _definition_ from _solution_ algorithms (DRY)\n",
"- Automate defining Julia functions for evaluating model equations/derivatives\n",
"- Implements _global_, _non-linear_ algorithms that handle _occasionally binding constraints_ (example later)"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true,
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### Example 1: Sudden stop model\n",
"\n",
"- Simple model of \"sudden stops\" in access to financial markets\n",
"- Shows importance of modeling constraints"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"# This file adapts the model described in\n",
"# \"From Sudden Stops to Fisherian Deflation, Quantitative Theory and Policy\"\n",
"# by Anton Korinek and Enrique G. Mendoza\n",
"\n",
"name: Sudden Stop (AR1)\n",
"model_type: dtcc\n",
"symbols:\n",
" exogenous: [ly]\n",
" states: [l]\n",
" controls: [b, lam]\n",
" parameters: [beta, R, sigma, mu, lam_inf]\n",
"\n",
"\n",
"definitions:\n",
" y: exp(ly)\n",
" c: 1 + y + l*R - b\n",
"\n",
"equations:\n",
" transition:\n",
" - l = b(-1)\n",
"\n",
" arbitrage:\n",
" - lam = b/c\n",
" - 1 - beta*(c(1)/c)^(-sigma)*R | lam_inf <= lam <= inf\n",
"\n",
"calibration:\n",
" beta: 0.95\n",
" R: 1/beta\n",
" sigma: 2.0\n",
" mu: 0.8\n",
" lam_inf: -0.2\n",
" ly: 0.0\n",
" l: 0.0\n",
" b: 0.0\n",
" lam: 0.0\n",
" y: exp(ly)\n",
" c: 1.0 + y\n",
"\n",
"exogenous: !VAR1\n",
" rho: 0.01\n",
" Sigma: 0.065^2\n",
" N: 2\n",
"\n",
"domain:\n",
" l: [-1.0, 1.0]\n",
"\n",
"options:\n",
" grid: !Cartesian\n",
" orders: [100]\n"
]
}
],
"source": [
"# Let's view the yaml file defining the model\n",
"using Dolo, PlotlyJS\n",
"print(readstring(joinpath(Dolo.pkg_path, \"examples\", \"models\", \"sudden_stop_ar1.yaml\")))"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/html": [
" <table>\n",
" <td><b>Model</b></td>\n",
" <tr>\n",
" <td>name</td>\n",
" <td>Sudden Stop (AR1)</td>\n",
" </tr>\n",
" <tr>\n",
" <td>filename</td>\n",
" <td>sudden_stop_ar1.yaml</td>\n",
" </tr>\n",
" </table>\n",
"<table width=\"100%\"><tr><td><b>Type</b></td><td><b>Equation</b></td></tr>\n",
"<tr><td>transition</td><td>\\[l_{t} = b_{t-1}\\]</td></tr><tr><td>arbitrage</td><td>\\[lam_{t} = \\frac{b_{t}}{c_{t}}\\]</td></tr><tr><td></td><td>\\[1-\\beta \\left(\\frac{c_{t+1}}{c_{t}}\\right)^{-\\sigma} R\\]</td></tr><table>"
],
"text/plain": []
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Model\n"
]
}
],
"source": [
"# Load model\n",
"model_ss = yaml_import(joinpath(Dolo.pkg_path, \"examples\", \"models\", \"sudden_stop_ar1.yaml\"))"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"#### Solving the model\n",
"\n",
"- Two methods:\n",
" - Linear perturbation around \"steady state\"\n",
" - Time iteration"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"Perturbation Results\n",
" * Decision Rule type: Dolo.PerturbationResult\n",
" * Blanchard-Kahn: true\n",
" * stable < true\n",
" * determined < true\n",
" * unique < true\n"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res_linear_ss = Dolo.perturbate(model_ss)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"Results of Time Iteration Algorithm\n",
" * Complementarities: true\n",
" * Discretized Process type: Dolo.DiscretizedProcess{Dolo.CartesianGrid}\n",
" * Decision Rule type: Dolo.DecisionRule{Dolo.CartesianGrid,Dolo.CartesianGrid}\n",
" * Number of iterations: 156\n",
" * Convergence: true\n",
" * |x - x'| < 1.0e-07: true\n"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res_nonlin_ss = Dolo.time_iteration(model_ss, verbose=false)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"#### Visualizing constraints"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"plot_policies (generic function with 1 method)"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function plot_policies(mod, state, variable, res_lin, res_nonlin, bounds)\n",
" s0, m0 = mod.calibration[:states, :exogenous]\n",
" linear_data = Dolo.tabulate(mod, res_lin.solution, state, bounds, s0, m0)\n",
" nonlin_data = Dolo.tabulate(mod, res_nonlin.dr, state, bounds, s0, m0);\n",
" t1 = scatter(x=linear_data[state], y=linear_data[variable], name=\"Linear policy\")\n",
" t2 = scatter(\n",
" x=nonlin_data[state], y=nonlin_data[variable], name=\"Non-linear policy\",\n",
" fill=\"tonextx\", fillcolor=\"RGBA(255, 0, 0, 0.2)\"\n",
" )\n",
" k_ss = mod.calibration.flat[state]\n",
" v_ss = mod.calibration.flat[variable]\n",
" layout = Layout(\n",
" annotations=[attr(x=k_ss, y=v_ss, text=\"Perturbation point\", ay=-50)],\n",
" xaxis_title=\"Capital\",\n",
" )\n",
" plot([t1, t2], layout)\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": "{\"layout\":{\"xaxis\":{\"title\":\"Capital\"},\"annotations\":[{\"y\":0.0,\"ay\":-50,\"text\":\"Perturbation point\",\"x\":0.0},{\"y\":-0.2,\"ax\":20,\"ay\":40,\"text\":\"Constraint\",\"x\":-0.415}],\"margin\":{\"l\":50,\"b\":50,\"r\":50,\"t\":60},\"title\":\"Price of capital\"},\"data\":[{\"y\":[-0.49999999999999867,-0.48989898989898856,-0.4797979797979785,-0.46969696969696845,-0.4595959595959584,-0.4494949494949483,-0.4393939393939382,-0.4292929292929281,-0.41919191919191806,-0.409090909090908,-0.39898989898989795,-0.38888888888888784,-0.3787878787878778,-0.3686868686868677,-0.3585858585858576,-0.34848484848484756,-0.3383838383838375,-0.3282828282828274,-0.31818181818181734,-0.30808080808080723,-0.2979797979797972,-0.2878787878787871,-0.27777777777777707,-0.26767676767676696,-0.2575757575757569,-0.24747474747474682,-0.23737373737373674,-0.22727272727272665,-0.2171717171717166,-0.20707070707070652,-0.19696969696969643,-0.18686868686868638,-0.1767676767676763,-0.1666666666666662,-0.15656565656565616,-0.14646464646464608,-0.136363636363636,-0.12626262626262594,-0.11616161616161585,-0.10606060606060579,-0.0959595959595957,-0.08585858585858563,-0.07575757575757555,-0.06565656565656548,-0.05555555555555541,-0.04545454545454534,-0.035353535353535255,-0.025252525252525186,-0.015151515151515112,-0.005050505050505037,0.005050505050505037,0.015151515151515112,0.025252525252525186,0.035353535353535255,0.04545454545454534,0.05555555555555541,0.06565656565656548,0.07575757575757555,0.08585858585858563,0.0959595959595957,0.10606060606060579,0.11616161616161585,0.12626262626262594,0.136363636363636,0.14646464646464608,0.15656565656565616,0.1666666666666662,0.1767676767676763,0.18686868686868638,0.19696969696969643,0.20707070707070652,0.2171717171717166,0.22727272727272665,0.23737373737373674,0.24747474747474682,0.2575757575757569,0.26767676767676696,0.27777777777777707,0.2878787878787871,0.2979797979797972,0.30808080808080723,0.31818181818181734,0.3282828282828274,0.3383838383838375,0.34848484848484756,0.3585858585858576,0.3686868686868677,0.3787878787878778,0.38888888888888784,0.39898989898989795,0.409090909090908,0.41919191919191806,0.4292929292929281,0.4393939393939382,0.4494949494949483,0.4595959595959584,0.46969696969696845,0.4797979797979785,0.48989898989898856,0.49999999999999867],\"type\":\"scatter\",\"name\":\"Linear policy\",\"x\":[-1.0,-0.9797979797979798,-0.9595959595959596,-0.9393939393939394,-0.9191919191919192,-0.898989898989899,-0.8787878787878788,-0.8585858585858586,-0.8383838383838383,-0.8181818181818182,-0.797979797979798,-0.7777777777777778,-0.7575757575757576,-0.7373737373737373,-0.7171717171717171,-0.696969696969697,-0.6767676767676768,-0.6565656565656566,-0.6363636363636364,-0.6161616161616161,-0.5959595959595959,-0.5757575757575758,-0.5555555555555556,-0.5353535353535354,-0.5151515151515151,-0.494949494949495,-0.47474747474747475,-0.45454545454545453,-0.43434343434343436,-0.41414141414141414,-0.3939393939393939,-0.37373737373737376,-0.35353535353535354,-0.3333333333333333,-0.31313131313131315,-0.29292929292929293,-0.2727272727272727,-0.25252525252525254,-0.23232323232323232,-0.21212121212121213,-0.1919191919191919,-0.1717171717171717,-0.15151515151515152,-0.13131313131313133,-0.1111111111111111,-0.09090909090909091,-0.0707070707070707,-0.050505050505050504,-0.030303030303030304,-0.010101010101010102,0.010101010101010102,0.030303030303030304,0.050505050505050504,0.0707070707070707,0.09090909090909091,0.1111111111111111,0.13131313131313133,0.15151515151515152,0.1717171717171717,0.1919191919191919,0.21212121212121213,0.23232323232323232,0.25252525252525254,0.2727272727272727,0.29292929292929293,0.31313131313131315,0.3333333333333333,0.35353535353535354,0.37373737373737376,0.3939393939393939,0.41414141414141414,0.43434343434343436,0.45454545454545453,0.47474747474747475,0.494949494949495,0.5151515151515151,0.5353535353535354,0.5555555555555556,0.5757575757575758,0.5959595959595959,0.6161616161616161,0.6363636363636364,0.6565656565656566,0.6767676767676768,0.696969696969697,0.7171717171717171,0.7373737373737373,0.7575757575757576,0.7777777777777778,0.797979797979798,0.8181818181818182,0.8383838383838383,0.8585858585858586,0.8787878787878788,0.898989898989899,0.9191919191919192,0.9393939393939394,0.9595959595959596,0.9797979797979798,1.0]},{\"fillcolor\":\"RGBA(255, 0, 0, .2)\",\"y\":[-0.19999999999999996,-0.19999999999999998,-0.19999999999999996,-0.19999999999999996,-0.19999999999999998,-0.2,-0.1999999999999999,-0.19999999999999996,-0.19999999999999996,-0.19999999999999996,-0.19999999999999996,-0.19999999999999996,-0.19999999999999996,-0.19999999999999996,-0.19999999999999996,-0.19999999999999996,-0.2,-0.19999999999999996,-0.2,-0.2,-0.19999999999999996,-0.19999999999999996,-0.19999999999999998,-0.19999999999999996,-0.19999999999999996,-0.19999999999999998,-0.19999999999999998,-0.2,-0.19999999999999996,-0.19557786072248595,-0.18753702226140614,-0.17907503035266625,-0.17037603952113492,-0.16157770690656686,-0.15236421337148973,-0.14289139731902267,-0.1333322647370439,-0.12365683307483004,-0.1139401396493856,-0.10416043382846288,-0.09431399533824762,-0.0844462303662222,-0.07454149886165963,-0.06461459240674712,-0.054676665119906986,-0.04471827114101436,-0.03475124624167949,-0.024778914757714512,-0.014797432449969894,-0.0048148135783834525,0.0051689286306318095,0.015155211377680496,0.025138847067471687,0.035120499501948864,0.04510049662252781,0.055075523814892155,0.06504631236469981,0.07501277432963012,0.0849727697457361,0.0949268845843192,0.10487490400462898,0.11481543114859716,0.12474889120736395,0.13467505979691355,0.1445930130120231,0.15450304239514476,0.1644049554962987,0.17429813468231428,0.18418277358009844,0.19405872088879372,0.20392556032188977,0.21378341787566513,0.22363218042804828,0.2334715660297719,0.24330165585124283,0.2531223682383381,0.2629335119436394,0.27273513938203847,0.2825271934015745,0.2923095445296402,0.3020822273202371,0.31184520311626235,0.3215983846824481,0.331341795879332,0.34107541180982737,0.35079917401887434,0.36051310020233546,0.3702171756967135,0.37991136127785985,0.38959567120429883,0.3992700987837307,0.40893461717671875,0.4185892385768446,0.42823396233089484,0.43786876852295453,0.44749366676613733,0.4571086637478243,0.4667137447751508,0.47630891638905837,0.48589419196418937],\"type\":\"scatter\",\"name\":\"Non-linear policy\",\"fill\":\"tonextx\",\"x\":[-1.0,-0.9797979797979798,-0.9595959595959596,-0.9393939393939394,-0.9191919191919192,-0.898989898989899,-0.8787878787878788,-0.8585858585858586,-0.8383838383838383,-0.8181818181818182,-0.797979797979798,-0.7777777777777778,-0.7575757575757576,-0.7373737373737373,-0.7171717171717171,-0.696969696969697,-0.6767676767676768,-0.6565656565656566,-0.6363636363636364,-0.6161616161616161,-0.5959595959595959,-0.5757575757575758,-0.5555555555555556,-0.5353535353535354,-0.5151515151515151,-0.494949494949495,-0.47474747474747475,-0.45454545454545453,-0.43434343434343436,-0.41414141414141414,-0.3939393939393939,-0.37373737373737376,-0.35353535353535354,-0.3333333333333333,-0.31313131313131315,-0.29292929292929293,-0.2727272727272727,-0.25252525252525254,-0.23232323232323232,-0.21212121212121213,-0.1919191919191919,-0.1717171717171717,-0.15151515151515152,-0.13131313131313133,-0.1111111111111111,-0.09090909090909091,-0.0707070707070707,-0.050505050505050504,-0.030303030303030304,-0.010101010101010102,0.010101010101010102,0.030303030303030304,0.050505050505050504,0.0707070707070707,0.09090909090909091,0.1111111111111111,0.13131313131313133,0.15151515151515152,0.1717171717171717,0.1919191919191919,0.21212121212121213,0.23232323232323232,0.25252525252525254,0.2727272727272727,0.29292929292929293,0.31313131313131315,0.3333333333333333,0.35353535353535354,0.37373737373737376,0.3939393939393939,0.41414141414141414,0.43434343434343436,0.45454545454545453,0.47474747474747475,0.494949494949495,0.5151515151515151,0.5353535353535354,0.5555555555555556,0.5757575757575758,0.5959595959595959,0.6161616161616161,0.6363636363636364,0.6565656565656566,0.6767676767676768,0.696969696969697,0.7171717171717171,0.7373737373737373,0.7575757575757576,0.7777777777777778,0.797979797979798,0.8181818181818182,0.8383838383838383,0.8585858585858586,0.8787878787878788,0.898989898989899,0.9191919191919192,0.9393939393939394,0.9595959595959596,0.9797979797979798,1.0]}]}",
"text/html": [
"<div id=\"5702e478-542e-45b7-9d8e-bcd8cff33bd7\" class=\"plotly-graph-div\"></div>\n",
"\n",
"<script>\n",
" window.PLOTLYENV=window.PLOTLYENV || {};\n",
" window.PLOTLYENV.BASE_URL=\"https://plot.ly\";\n",
" require(['plotly'], function(Plotly) {\n",
" Plotly.newPlot('5702e478-542e-45b7-9d8e-bcd8cff33bd7', [{\"y\":[-0.49999999999999867,-0.48989898989898856,-0.4797979797979785,-0.46969696969696845,-0.4595959595959584,-0.4494949494949483,-0.4393939393939382,-0.4292929292929281,-0.41919191919191806,-0.409090909090908,-0.39898989898989795,-0.38888888888888784,-0.3787878787878778,-0.3686868686868677,-0.3585858585858576,-0.34848484848484756,-0.3383838383838375,-0.3282828282828274,-0.31818181818181734,-0.30808080808080723,-0.2979797979797972,-0.2878787878787871,-0.27777777777777707,-0.26767676767676696,-0.2575757575757569,-0.24747474747474682,-0.23737373737373674,-0.22727272727272665,-0.2171717171717166,-0.20707070707070652,-0.19696969696969643,-0.18686868686868638,-0.1767676767676763,-0.1666666666666662,-0.15656565656565616,-0.14646464646464608,-0.136363636363636,-0.12626262626262594,-0.11616161616161585,-0.10606060606060579,-0.0959595959595957,-0.08585858585858563,-0.07575757575757555,-0.06565656565656548,-0.05555555555555541,-0.04545454545454534,-0.035353535353535255,-0.025252525252525186,-0.015151515151515112,-0.005050505050505037,0.005050505050505037,0.015151515151515112,0.025252525252525186,0.035353535353535255,0.04545454545454534,0.05555555555555541,0.06565656565656548,0.07575757575757555,0.08585858585858563,0.0959595959595957,0.10606060606060579,0.11616161616161585,0.12626262626262594,0.136363636363636,0.14646464646464608,0.15656565656565616,0.1666666666666662,0.1767676767676763,0.18686868686868638,0.19696969696969643,0.20707070707070652,0.2171717171717166,0.22727272727272665,0.23737373737373674,0.24747474747474682,0.2575757575757569,0.26767676767676696,0.27777777777777707,0.2878787878787871,0.2979797979797972,0.30808080808080723,0.31818181818181734,0.3282828282828274,0.3383838383838375,0.34848484848484756,0.3585858585858576,0.3686868686868677,0.3787878787878778,0.38888888888888784,0.39898989898989795,0.409090909090908,0.41919191919191806,0.4292929292929281,0.4393939393939382,0.4494949494949483,0.4595959595959584,0.46969696969696845,0.4797979797979785,0.48989898989898856,0.49999999999999867],\"type\":\"scatter\",\"name\":\"Linear policy\",\"x\":[-1.0,-0.9797979797979798,-0.9595959595959596,-0.9393939393939394,-0.9191919191919192,-0.898989898989899,-0.8787878787878788,-0.8585858585858586,-0.8383838383838383,-0.8181818181818182,-0.797979797979798,-0.7777777777777778,-0.7575757575757576,-0.7373737373737373,-0.7171717171717171,-0.696969696969697,-0.6767676767676768,-0.6565656565656566,-0.6363636363636364,-0.6161616161616161,-0.5959595959595959,-0.5757575757575758,-0.5555555555555556,-0.5353535353535354,-0.5151515151515151,-0.494949494949495,-0.47474747474747475,-0.45454545454545453,-0.43434343434343436,-0.41414141414141414,-0.3939393939393939,-0.37373737373737376,-0.35353535353535354,-0.3333333333333333,-0.31313131313131315,-0.29292929292929293,-0.2727272727272727,-0.25252525252525254,-0.23232323232323232,-0.21212121212121213,-0.1919191919191919,-0.1717171717171717,-0.15151515151515152,-0.13131313131313133,-0.1111111111111111,-0.09090909090909091,-0.0707070707070707,-0.050505050505050504,-0.030303030303030304,-0.010101010101010102,0.010101010101010102,0.030303030303030304,0.050505050505050504,0.0707070707070707,0.09090909090909091,0.1111111111111111,0.13131313131313133,0.15151515151515152,0.1717171717171717,0.1919191919191919,0.21212121212121213,0.23232323232323232,0.25252525252525254,0.2727272727272727,0.29292929292929293,0.31313131313131315,0.3333333333333333,0.35353535353535354,0.37373737373737376,0.3939393939393939,0.41414141414141414,0.43434343434343436,0.45454545454545453,0.47474747474747475,0.494949494949495,0.5151515151515151,0.5353535353535354,0.5555555555555556,0.5757575757575758,0.5959595959595959,0.6161616161616161,0.6363636363636364,0.6565656565656566,0.6767676767676768,0.696969696969697,0.7171717171717171,0.7373737373737373,0.7575757575757576,0.7777777777777778,0.797979797979798,0.8181818181818182,0.8383838383838383,0.8585858585858586,0.8787878787878788,0.898989898989899,0.9191919191919192,0.9393939393939394,0.9595959595959596,0.9797979797979798,1.0]},{\"fillcolor\":\"RGBA(255, 0, 0, .2)\",\"y\":[-0.19999999999999996,-0.19999999999999998,-0.19999999999999996,-0.19999999999999996,-0.19999999999999998,-0.2,-0.1999999999999999,-0.19999999999999996,-0.19999999999999996,-0.19999999999999996,-0.19999999999999996,-0.19999999999999996,-0.19999999999999996,-0.19999999999999996,-0.19999999999999996,-0.19999999999999996,-0.2,-0.19999999999999996,-0.2,-0.2,-0.19999999999999996,-0.19999999999999996,-0.19999999999999998,-0.19999999999999996,-0.19999999999999996,-0.19999999999999998,-0.19999999999999998,-0.2,-0.19999999999999996,-0.19557786072248595,-0.18753702226140614,-0.17907503035266625,-0.17037603952113492,-0.16157770690656686,-0.15236421337148973,-0.14289139731902267,-0.1333322647370439,-0.12365683307483004,-0.1139401396493856,-0.10416043382846288,-0.09431399533824762,-0.0844462303662222,-0.07454149886165963,-0.06461459240674712,-0.054676665119906986,-0.04471827114101436,-0.03475124624167949,-0.024778914757714512,-0.014797432449969894,-0.0048148135783834525,0.0051689286306318095,0.015155211377680496,0.025138847067471687,0.035120499501948864,0.04510049662252781,0.055075523814892155,0.06504631236469981,0.07501277432963012,0.0849727697457361,0.0949268845843192,0.10487490400462898,0.11481543114859716,0.12474889120736395,0.13467505979691355,0.1445930130120231,0.15450304239514476,0.1644049554962987,0.17429813468231428,0.18418277358009844,0.19405872088879372,0.20392556032188977,0.21378341787566513,0.22363218042804828,0.2334715660297719,0.24330165585124283,0.2531223682383381,0.2629335119436394,0.27273513938203847,0.2825271934015745,0.2923095445296402,0.3020822273202371,0.31184520311626235,0.3215983846824481,0.331341795879332,0.34107541180982737,0.35079917401887434,0.36051310020233546,0.3702171756967135,0.37991136127785985,0.38959567120429883,0.3992700987837307,0.40893461717671875,0.4185892385768446,0.42823396233089484,0.43786876852295453,0.44749366676613733,0.4571086637478243,0.4667137447751508,0.47630891638905837,0.48589419196418937],\"type\":\"scatter\",\"name\":\"Non-linear policy\",\"fill\":\"tonextx\",\"x\":[-1.0,-0.9797979797979798,-0.9595959595959596,-0.9393939393939394,-0.9191919191919192,-0.898989898989899,-0.8787878787878788,-0.8585858585858586,-0.8383838383838383,-0.8181818181818182,-0.797979797979798,-0.7777777777777778,-0.7575757575757576,-0.7373737373737373,-0.7171717171717171,-0.696969696969697,-0.6767676767676768,-0.6565656565656566,-0.6363636363636364,-0.6161616161616161,-0.5959595959595959,-0.5757575757575758,-0.5555555555555556,-0.5353535353535354,-0.5151515151515151,-0.494949494949495,-0.47474747474747475,-0.45454545454545453,-0.43434343434343436,-0.41414141414141414,-0.3939393939393939,-0.37373737373737376,-0.35353535353535354,-0.3333333333333333,-0.31313131313131315,-0.29292929292929293,-0.2727272727272727,-0.25252525252525254,-0.23232323232323232,-0.21212121212121213,-0.1919191919191919,-0.1717171717171717,-0.15151515151515152,-0.13131313131313133,-0.1111111111111111,-0.09090909090909091,-0.0707070707070707,-0.050505050505050504,-0.030303030303030304,-0.010101010101010102,0.010101010101010102,0.030303030303030304,0.050505050505050504,0.0707070707070707,0.09090909090909091,0.1111111111111111,0.13131313131313133,0.15151515151515152,0.1717171717171717,0.1919191919191919,0.21212121212121213,0.23232323232323232,0.25252525252525254,0.2727272727272727,0.29292929292929293,0.31313131313131315,0.3333333333333333,0.35353535353535354,0.37373737373737376,0.3939393939393939,0.41414141414141414,0.43434343434343436,0.45454545454545453,0.47474747474747475,0.494949494949495,0.5151515151515151,0.5353535353535354,0.5555555555555556,0.5757575757575758,0.5959595959595959,0.6161616161616161,0.6363636363636364,0.6565656565656566,0.6767676767676768,0.696969696969697,0.7171717171717171,0.7373737373737373,0.7575757575757576,0.7777777777777778,0.797979797979798,0.8181818181818182,0.8383838383838383,0.8585858585858586,0.8787878787878788,0.898989898989899,0.9191919191919192,0.9393939393939394,0.9595959595959596,0.9797979797979798,1.0]}],\n",
" {\"xaxis\":{\"title\":\"Capital\"},\"annotations\":[{\"y\":0.0,\"ay\":-50,\"text\":\"Perturbation point\",\"x\":0.0},{\"y\":-0.2,\"ax\":20,\"ay\":40,\"text\":\"Constraint\",\"x\":-0.415}],\"margin\":{\"l\":50,\"b\":50,\"r\":50,\"t\":60},\"title\":\"Price of capital\"}, {showLink: false});\n",
"\n",
" });\n",
" </script>\n"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bounds_ss = [model_ss.grid.min[1]; model_ss.grid.max[1]];\n",
"p_b = plot_policies(model_ss, :l, :lam, res_linear_ss, res_nonlin_ss, bounds_ss)\n",
"restyle!(p_b, 2, fill=\"tonextx\", fillcolor=\"RGBA(255, 0, 0, .2)\")\n",
"constraint = model_ss.calibration.flat[:lam_inf]\n",
"relayout(\n",
" p_b, \n",
" title=\"Price of capital\", \n",
" annotations=[\n",
" p_b.plot.layout[:annotations];\n",
" attr(text=\"Constraint\", x=-0.415, y=constraint, ay=40, ax=20)\n",
" ]\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### Example 2: RBC Model\n",
"\n",
"- Classic model of business cycles (recessions and booms) "
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/html": [
" <table>\n",
" <td><b>Model</b></td>\n",
" <tr>\n",
" <td>name</td>\n",
" <td>Real Business Cycle</td>\n",
" </tr>\n",
" <tr>\n",
" <td>filename</td>\n",
" <td>rbc_dtcc_iid.yaml</td>\n",
" </tr>\n",
" </table>\n",
"<table width=\"100%\"><tr><td><b>Type</b></td><td><b>Equation</b></td></tr>\n",
"<tr><td>expectation</td><td>\\[m_{t} = \\frac{\\beta}{\\left(c_{t+1}\\right)^{\\sigma}} 1-\\delta+rk_{t+1}\\]</td></tr><tr><td>value</td><td>\\[V_{t} = \\frac{\\left(c_{t}\\right)^{1-\\sigma}}{1-\\sigma}-\\frac{\\chi \\left(n_{t}\\right)^{1+\\eta}}{1+\\eta}+\\beta V_{t+1}\\]</td></tr><tr><td>transition</td><td>\\[z_{t} = \\rho z_{t-1}+e_{z,t}\\]</td></tr><tr><td></td><td>\\[k_{t} = 1-\\delta k_{t-1}+i_{t-1}\\]</td></tr><tr><td>direct_response</td><td>\\[n_{t} = \\left(\\frac{1-\\alpha \\text{exp}\\left(z_{t}\\right) \\left(k_{t}\\right)^{\\alpha} m_{t}}{\\chi}\\right)^{\\frac{1}{\\eta+\\alpha}}\\]</td></tr><tr><td></td><td>\\[i_{t} = \\text{exp}\\left(z_{t}\\right) \\left(k_{t}\\right)^{\\alpha} \\left(n_{t}\\right)^{1-\\alpha}-\\left(m_{t}\\right)^{\\frac{-1}{\\sigma}}\\]</td></tr><tr><td>felicity</td><td>\\[u_{t} = \\frac{\\left(c_{t}\\right)^{1-\\sigma}}{1-\\sigma}-\\frac{\\chi \\left(n_{t}\\right)^{1+\\eta}}{1+\\eta}\\]</td></tr><tr><td>arbitrage</td><td>\\[\\chi \\left(n_{t}\\right)^{\\eta} \\left(c_{t}\\right)^{\\sigma}-w_{t}\\]</td></tr><tr><td></td><td>\\[1-\\beta \\left(\\frac{c_{t}}{c_{t+1}}\\right)^{\\sigma} 1-\\delta+rk_{t+1}\\]</td></tr><table>"
],
"text/plain": []
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Model\n"
]
}
],
"source": [
"# import model\n",
"model = yaml_import(joinpath(Dolo.pkg_path, \"examples\", \"models\", \"rbc_dtcc_iid.yaml\"))"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"#### Solving the RBC model\n",
"\n",
"- Use same two algorithms for this model as above\n",
"- Uses the _same_ implementation of the algorithm (separate model description from solution)"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Results of Time Iteration Algorithm\n",
" * Complementarities: true\n",
" * Discretized Process type: Dolo.DiscretizedIIDProcess\n",
" * Decision Rule type: Dolo.DecisionRule{Dolo.EmptyGrid,Dolo.CartesianGrid}\n",
" * Number of iterations: 134\n",
" * Convergence: true\n",
" * |x - x'| < 1.0e-07: true\n"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res_linear = Dolo.perturbate(model)\n",
"res_nonlin = time_iteration(model, verbose=false)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"#### Visualizing nonlinearities\n",
"\n",
"- We will visualize the optimal choices under the linear and non-linear policy rules"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": "{\"layout\":{\"xaxis\":{\"title\":\"Capital\"},\"annotations\":[{\"y\":0.33,\"ay\":-50,\"text\":\"Perturbation point\",\"x\":9.354978290145986}],\"margin\":{\"l\":50,\"b\":50,\"r\":50,\"t\":60},\"title\":\"Labor supply choice\"},\"data\":[{\"y\":[0.4014764492873364,0.40003248061486496,0.3985885119423935,0.39714454326992205,0.3957005745974506,0.3942566059249792,0.3928126372525077,0.39136866858003627,0.38992469990756484,0.3884807312350934,0.387036762562622,0.3855927938901505,0.38414882521767907,0.38270485654520764,0.3812608878727362,0.3798169192002647,0.3783729505277933,0.37692898185532187,0.37548501318285044,0.374041044510379,0.3725970758379075,0.3711531071654361,0.36970913849296466,0.36826516982049323,0.36682120114802175,0.3653772324755503,0.3639332638030789,0.36248929513060746,0.36104532645813603,0.3596013577856646,0.3581573891131931,0.3567134204407217,0.35526945176825026,0.3538254830957788,0.35238151442330734,0.3509375457508359,0.3494935770783645,0.34804960840589305,0.3466056397334216,0.34516167106095014,0.3437177023884787,0.3422737337160073,0.3408297650435358,0.3393857963710644,0.33794182769859293,0.3364978590261215,0.3350538903536501,0.3336099216811786,0.33216595300870716,0.33072198433623573,0.3292780156637643,0.32783404699129287,0.32639007831882144,0.32494610964634996,0.3235021409738785,0.3220581723014071,0.3206142036289356,0.31917023495646424,0.31772626628399275,0.3162822976115213,0.3148383289390499,0.3133943602665784,0.311950391594107,0.31050642292163555,0.3090624542491641,0.3076184855766927,0.3061745169042212,0.3047305482317498,0.30328657955927835,0.3018426108868069,0.3003986422143355,0.298954673541864,0.2975107048693926,0.29606673619692114,0.2946227675244497,0.29317879885197823,0.29173483017950685,0.29029086150703537,0.28884689283456394,0.2874029241620925,0.285958955489621,0.2845149868171496,0.28307101814467817,0.28162704947220674,0.2801830807997353,0.2787391121272638,0.2772951434547924,0.27585117478232096,0.2744072061098495,0.27296323743737805,0.2715192687649066,0.2700753000924352,0.26863133141996376,0.26718736274749233,0.26574339407502084,0.2642994254025494,0.262855456730078,0.26141148805760656,0.25996751938513507,0.25852355071266364],\"type\":\"scatter\",\"name\":\"Linear policy\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]},{\"fillcolor\":\"RGBA(255, 0, 0, 0.2)\",\"y\":[0.4383313296227615,0.43497183827541835,0.43165739846247053,0.42842443371741074,0.42527267602312535,0.4221931173507337,0.4191813242513446,0.41623439383371685,0.41335056867733233,0.4105282608042005,0.4077649902993769,0.40505812700146565,0.40240577095634045,0.39980624332695747,0.39725771399539983,0.3947583353321654,0.3923064874379144,0.38990064366635824,0.38753931989413876,0.3852210639305076,0.3829445276101875,0.38070841559710755,0.3785114950124661,0.37635256965411035,0.3742305109685191,0.3721442290623099,0.37009268784840016,0.3680748839229029,0.36608986420233486,0.36413670687337313,0.3622145332731806,0.3603224927551345,0.3584597736688908,0.3566255905779189,0.35481919230838727,0.3530398516785367,0.3512868722124239,0.3495595797870107,0.347857327540829,0.3461794892854565,0.3445254632337052,0.3428946668707271,0.3412865394712021,0.3397005382468994,0.3381361399410129,0.3365928380574695,0.33507014360659243,0.33356758326344804,0.3320846994272822,0.33062104916999613,0.32917620369629397,0.32774974796389084,0.32634127965542037,0.32495040936687986,0.32357675916916673,0.3222199632744777,0.32087966624842346,0.31955552407541826,0.31824720210135743,0.3169543764310731,0.31567673163027105,0.3144139623919787,0.3131657710897355,0.3119318696690376,0.31071197701827274,0.3095058210234256,0.3083131359180045,0.30713366449511587,0.30596715525877943,0.3048133646943525,0.3036720545875479,0.30254299444290983,0.30142595845225295,0.3003207278202639,0.2992270882627033,0.2981448325978599,0.29707375742098213,0.29601366526578116,0.29496436269304444,0.2939256632237436,0.2928973831429596,0.29187934293018125,0.29087136724036916,0.28987328917729976,0.2888849427326866,0.28790616112747985,0.2869367839512087,0.2859766678078238,0.28502566484201003,0.2840836071233843,0.2831503408206794,0.2822257639783386,0.28130976177135,0.2804021491205769,0.2795027374191315,0.2786113720739719,0.2777280486831291,0.2768532694493282,0.27598673827669007,0.2751247338535726],\"type\":\"scatter\",\"name\":\"Non-linear policy\",\"fill\":\"tonextx\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]}]}",
"text/html": [
"<div id=\"2a9907b8-8ab7-45bc-b741-e778aa5018ee\" class=\"plotly-graph-div\"></div>\n",
"\n",
"<script>\n",
" window.PLOTLYENV=window.PLOTLYENV || {};\n",
" window.PLOTLYENV.BASE_URL=\"https://plot.ly\";\n",
" require(['plotly'], function(Plotly) {\n",
" Plotly.newPlot('2a9907b8-8ab7-45bc-b741-e778aa5018ee', [{\"y\":[0.4014764492873364,0.40003248061486496,0.3985885119423935,0.39714454326992205,0.3957005745974506,0.3942566059249792,0.3928126372525077,0.39136866858003627,0.38992469990756484,0.3884807312350934,0.387036762562622,0.3855927938901505,0.38414882521767907,0.38270485654520764,0.3812608878727362,0.3798169192002647,0.3783729505277933,0.37692898185532187,0.37548501318285044,0.374041044510379,0.3725970758379075,0.3711531071654361,0.36970913849296466,0.36826516982049323,0.36682120114802175,0.3653772324755503,0.3639332638030789,0.36248929513060746,0.36104532645813603,0.3596013577856646,0.3581573891131931,0.3567134204407217,0.35526945176825026,0.3538254830957788,0.35238151442330734,0.3509375457508359,0.3494935770783645,0.34804960840589305,0.3466056397334216,0.34516167106095014,0.3437177023884787,0.3422737337160073,0.3408297650435358,0.3393857963710644,0.33794182769859293,0.3364978590261215,0.3350538903536501,0.3336099216811786,0.33216595300870716,0.33072198433623573,0.3292780156637643,0.32783404699129287,0.32639007831882144,0.32494610964634996,0.3235021409738785,0.3220581723014071,0.3206142036289356,0.31917023495646424,0.31772626628399275,0.3162822976115213,0.3148383289390499,0.3133943602665784,0.311950391594107,0.31050642292163555,0.3090624542491641,0.3076184855766927,0.3061745169042212,0.3047305482317498,0.30328657955927835,0.3018426108868069,0.3003986422143355,0.298954673541864,0.2975107048693926,0.29606673619692114,0.2946227675244497,0.29317879885197823,0.29173483017950685,0.29029086150703537,0.28884689283456394,0.2874029241620925,0.285958955489621,0.2845149868171496,0.28307101814467817,0.28162704947220674,0.2801830807997353,0.2787391121272638,0.2772951434547924,0.27585117478232096,0.2744072061098495,0.27296323743737805,0.2715192687649066,0.2700753000924352,0.26863133141996376,0.26718736274749233,0.26574339407502084,0.2642994254025494,0.262855456730078,0.26141148805760656,0.25996751938513507,0.25852355071266364],\"type\":\"scatter\",\"name\":\"Linear policy\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]},{\"fillcolor\":\"RGBA(255, 0, 0, 0.2)\",\"y\":[0.4383313296227615,0.43497183827541835,0.43165739846247053,0.42842443371741074,0.42527267602312535,0.4221931173507337,0.4191813242513446,0.41623439383371685,0.41335056867733233,0.4105282608042005,0.4077649902993769,0.40505812700146565,0.40240577095634045,0.39980624332695747,0.39725771399539983,0.3947583353321654,0.3923064874379144,0.38990064366635824,0.38753931989413876,0.3852210639305076,0.3829445276101875,0.38070841559710755,0.3785114950124661,0.37635256965411035,0.3742305109685191,0.3721442290623099,0.37009268784840016,0.3680748839229029,0.36608986420233486,0.36413670687337313,0.3622145332731806,0.3603224927551345,0.3584597736688908,0.3566255905779189,0.35481919230838727,0.3530398516785367,0.3512868722124239,0.3495595797870107,0.347857327540829,0.3461794892854565,0.3445254632337052,0.3428946668707271,0.3412865394712021,0.3397005382468994,0.3381361399410129,0.3365928380574695,0.33507014360659243,0.33356758326344804,0.3320846994272822,0.33062104916999613,0.32917620369629397,0.32774974796389084,0.32634127965542037,0.32495040936687986,0.32357675916916673,0.3222199632744777,0.32087966624842346,0.31955552407541826,0.31824720210135743,0.3169543764310731,0.31567673163027105,0.3144139623919787,0.3131657710897355,0.3119318696690376,0.31071197701827274,0.3095058210234256,0.3083131359180045,0.30713366449511587,0.30596715525877943,0.3048133646943525,0.3036720545875479,0.30254299444290983,0.30142595845225295,0.3003207278202639,0.2992270882627033,0.2981448325978599,0.29707375742098213,0.29601366526578116,0.29496436269304444,0.2939256632237436,0.2928973831429596,0.29187934293018125,0.29087136724036916,0.28987328917729976,0.2888849427326866,0.28790616112747985,0.2869367839512087,0.2859766678078238,0.28502566484201003,0.2840836071233843,0.2831503408206794,0.2822257639783386,0.28130976177135,0.2804021491205769,0.2795027374191315,0.2786113720739719,0.2777280486831291,0.2768532694493282,0.27598673827669007,0.2751247338535726],\"type\":\"scatter\",\"name\":\"Non-linear policy\",\"fill\":\"tonextx\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]}],\n",
" {\"xaxis\":{\"title\":\"Capital\"},\"annotations\":[{\"y\":0.33,\"ay\":-50,\"text\":\"Perturbation point\",\"x\":9.354978290145986}],\"margin\":{\"l\":50,\"b\":50,\"r\":50,\"t\":60},\"title\":\"Labor supply choice\"}, {showLink: false});\n",
"\n",
" });\n",
" </script>\n"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# let's look at labor supply as capital varies\n",
"bounds = [model.grid.min[2]; model.grid.max[2]];\n",
"p_n = plot_policies(model, :k, :n, res_linear, res_nonlin, bounds)\n",
"relayout!(p_n, title=\"Labor supply choice\")\n",
"p_n"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": "{\"layout\":{\"xaxis\":{\"title\":\"Capital\"},\"annotations\":[{\"y\":0.23387445725364966,\"ay\":-50,\"text\":\"Perturbation point\",\"x\":9.354978290145986}],\"margin\":{\"l\":50,\"b\":50,\"r\":50,\"t\":60},\"title\":\"Investment choice\"},\"data\":[{\"y\":[0.2830657236253331,0.2820719606683294,0.2810781977113257,0.280084434754322,0.2790906717973183,0.27809690884031457,0.27710314588331086,0.27610938292630716,0.27511561996930345,0.27412185701229974,0.27312809405529603,0.2721343310982923,0.2711405681412886,0.2701468051842849,0.2691530422272812,0.2681592792702775,0.2671655163132738,0.2661717533562701,0.2651779903992664,0.26418422744226266,0.26319046448525896,0.26219670152825525,0.26120293857125154,0.26020917561424783,0.2592154126572441,0.2582216497002405,0.25722788674323677,0.25623412378623306,0.25524036082922935,0.25424659787222564,0.25325283491522194,0.25225907195821823,0.2512653090012145,0.2502715460442108,0.2492777830872071,0.2482840201302034,0.2472902571731997,0.24629649421619598,0.24530273125919227,0.24430896830218857,0.24331520534518486,0.24232144238818115,0.24132767943117744,0.24033391647417376,0.23934015351717006,0.23834639056016635,0.23735262760316264,0.23635886464615893,0.23536510168915523,0.23437133873215152,0.2333775757751478,0.2323838128181441,0.2313900498611404,0.2303962869041367,0.22940252394713298,0.22840876099012927,0.22741499803312556,0.22642123507612189,0.22542747211911818,0.22443370916211447,0.22343994620511076,0.22244618324810705,0.22145242029110335,0.22045865733409964,0.21946489437709593,0.21847113142009222,0.21747736846308852,0.2164836055060848,0.2154898425490811,0.2144960795920774,0.2135023166350737,0.21250855367807,0.2115147907210663,0.2105210277640626,0.20952726480705888,0.20853350185005518,0.20753973889305147,0.20654597593604776,0.20555221297904405,0.20455845002204034,0.20356468706503664,0.20257092410803293,0.20157716115102922,0.20058339819402554,0.19958963523702183,0.19859587228001813,0.19760210932301442,0.1966083463660107,0.195614583409007,0.1946208204520033,0.1936270574949996,0.19263329453799588,0.19163953158099217,0.19064576862398847,0.18965200566698476,0.18865824270998105,0.18766447975297737,0.18667071679597366,0.18567695383896995,0.18468319088196625],\"type\":\"scatter\",\"name\":\"Linear policy\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]},{\"fillcolor\":\"RGBA(255, 0, 0, 0.2)\",\"y\":[0.28318177262692096,0.28226142830638545,0.2813278718055469,0.2803724337801543,0.27940576381055615,0.2784401419019473,0.2774720040745158,0.27649503697545486,0.2755112291779802,0.2745243066101979,0.27353413446895,0.2725396415509343,0.27154136076236235,0.27054024610985034,0.26953654419639117,0.2685302887209804,0.2675217686362655,0.2665113496313932,0.2654992616605476,0.26448568420955015,0.2634708278114075,0.26245491152090544,0.2614381182398998,0.26042061403818656,0.25940256155225394,0.25838411997254573,0.257365432755033,0.25634663456658646,0.255327852630509,0.2543092092359718,0.25329081709429674,0.2522727828757235,0.25125520658199774,0.25023818366755246,0.2492218028967308,0.24820614839822394,0.24719129896395847,0.24617732949190074,0.24516430995859712,0.24415230662420748,0.2431413815928884,0.24213159368960185,0.24112299803118947,0.24011564668935886,0.23910958853614717,0.23810486970262523,0.23710153349616575,0.2360996207020385,0.23509916964029615,0.23410021633445766,0.23310279463098169,0.23210693626121628,0.2311126710474914,0.23012002687912447,0.22912902997917664,0.22813970481152457,0.2271520743656748,0.2261661600082782,0.2251819818225812,0.22419955842069822,0.22321890725756652,0.2222400444047229,0.22126298495518382,0.22028774278954374,0.21931433085569432,0.2183427608881358,0.21737304391221154,0.2164051900178896,0.21543920848809234,0.21447510744669962,0.21351289458411,0.21255257702892694,0.21159416109473117,0.2106376517523082,0.20968305391562037,0.20873037263879762,0.20777961188249666,0.20683077342782863,0.2058838597728475,0.20493887542959782,0.20399582269365463,0.20305469842751833,0.2021155026104815,0.20117824417947322,0.20024292526831938,0.19930952803468877,0.19837804746571985,0.1974485201511654,0.1965209556834806,0.1955952697884713,0.19467143292491523,0.19374962503247348,0.19282991742425273,0.19191192006746158,0.1909954347377871,0.19008120263666012,0.18916972167984855,0.1882599370090073,0.18735066933097788,0.18644156327667488],\"type\":\"scatter\",\"name\":\"Non-linear policy\",\"fill\":\"tonextx\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]}]}",
"text/html": [
"<div id=\"3413173c-cdfd-4cbc-a732-d1392909d2da\" class=\"plotly-graph-div\"></div>\n",
"\n",
"<script>\n",
" window.PLOTLYENV=window.PLOTLYENV || {};\n",
" window.PLOTLYENV.BASE_URL=\"https://plot.ly\";\n",
" require(['plotly'], function(Plotly) {\n",
" Plotly.newPlot('3413173c-cdfd-4cbc-a732-d1392909d2da', [{\"y\":[0.2830657236253331,0.2820719606683294,0.2810781977113257,0.280084434754322,0.2790906717973183,0.27809690884031457,0.27710314588331086,0.27610938292630716,0.27511561996930345,0.27412185701229974,0.27312809405529603,0.2721343310982923,0.2711405681412886,0.2701468051842849,0.2691530422272812,0.2681592792702775,0.2671655163132738,0.2661717533562701,0.2651779903992664,0.26418422744226266,0.26319046448525896,0.26219670152825525,0.26120293857125154,0.26020917561424783,0.2592154126572441,0.2582216497002405,0.25722788674323677,0.25623412378623306,0.25524036082922935,0.25424659787222564,0.25325283491522194,0.25225907195821823,0.2512653090012145,0.2502715460442108,0.2492777830872071,0.2482840201302034,0.2472902571731997,0.24629649421619598,0.24530273125919227,0.24430896830218857,0.24331520534518486,0.24232144238818115,0.24132767943117744,0.24033391647417376,0.23934015351717006,0.23834639056016635,0.23735262760316264,0.23635886464615893,0.23536510168915523,0.23437133873215152,0.2333775757751478,0.2323838128181441,0.2313900498611404,0.2303962869041367,0.22940252394713298,0.22840876099012927,0.22741499803312556,0.22642123507612189,0.22542747211911818,0.22443370916211447,0.22343994620511076,0.22244618324810705,0.22145242029110335,0.22045865733409964,0.21946489437709593,0.21847113142009222,0.21747736846308852,0.2164836055060848,0.2154898425490811,0.2144960795920774,0.2135023166350737,0.21250855367807,0.2115147907210663,0.2105210277640626,0.20952726480705888,0.20853350185005518,0.20753973889305147,0.20654597593604776,0.20555221297904405,0.20455845002204034,0.20356468706503664,0.20257092410803293,0.20157716115102922,0.20058339819402554,0.19958963523702183,0.19859587228001813,0.19760210932301442,0.1966083463660107,0.195614583409007,0.1946208204520033,0.1936270574949996,0.19263329453799588,0.19163953158099217,0.19064576862398847,0.18965200566698476,0.18865824270998105,0.18766447975297737,0.18667071679597366,0.18567695383896995,0.18468319088196625],\"type\":\"scatter\",\"name\":\"Linear policy\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]},{\"fillcolor\":\"RGBA(255, 0, 0, 0.2)\",\"y\":[0.28318177262692096,0.28226142830638545,0.2813278718055469,0.2803724337801543,0.27940576381055615,0.2784401419019473,0.2774720040745158,0.27649503697545486,0.2755112291779802,0.2745243066101979,0.27353413446895,0.2725396415509343,0.27154136076236235,0.27054024610985034,0.26953654419639117,0.2685302887209804,0.2675217686362655,0.2665113496313932,0.2654992616605476,0.26448568420955015,0.2634708278114075,0.26245491152090544,0.2614381182398998,0.26042061403818656,0.25940256155225394,0.25838411997254573,0.257365432755033,0.25634663456658646,0.255327852630509,0.2543092092359718,0.25329081709429674,0.2522727828757235,0.25125520658199774,0.25023818366755246,0.2492218028967308,0.24820614839822394,0.24719129896395847,0.24617732949190074,0.24516430995859712,0.24415230662420748,0.2431413815928884,0.24213159368960185,0.24112299803118947,0.24011564668935886,0.23910958853614717,0.23810486970262523,0.23710153349616575,0.2360996207020385,0.23509916964029615,0.23410021633445766,0.23310279463098169,0.23210693626121628,0.2311126710474914,0.23012002687912447,0.22912902997917664,0.22813970481152457,0.2271520743656748,0.2261661600082782,0.2251819818225812,0.22419955842069822,0.22321890725756652,0.2222400444047229,0.22126298495518382,0.22028774278954374,0.21931433085569432,0.2183427608881358,0.21737304391221154,0.2164051900178896,0.21543920848809234,0.21447510744669962,0.21351289458411,0.21255257702892694,0.21159416109473117,0.2106376517523082,0.20968305391562037,0.20873037263879762,0.20777961188249666,0.20683077342782863,0.2058838597728475,0.20493887542959782,0.20399582269365463,0.20305469842751833,0.2021155026104815,0.20117824417947322,0.20024292526831938,0.19930952803468877,0.19837804746571985,0.1974485201511654,0.1965209556834806,0.1955952697884713,0.19467143292491523,0.19374962503247348,0.19282991742425273,0.19191192006746158,0.1909954347377871,0.19008120263666012,0.18916972167984855,0.1882599370090073,0.18735066933097788,0.18644156327667488],\"type\":\"scatter\",\"name\":\"Non-linear policy\",\"fill\":\"tonextx\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]}],\n",
" {\"xaxis\":{\"title\":\"Capital\"},\"annotations\":[{\"y\":0.23387445725364966,\"ay\":-50,\"text\":\"Perturbation point\",\"x\":9.354978290145986}],\"margin\":{\"l\":50,\"b\":50,\"r\":50,\"t\":60},\"title\":\"Investment choice\"}, {showLink: false});\n",
"\n",
" });\n",
" </script>\n"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Now look at investment -- looks fairly linear\n",
"p_i = plot_policies(model, :k, :i, res_linear, res_nonlin, bounds)\n",
"relayout(p_i, title=\"Investment choice\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"#### Experiment\n",
"\n",
"- Does the \"error\" from linear policy change as we vary how much agents dislike working\n",
"- Will change the parameter $\\eta$ that governs \"pain\" from working\n",
"- Shows off some flexibility of Dolo"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"data": {},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.plotly.v1+json": "{\"layout\":{\"xaxis\":{\"title\":\"Capital\"},\"annotations\":[{\"y\":0.33,\"ay\":-50,\"text\":\"Perturbation point\",\"x\":9.354978290145986}],\"margin\":{\"l\":50,\"b\":50,\"r\":50,\"t\":60},\"title\":\"Labor supply choice (η = 2)\"},\"data\":[{\"y\":[0.38010337876312555,0.37909118929316343,0.3780789998232013,0.3770668103532392,0.376054620883277,0.3750424314133149,0.37403024194335277,0.37301805247339065,0.3720058630034285,0.37099367353346635,0.36998148406350423,0.3689692945935421,0.36795710512358,0.36694491565361786,0.3659327261836557,0.36492053671369357,0.36390834724373144,0.3628961577737693,0.3618839683038072,0.360871778833845,0.3598595893638829,0.3588473998939208,0.35783521042395866,0.35682302095399654,0.35581083148403436,0.35479864201407224,0.3537864525441101,0.352774263074148,0.3517620736041859,0.35074988413422375,0.3497376946642616,0.34872550519429946,0.34771331572433734,0.3467011262543752,0.34568893678441304,0.3446767473144509,0.3436645578444888,0.3426523683745267,0.34164017890456455,0.34062798943460243,0.33961579996464025,0.33860361049467813,0.337591421024716,0.3365792315547539,0.33556704208479177,0.3345548526148296,0.33354266314486747,0.33253047367490535,0.3315182842049432,0.33050609473498105,0.329493905265019,0.3284817157950568,0.3274695263250947,0.32645733685513256,0.32544514738517044,0.32443295791520826,0.32342076844524614,0.322408578975284,0.3213963895053219,0.3203842000353598,0.3193720105653976,0.3183598210954355,0.31734763162547336,0.31633544215551124,0.3153232526855491,0.314311063215587,0.3132988737456248,0.3122866842756627,0.3112744948057006,0.31026230533573845,0.30925011586577633,0.30823792639581415,0.30722573692585203,0.3062135474558899,0.3052013579859278,0.3041891685159656,0.3031769790460035,0.30216478957604137,0.30115260010607925,0.3001404106361171,0.299128221166155,0.29811603169619283,0.2971038422262307,0.2960916527562686,0.29507946328630646,0.29406727381634434,0.29305508434638217,0.29204289487642004,0.2910307054064579,0.2900185159364958,0.2890063264665337,0.2879941369965715,0.2869819475266094,0.28596975805664726,0.28495756858668514,0.283945379116723,0.2829331896467609,0.2819210001767987,0.2809088107068366,0.2798966212368745],\"type\":\"scatter\",\"name\":\"Linear policy\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]},{\"fillcolor\":\"RGBA(255, 0, 0, 0.2)\",\"y\":[0.4042581003854534,0.4020016039317888,0.39977164356139494,0.3975902828019696,0.3954605651323041,0.3933800753393793,0.3913445732127373,0.38935002577085387,0.3873958754373079,0.3854822285341846,0.3836072510079124,0.3817686961262173,0.3799654386944925,0.37819666334578667,0.376461149603862,0.37475757887931166,0.3730849258231358,0.37144227020107834,0.3698286478636034,0.368243091434484,0.3666847359404952,0.3651527631789302,0.36364637692069257,0.3621647974498588,0.36070729811805846,0.3592731811367297,0.35786177811886494,0.3564724393530244,0.35510455033218025,0.35375751802946237,0.3524307755365315,0.35112377311357357,0.3498359869925196,0.34856691075757085,0.34731605949023536,0.3460829633795015,0.3448671726376862,0.3436682520271903,0.34248578366577503,0.34131936284455217,0.3401686006249265,0.33903312051873186,0.33791255999583647,0.3368065680182666,0.33571480612520144,0.3346369466484255,0.33357267316208095,0.3325216793000397,0.3314836688105426,0.33045835488018344,0.3294454597830309,0.3284447146363986,0.32745585874259286,0.3264786397102868,0.3255128125299758,0.32455814000266336,0.3236143915882406,0.32268134409083404,0.32175878034312183,0.32084649010660193,0.319944268581635,0.31905191747821415,0.31816924346435504,0.3172960593888451,0.31643218255086347,0.31557743601355454,0.314731646962813,0.31389464815179247,0.3130662759598429,0.3122463718188916,0.311434780662149,0.31063135255161284,0.3098359404383258,0.3090484015369973,0.308268596179817,0.30749638971390925,0.30673164959756705,0.3059742463892566,0.3052240537598438,0.30448095111643514,0.3037448188289241,0.3030155378248103,0.30229299307030966,0.3015770787884341,0.3008676875271621,0.30016470443734633,0.29946802265377376,0.29877755920172283,0.2980932214142908,0.2974148788882162,0.2967424224660612,0.2960758249731772,0.29541502959169175,0.29475983930221217,0.2941100896789231,0.2934658161906193,0.29282710772813736,0.2921940951255883,0.29156638245085464,0.2909415568760726],\"type\":\"scatter\",\"name\":\"Non-linear policy\",\"fill\":\"tonextx\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]}]}",
"text/html": [
"<div id=\"26d17820-97e7-436e-99df-c59e348b5bdf\" class=\"plotly-graph-div\"></div>\n",
"\n",
"<script>\n",
" window.PLOTLYENV=window.PLOTLYENV || {};\n",
" window.PLOTLYENV.BASE_URL=\"https://plot.ly\";\n",
" require(['plotly'], function(Plotly) {\n",
" Plotly.newPlot('26d17820-97e7-436e-99df-c59e348b5bdf', [{\"y\":[0.38010337876312555,0.37909118929316343,0.3780789998232013,0.3770668103532392,0.376054620883277,0.3750424314133149,0.37403024194335277,0.37301805247339065,0.3720058630034285,0.37099367353346635,0.36998148406350423,0.3689692945935421,0.36795710512358,0.36694491565361786,0.3659327261836557,0.36492053671369357,0.36390834724373144,0.3628961577737693,0.3618839683038072,0.360871778833845,0.3598595893638829,0.3588473998939208,0.35783521042395866,0.35682302095399654,0.35581083148403436,0.35479864201407224,0.3537864525441101,0.352774263074148,0.3517620736041859,0.35074988413422375,0.3497376946642616,0.34872550519429946,0.34771331572433734,0.3467011262543752,0.34568893678441304,0.3446767473144509,0.3436645578444888,0.3426523683745267,0.34164017890456455,0.34062798943460243,0.33961579996464025,0.33860361049467813,0.337591421024716,0.3365792315547539,0.33556704208479177,0.3345548526148296,0.33354266314486747,0.33253047367490535,0.3315182842049432,0.33050609473498105,0.329493905265019,0.3284817157950568,0.3274695263250947,0.32645733685513256,0.32544514738517044,0.32443295791520826,0.32342076844524614,0.322408578975284,0.3213963895053219,0.3203842000353598,0.3193720105653976,0.3183598210954355,0.31734763162547336,0.31633544215551124,0.3153232526855491,0.314311063215587,0.3132988737456248,0.3122866842756627,0.3112744948057006,0.31026230533573845,0.30925011586577633,0.30823792639581415,0.30722573692585203,0.3062135474558899,0.3052013579859278,0.3041891685159656,0.3031769790460035,0.30216478957604137,0.30115260010607925,0.3001404106361171,0.299128221166155,0.29811603169619283,0.2971038422262307,0.2960916527562686,0.29507946328630646,0.29406727381634434,0.29305508434638217,0.29204289487642004,0.2910307054064579,0.2900185159364958,0.2890063264665337,0.2879941369965715,0.2869819475266094,0.28596975805664726,0.28495756858668514,0.283945379116723,0.2829331896467609,0.2819210001767987,0.2809088107068366,0.2798966212368745],\"type\":\"scatter\",\"name\":\"Linear policy\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]},{\"fillcolor\":\"RGBA(255, 0, 0, 0.2)\",\"y\":[0.4042581003854534,0.4020016039317888,0.39977164356139494,0.3975902828019696,0.3954605651323041,0.3933800753393793,0.3913445732127373,0.38935002577085387,0.3873958754373079,0.3854822285341846,0.3836072510079124,0.3817686961262173,0.3799654386944925,0.37819666334578667,0.376461149603862,0.37475757887931166,0.3730849258231358,0.37144227020107834,0.3698286478636034,0.368243091434484,0.3666847359404952,0.3651527631789302,0.36364637692069257,0.3621647974498588,0.36070729811805846,0.3592731811367297,0.35786177811886494,0.3564724393530244,0.35510455033218025,0.35375751802946237,0.3524307755365315,0.35112377311357357,0.3498359869925196,0.34856691075757085,0.34731605949023536,0.3460829633795015,0.3448671726376862,0.3436682520271903,0.34248578366577503,0.34131936284455217,0.3401686006249265,0.33903312051873186,0.33791255999583647,0.3368065680182666,0.33571480612520144,0.3346369466484255,0.33357267316208095,0.3325216793000397,0.3314836688105426,0.33045835488018344,0.3294454597830309,0.3284447146363986,0.32745585874259286,0.3264786397102868,0.3255128125299758,0.32455814000266336,0.3236143915882406,0.32268134409083404,0.32175878034312183,0.32084649010660193,0.319944268581635,0.31905191747821415,0.31816924346435504,0.3172960593888451,0.31643218255086347,0.31557743601355454,0.314731646962813,0.31389464815179247,0.3130662759598429,0.3122463718188916,0.311434780662149,0.31063135255161284,0.3098359404383258,0.3090484015369973,0.308268596179817,0.30749638971390925,0.30673164959756705,0.3059742463892566,0.3052240537598438,0.30448095111643514,0.3037448188289241,0.3030155378248103,0.30229299307030966,0.3015770787884341,0.3008676875271621,0.30016470443734633,0.29946802265377376,0.29877755920172283,0.2980932214142908,0.2974148788882162,0.2967424224660612,0.2960758249731772,0.29541502959169175,0.29475983930221217,0.2941100896789231,0.2934658161906193,0.29282710772813736,0.2921940951255883,0.29156638245085464,0.2909415568760726],\"type\":\"scatter\",\"name\":\"Non-linear policy\",\"fill\":\"tonextx\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]}],\n",
" {\"xaxis\":{\"title\":\"Capital\"},\"annotations\":[{\"y\":0.33,\"ay\":-50,\"text\":\"Perturbation point\",\"x\":9.354978290145986}],\"margin\":{\"l\":50,\"b\":50,\"r\":50,\"t\":60},\"title\":\"Labor supply choice (η = 2)\"}, {showLink: false});\n",
"\n",
" });\n",
" </script>\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# one line to change a paramter value and have it propogate through the model\n",
"Dolo.set_calibration(model, :eta, 2.0)\n",
"\n",
"# resolve the model with new parameters\n",
"res_linear2 = Dolo.perturbate(model)\n",
"res_nonlin2 = time_iteration(model, verbose=false)\n",
"\n",
"# produce a new plot for the labor choice\n",
"p_n2 = plot_policies(model, :k, :n, res_linear2, res_nonlin2, bounds)\n",
"relayout!(p_n2, title=\"Labor supply choice (η = 2)\")\n",
"\n",
"# repeat previous plot for comparison\n",
"display(p_n)\n",
"display(p_n2)"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": "{\"layout\":{\"xaxis\":{\"title\":\"Capital\"},\"annotations\":[{\"y\":0.23387445725364966,\"ay\":-50,\"text\":\"Perturbation point\",\"x\":9.354978290145986}],\"margin\":{\"l\":50,\"b\":50,\"r\":50,\"t\":60}},\"data\":[{\"y\":[0.2830657236253331,0.2820719606683294,0.2810781977113257,0.280084434754322,0.2790906717973183,0.27809690884031457,0.27710314588331086,0.27610938292630716,0.27511561996930345,0.27412185701229974,0.27312809405529603,0.2721343310982923,0.2711405681412886,0.2701468051842849,0.2691530422272812,0.2681592792702775,0.2671655163132738,0.2661717533562701,0.2651779903992664,0.26418422744226266,0.26319046448525896,0.26219670152825525,0.26120293857125154,0.26020917561424783,0.2592154126572441,0.2582216497002405,0.25722788674323677,0.25623412378623306,0.25524036082922935,0.25424659787222564,0.25325283491522194,0.25225907195821823,0.2512653090012145,0.2502715460442108,0.2492777830872071,0.2482840201302034,0.2472902571731997,0.24629649421619598,0.24530273125919227,0.24430896830218857,0.24331520534518486,0.24232144238818115,0.24132767943117744,0.24033391647417376,0.23934015351717006,0.23834639056016635,0.23735262760316264,0.23635886464615893,0.23536510168915523,0.23437133873215152,0.2333775757751478,0.2323838128181441,0.2313900498611404,0.2303962869041367,0.22940252394713298,0.22840876099012927,0.22741499803312556,0.22642123507612189,0.22542747211911818,0.22443370916211447,0.22343994620511076,0.22244618324810705,0.22145242029110335,0.22045865733409964,0.21946489437709593,0.21847113142009222,0.21747736846308852,0.2164836055060848,0.2154898425490811,0.2144960795920774,0.2135023166350737,0.21250855367807,0.2115147907210663,0.2105210277640626,0.20952726480705888,0.20853350185005518,0.20753973889305147,0.20654597593604776,0.20555221297904405,0.20455845002204034,0.20356468706503664,0.20257092410803293,0.20157716115102922,0.20058339819402554,0.19958963523702183,0.19859587228001813,0.19760210932301442,0.1966083463660107,0.195614583409007,0.1946208204520033,0.1936270574949996,0.19263329453799588,0.19163953158099217,0.19064576862398847,0.18965200566698476,0.18865824270998105,0.18766447975297737,0.18667071679597366,0.18567695383896995,0.18468319088196625],\"type\":\"scatter\",\"name\":\"Linear policy\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]},{\"fillcolor\":\"RGBA(255, 0, 0, 0.2)\",\"y\":[0.28318177262692096,0.28226142830638545,0.2813278718055469,0.2803724337801543,0.27940576381055615,0.2784401419019473,0.2774720040745158,0.27649503697545486,0.2755112291779802,0.2745243066101979,0.27353413446895,0.2725396415509343,0.27154136076236235,0.27054024610985034,0.26953654419639117,0.2685302887209804,0.2675217686362655,0.2665113496313932,0.2654992616605476,0.26448568420955015,0.2634708278114075,0.26245491152090544,0.2614381182398998,0.26042061403818656,0.25940256155225394,0.25838411997254573,0.257365432755033,0.25634663456658646,0.255327852630509,0.2543092092359718,0.25329081709429674,0.2522727828757235,0.25125520658199774,0.25023818366755246,0.2492218028967308,0.24820614839822394,0.24719129896395847,0.24617732949190074,0.24516430995859712,0.24415230662420748,0.2431413815928884,0.24213159368960185,0.24112299803118947,0.24011564668935886,0.23910958853614717,0.23810486970262523,0.23710153349616575,0.2360996207020385,0.23509916964029615,0.23410021633445766,0.23310279463098169,0.23210693626121628,0.2311126710474914,0.23012002687912447,0.22912902997917664,0.22813970481152457,0.2271520743656748,0.2261661600082782,0.2251819818225812,0.22419955842069822,0.22321890725756652,0.2222400444047229,0.22126298495518382,0.22028774278954374,0.21931433085569432,0.2183427608881358,0.21737304391221154,0.2164051900178896,0.21543920848809234,0.21447510744669962,0.21351289458411,0.21255257702892694,0.21159416109473117,0.2106376517523082,0.20968305391562037,0.20873037263879762,0.20777961188249666,0.20683077342782863,0.2058838597728475,0.20493887542959782,0.20399582269365463,0.20305469842751833,0.2021155026104815,0.20117824417947322,0.20024292526831938,0.19930952803468877,0.19837804746571985,0.1974485201511654,0.1965209556834806,0.1955952697884713,0.19467143292491523,0.19374962503247348,0.19282991742425273,0.19191192006746158,0.1909954347377871,0.19008120263666012,0.18916972167984855,0.1882599370090073,0.18735066933097788,0.18644156327667488],\"type\":\"scatter\",\"name\":\"Non-linear policy\",\"fill\":\"tonextx\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]}]}",
"text/html": [
"<div id=\"1e052bc6-cc37-454b-a705-4e259298d305\" class=\"plotly-graph-div\"></div>\n",
"\n",
"<script>\n",
" window.PLOTLYENV=window.PLOTLYENV || {};\n",
" window.PLOTLYENV.BASE_URL=\"https://plot.ly\";\n",
" require(['plotly'], function(Plotly) {\n",
" Plotly.newPlot('1e052bc6-cc37-454b-a705-4e259298d305', [{\"y\":[0.2830657236253331,0.2820719606683294,0.2810781977113257,0.280084434754322,0.2790906717973183,0.27809690884031457,0.27710314588331086,0.27610938292630716,0.27511561996930345,0.27412185701229974,0.27312809405529603,0.2721343310982923,0.2711405681412886,0.2701468051842849,0.2691530422272812,0.2681592792702775,0.2671655163132738,0.2661717533562701,0.2651779903992664,0.26418422744226266,0.26319046448525896,0.26219670152825525,0.26120293857125154,0.26020917561424783,0.2592154126572441,0.2582216497002405,0.25722788674323677,0.25623412378623306,0.25524036082922935,0.25424659787222564,0.25325283491522194,0.25225907195821823,0.2512653090012145,0.2502715460442108,0.2492777830872071,0.2482840201302034,0.2472902571731997,0.24629649421619598,0.24530273125919227,0.24430896830218857,0.24331520534518486,0.24232144238818115,0.24132767943117744,0.24033391647417376,0.23934015351717006,0.23834639056016635,0.23735262760316264,0.23635886464615893,0.23536510168915523,0.23437133873215152,0.2333775757751478,0.2323838128181441,0.2313900498611404,0.2303962869041367,0.22940252394713298,0.22840876099012927,0.22741499803312556,0.22642123507612189,0.22542747211911818,0.22443370916211447,0.22343994620511076,0.22244618324810705,0.22145242029110335,0.22045865733409964,0.21946489437709593,0.21847113142009222,0.21747736846308852,0.2164836055060848,0.2154898425490811,0.2144960795920774,0.2135023166350737,0.21250855367807,0.2115147907210663,0.2105210277640626,0.20952726480705888,0.20853350185005518,0.20753973889305147,0.20654597593604776,0.20555221297904405,0.20455845002204034,0.20356468706503664,0.20257092410803293,0.20157716115102922,0.20058339819402554,0.19958963523702183,0.19859587228001813,0.19760210932301442,0.1966083463660107,0.195614583409007,0.1946208204520033,0.1936270574949996,0.19263329453799588,0.19163953158099217,0.19064576862398847,0.18965200566698476,0.18865824270998105,0.18766447975297737,0.18667071679597366,0.18567695383896995,0.18468319088196625],\"type\":\"scatter\",\"name\":\"Linear policy\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]},{\"fillcolor\":\"RGBA(255, 0, 0, 0.2)\",\"y\":[0.28318177262692096,0.28226142830638545,0.2813278718055469,0.2803724337801543,0.27940576381055615,0.2784401419019473,0.2774720040745158,0.27649503697545486,0.2755112291779802,0.2745243066101979,0.27353413446895,0.2725396415509343,0.27154136076236235,0.27054024610985034,0.26953654419639117,0.2685302887209804,0.2675217686362655,0.2665113496313932,0.2654992616605476,0.26448568420955015,0.2634708278114075,0.26245491152090544,0.2614381182398998,0.26042061403818656,0.25940256155225394,0.25838411997254573,0.257365432755033,0.25634663456658646,0.255327852630509,0.2543092092359718,0.25329081709429674,0.2522727828757235,0.25125520658199774,0.25023818366755246,0.2492218028967308,0.24820614839822394,0.24719129896395847,0.24617732949190074,0.24516430995859712,0.24415230662420748,0.2431413815928884,0.24213159368960185,0.24112299803118947,0.24011564668935886,0.23910958853614717,0.23810486970262523,0.23710153349616575,0.2360996207020385,0.23509916964029615,0.23410021633445766,0.23310279463098169,0.23210693626121628,0.2311126710474914,0.23012002687912447,0.22912902997917664,0.22813970481152457,0.2271520743656748,0.2261661600082782,0.2251819818225812,0.22419955842069822,0.22321890725756652,0.2222400444047229,0.22126298495518382,0.22028774278954374,0.21931433085569432,0.2183427608881358,0.21737304391221154,0.2164051900178896,0.21543920848809234,0.21447510744669962,0.21351289458411,0.21255257702892694,0.21159416109473117,0.2106376517523082,0.20968305391562037,0.20873037263879762,0.20777961188249666,0.20683077342782863,0.2058838597728475,0.20493887542959782,0.20399582269365463,0.20305469842751833,0.2021155026104815,0.20117824417947322,0.20024292526831938,0.19930952803468877,0.19837804746571985,0.1974485201511654,0.1965209556834806,0.1955952697884713,0.19467143292491523,0.19374962503247348,0.19282991742425273,0.19191192006746158,0.1909954347377871,0.19008120263666012,0.18916972167984855,0.1882599370090073,0.18735066933097788,0.18644156327667488],\"type\":\"scatter\",\"name\":\"Non-linear policy\",\"fill\":\"tonextx\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]}],\n",
" {\"xaxis\":{\"title\":\"Capital\"},\"annotations\":[{\"y\":0.23387445725364966,\"ay\":-50,\"text\":\"Perturbation point\",\"x\":9.354978290145986}],\"margin\":{\"l\":50,\"b\":50,\"r\":50,\"t\":60}}, {showLink: false});\n",
"\n",
" });\n",
" </script>\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.plotly.v1+json": "{\"layout\":{\"xaxis\":{\"title\":\"Capital\"},\"annotations\":[{\"y\":0.23387445725364966,\"ay\":-50,\"text\":\"Perturbation point\",\"x\":9.354978290145986}],\"margin\":{\"l\":50,\"b\":50,\"r\":50,\"t\":60},\"title\":\"Investment choice (η = 2)\"},\"data\":[{\"y\":[0.24988655803090393,0.24956308124752508,0.2492396044641462,0.24891612768076732,0.24859265089738844,0.24826917411400956,0.24794569733063068,0.24762222054725183,0.24729874376387295,0.24697526698049407,0.2466517901971152,0.24632831341373632,0.24600483663035744,0.2456813598469786,0.2453578830635997,0.24503440628022083,0.24471092949684195,0.24438745271346307,0.2440639759300842,0.24374049914670534,0.24341702236332646,0.24309354557994758,0.2427700687965687,0.24244659201318983,0.24212311522981095,0.2417996384464321,0.24147616166305322,0.24115268487967434,0.24082920809629546,0.24050573131291658,0.2401822545295377,0.23985877774615882,0.23953530096277997,0.2392118241794011,0.23888834739602222,0.23856487061264334,0.23824139382926446,0.2379179170458856,0.23759444026250673,0.23727096347912785,0.23694748669574897,0.2366240099123701,0.2363005331289912,0.23597705634561236,0.23565357956223348,0.2353301027788546,0.23500662599547573,0.23468314921209685,0.23435967242871797,0.2340361956453391,0.23371271886196024,0.23338924207858136,0.23306576529520248,0.2327422885118236,0.23241881172844472,0.23209533494506585,0.23177185816168697,0.23144838137830812,0.23112490459492924,0.23080142781155036,0.23047795102817148,0.2301544742447926,0.22983099746141372,0.22950752067803487,0.229184043894656,0.2288605671112771,0.22853709032789823,0.22821361354451936,0.22789013676114048,0.22756665997776163,0.22724318319438275,0.22691970641100387,0.226596229627625,0.2262727528442461,0.22594927606086723,0.22562579927748838,0.2253023224941095,0.22497884571073062,0.22465536892735175,0.22433189214397287,0.224008415360594,0.22368493857721514,0.22336146179383626,0.22303798501045738,0.2227145082270785,0.22239103144369962,0.22206755466032074,0.2217440778769419,0.221420601093563,0.22109712431018413,0.22077364752680526,0.22045017074342638,0.2201266939600475,0.21980321717666865,0.21947974039328977,0.2191562636099109,0.218832786826532,0.21850931004315313,0.21818583325977425,0.2178623564763954],\"type\":\"scatter\",\"name\":\"Linear policy\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]},{\"fillcolor\":\"RGBA(255, 0, 0, 0.2)\",\"y\":[0.24538824832858613,0.24534693007286396,0.24528516980750553,0.2451894668577091,0.24507583936087782,0.2449627539064333,0.24484427438949635,0.244710300586008,0.24456385743535863,0.24441067675686312,0.24425018288158132,0.24408030736066913,0.24390180417052243,0.243716157790665,0.24352354777481072,0.2433237750652511,0.24311719855727387,0.24290434635963098,0.24268545987934384,0.24246068049130637,0.24223026126415997,0.24199449286362726,0.2417535885893801,0.24150772912046536,0.2412571152528394,0.24100195423286663,0.24074242523995895,0.2404786931798894,0.24021092291777763,0.23993927796814635,0.23966390820055053,0.23938495533540008,0.23910255674083997,0.23881684650703233,0.23852795051168735,0.23823598906753685,0.2379410777120715,0.23764332842008623,0.23734284753004242,0.23703973715025486,0.23673409516724764,0.23642601611731767,0.23611559036414742,0.23580290484495708,0.2354880430057216,0.23517108529627945,0.23485210894417402,0.23453118829485886,0.23420839487111964,0.2338837975635925,0.23355746271653888,0.2332294541967347,0.23289983359948138,0.23256866021671602,0.23223599131316153,0.2319018820095216,0.23156638559258,0.2312295533274017,0.23089143486353897,0.23055207799594246,0.23021152901131176,0.22986983238879583,0.22952703134539434,0.22918316753427742,0.2288382813108849,0.22849241133157844,0.22814559534321077,0.22779786990592682,0.22744927033879775,0.22709983014880797,0.2267495823831654,0.22639855957205418,0.2260467927869973,0.22569431061862205,0.22534114196569377,0.22498731675332878,0.22463286261662122,0.22427780247183127,0.22392216125059888,0.22356596920994476,0.2232092517511914,0.22285202212143765,0.22249430040088808,0.22213612638797928,0.2217775264415792,0.22141848674017417,0.22105901690607815,0.22069920405571067,0.2203390896469688,0.2199785531655088,0.2196175609335831,0.21925641828016093,0.21889526444240887,0.2185335224725473,0.21817090936271147,0.21780858772420958,0.21744730023764353,0.21708523887022946,0.2167207230037107,0.21635467396459443],\"type\":\"scatter\",\"name\":\"Non-linear policy\",\"fill\":\"tonextx\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]}]}",
"text/html": [
"<div id=\"ce69664d-6cab-4640-a2db-d77b75c0d0a2\" class=\"plotly-graph-div\"></div>\n",
"\n",
"<script>\n",
" window.PLOTLYENV=window.PLOTLYENV || {};\n",
" window.PLOTLYENV.BASE_URL=\"https://plot.ly\";\n",
" require(['plotly'], function(Plotly) {\n",
" Plotly.newPlot('ce69664d-6cab-4640-a2db-d77b75c0d0a2', [{\"y\":[0.24988655803090393,0.24956308124752508,0.2492396044641462,0.24891612768076732,0.24859265089738844,0.24826917411400956,0.24794569733063068,0.24762222054725183,0.24729874376387295,0.24697526698049407,0.2466517901971152,0.24632831341373632,0.24600483663035744,0.2456813598469786,0.2453578830635997,0.24503440628022083,0.24471092949684195,0.24438745271346307,0.2440639759300842,0.24374049914670534,0.24341702236332646,0.24309354557994758,0.2427700687965687,0.24244659201318983,0.24212311522981095,0.2417996384464321,0.24147616166305322,0.24115268487967434,0.24082920809629546,0.24050573131291658,0.2401822545295377,0.23985877774615882,0.23953530096277997,0.2392118241794011,0.23888834739602222,0.23856487061264334,0.23824139382926446,0.2379179170458856,0.23759444026250673,0.23727096347912785,0.23694748669574897,0.2366240099123701,0.2363005331289912,0.23597705634561236,0.23565357956223348,0.2353301027788546,0.23500662599547573,0.23468314921209685,0.23435967242871797,0.2340361956453391,0.23371271886196024,0.23338924207858136,0.23306576529520248,0.2327422885118236,0.23241881172844472,0.23209533494506585,0.23177185816168697,0.23144838137830812,0.23112490459492924,0.23080142781155036,0.23047795102817148,0.2301544742447926,0.22983099746141372,0.22950752067803487,0.229184043894656,0.2288605671112771,0.22853709032789823,0.22821361354451936,0.22789013676114048,0.22756665997776163,0.22724318319438275,0.22691970641100387,0.226596229627625,0.2262727528442461,0.22594927606086723,0.22562579927748838,0.2253023224941095,0.22497884571073062,0.22465536892735175,0.22433189214397287,0.224008415360594,0.22368493857721514,0.22336146179383626,0.22303798501045738,0.2227145082270785,0.22239103144369962,0.22206755466032074,0.2217440778769419,0.221420601093563,0.22109712431018413,0.22077364752680526,0.22045017074342638,0.2201266939600475,0.21980321717666865,0.21947974039328977,0.2191562636099109,0.218832786826532,0.21850931004315313,0.21818583325977425,0.2178623564763954],\"type\":\"scatter\",\"name\":\"Linear policy\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]},{\"fillcolor\":\"RGBA(255, 0, 0, 0.2)\",\"y\":[0.24538824832858613,0.24534693007286396,0.24528516980750553,0.2451894668577091,0.24507583936087782,0.2449627539064333,0.24484427438949635,0.244710300586008,0.24456385743535863,0.24441067675686312,0.24425018288158132,0.24408030736066913,0.24390180417052243,0.243716157790665,0.24352354777481072,0.2433237750652511,0.24311719855727387,0.24290434635963098,0.24268545987934384,0.24246068049130637,0.24223026126415997,0.24199449286362726,0.2417535885893801,0.24150772912046536,0.2412571152528394,0.24100195423286663,0.24074242523995895,0.2404786931798894,0.24021092291777763,0.23993927796814635,0.23966390820055053,0.23938495533540008,0.23910255674083997,0.23881684650703233,0.23852795051168735,0.23823598906753685,0.2379410777120715,0.23764332842008623,0.23734284753004242,0.23703973715025486,0.23673409516724764,0.23642601611731767,0.23611559036414742,0.23580290484495708,0.2354880430057216,0.23517108529627945,0.23485210894417402,0.23453118829485886,0.23420839487111964,0.2338837975635925,0.23355746271653888,0.2332294541967347,0.23289983359948138,0.23256866021671602,0.23223599131316153,0.2319018820095216,0.23156638559258,0.2312295533274017,0.23089143486353897,0.23055207799594246,0.23021152901131176,0.22986983238879583,0.22952703134539434,0.22918316753427742,0.2288382813108849,0.22849241133157844,0.22814559534321077,0.22779786990592682,0.22744927033879775,0.22709983014880797,0.2267495823831654,0.22639855957205418,0.2260467927869973,0.22569431061862205,0.22534114196569377,0.22498731675332878,0.22463286261662122,0.22427780247183127,0.22392216125059888,0.22356596920994476,0.2232092517511914,0.22285202212143765,0.22249430040088808,0.22213612638797928,0.2217775264415792,0.22141848674017417,0.22105901690607815,0.22069920405571067,0.2203390896469688,0.2199785531655088,0.2196175609335831,0.21925641828016093,0.21889526444240887,0.2185335224725473,0.21817090936271147,0.21780858772420958,0.21744730023764353,0.21708523887022946,0.2167207230037107,0.21635467396459443],\"type\":\"scatter\",\"name\":\"Non-linear policy\",\"fill\":\"tonextx\",\"x\":[4.677489145072993,4.771983875276488,4.8664786054799825,4.9609733356834775,5.055468065886973,5.149962796090467,5.244457526293962,5.338952256497457,5.433446986700952,5.527941716904446,5.622436447107941,5.716931177311436,5.811425907514931,5.905920637718426,6.000415367921921,6.094910098125415,6.18940482832891,6.283899558532405,6.3783942887359,6.472889018939394,6.5673837491428895,6.6618784793463846,6.756373209549879,6.850867939753374,6.945362669956869,7.039857400160363,7.134352130363858,7.228846860567353,7.323341590770848,7.4178363209743425,7.512331051177838,7.606825781381333,7.701320511584827,7.795815241788322,7.890309971991817,7.984804702195311,8.079299432398807,8.1737941626023,8.268288892805796,8.36278362300929,8.457278353212786,8.55177308341628,8.646267813619776,8.74076254382327,8.835257274026764,8.92975200423026,9.024246734433754,9.11874146463725,9.213236194840745,9.30773092504424,9.402225655247733,9.496720385451228,9.591215115654723,9.685709845858218,9.780204576061713,9.874699306265208,9.969194036468704,10.063688766672197,10.158183496875692,10.252678227079187,10.347172957282682,10.441667687486177,10.536162417689672,10.630657147893166,10.72515187809666,10.819646608300156,10.91414133850365,11.008636068707146,11.103130798910641,11.197625529114136,11.29212025931763,11.386614989521124,11.48110971972462,11.575604449928115,11.67009918013161,11.764593910335105,11.859088640538598,11.953583370742093,12.048078100945588,12.142572831149083,12.237067561352578,12.331562291556073,12.426057021759568,12.520551751963062,12.615046482166557,12.709541212370052,12.804035942573547,12.898530672777042,12.993025402980537,13.087520133184032,13.182014863387526,13.27650959359102,13.371004323794516,13.46549905399801,13.559993784201506,13.654488514405001,13.748983244608494,13.84347797481199,13.937972705015484,14.03246743521898]}],\n",
" {\"xaxis\":{\"title\":\"Capital\"},\"annotations\":[{\"y\":0.23387445725364966,\"ay\":-50,\"text\":\"Perturbation point\",\"x\":9.354978290145986}],\"margin\":{\"l\":50,\"b\":50,\"r\":50,\"t\":60},\"title\":\"Investment choice (η = 2)\"}, {showLink: false});\n",
"\n",
" });\n",
" </script>\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# make new plot for investment\n",
"# (intuition -- when we work less, capital is less valuable, so investment lowers...\n",
"# raising eta made things more non-linear, so linear model does worse)\n",
"p_i2 = plot_policies(model, :k, :i, res_linear2, res_nonlin2, bounds)\n",
"relayout!(p_i2, title=\"Investment choice (η = 2)\")\n",
"display(p_i)\n",
"display(p_i2)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### Dyno.jl\n",
"\n",
"- Prototype of Julia version of Dynare\n",
"- Leverages Dolang as compiler"
]
},
{
"cell_type": "raw",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Thanks\n",
"\n",
"- Thanks to Pablo Winant -- started dolo.py for his thesis and continued at IMF and Bank of England\n",
"- Dolo.jl: Started at Bank of England with Pablo, Anastasia Zhutova, James Graham, and me\n",
"- Dolang.jl: Written by Pablo and me\n",
"- Financial support from QuantEcon\n",
"- Thanks JuliaCon committee for accepting the talk"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"celltoolbar": "Slideshow",
"gist": {
"data": {
"description": "Intro.ipynb",
"public": false
},
"id": ""
},
"kernelspec": {
"display_name": "Julia 0.6.0-rc1",
"language": "julia",
"name": "julia-0.6"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.6.1"
},
"livereveal": {
"scroll": true,
"start_slideshow_at": "selected",
"theme": "white",
"transition": "fade"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment