HSG-MCS-HS21_Julia/Problemsets/Solutions/PS01_Basics_Solution.ipynb

1689 lines
126 KiB
Plaintext
Raw Permalink Normal View History

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Basic Julia Tutorial"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Running/Installing Julia\n",
"\n",
"This is a notebook. To run in you need Julia and jupyter or nteract (see below).\n",
"\n",
"1. To run Julia without a local installation, use (for instance) [CoCalc](https://cocalc.com).\n",
"\n",
"2. To install Julia on your machine, [download and install it](https://julialang.org/downloads/). \n",
"\n",
"3. You may also want to use [VS Code with the Julia extension](https://github.com/julia-vscode/julia-vscode) IDE. See also the [julia-vscode.org](https://www.julia-vscode.org/) for more information.\n",
"\n",
"4. To run notebooks with either jupyter or nteract from your local installation, see [IJulia](https://github.com/JuliaLang/IJulia.jl) for instructions. See also below for some hints.\n",
"\n",
"5. As an alternative to jupyter/nteract you can also run notebooks in VS Code (see above).\n",
"\n",
"\n",
"\n",
"## More Details on Installing jupyter and nteract\n",
"\n",
"1. If you want to use nteract do as follows: install IJulia, but do *not* call on `notebook()` to avoid the automatic Python installation. Then install nteract.\n",
"\n",
"2. After installing IJulia and issuing the command `notebook()` a new local Python installation will be made - unless IJulia finds an existing installation.\n",
"\n",
"3. If you already have a Python installation, run `ENV[\"JUPYTER\"] = \"C:\\\\Miniconda3\\\\Scripts\\\\jupyter.exe\"` (change the path as needed) before you install IJulia. The best is perhaps to add this to your startup.jl file (~/.julia/config/startup.jl, for instance, C:\\Users\\yourusername\\.julia\\config\\startup.jl if you are on Windows). You can test whether it works by running ```run(`$(ENV[\"JUPYTER\"]) --version`)``` from the Julia REPL.\n",
"\n",
"4. On Windows, it helps to allow the Python installer to add python to the system path."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Documentation and Help\n",
"\n",
"1. Cheat sheet at [QuantEcon](https://cheatsheets.quantecon.org/julia-cheatsheet.html)\n",
"2. [Wiki book](https://en.wikibooks.org/wiki/Introducing_Julia)\n",
"3. [Short tutorials](https://techytok.com/from-zero-to-julia/) \n",
"4. [ThinkJulia](https://benlauwens.github.io/ThinkJulia.jl/latest/book.html) is a free on-line book\n",
"5. The [official Julia on-line manual](https://docs.julialang.org)\n",
"6. Discussion lists are found at\n",
" * https://discourse.julialang.org/\n",
" * https://stackoverflow.com/questions/tagged/julia-lang\n",
" * https://www.reddit.com/r/Julia/\n",
" * https://gitter.im/JuliaLang/julia\n",
"7. In Julia, do ```? cos``` to get help with the cos function "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# About Notebooks\n",
"\n",
"This cell is a \"Markdown\" cell. This is meant for comments and documentation, not computations.\n",
"\n",
"You can change a cell to \"Code\" or \"Markdown\" in the menu.\n",
"\n",
"Markdown cells can handle LaTeX. An example: $\\alpha = \\beta/2$. A Markdown cell can also contain some *formatting*, like lists of this kind\n",
"\n",
"1. To insert a new cell, use the menu. \n",
"\n",
"2. The next cell is \"Code\". You can run it. Text after a # sign is treated as a comment.\n",
"\n",
"3. The subsequent cell shows how to get help on a command."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = 2 #this is a comment\n",
" #run this cell by using the menu, or by Shift+Enter"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"search: \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22m \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22mh \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22md \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22mc \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22mpi a\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22m a\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22mh a\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22md sin\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22m sin\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22md sin\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22mpi \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22mn\u001b[0m\u001b[1ms\u001b[22mt\n",
"\n"
]
},
{
"data": {
"text/latex": [
"\\begin{verbatim}\n",
"cos(x)\n",
"\\end{verbatim}\n",
"Compute cosine of \\texttt{x}, where \\texttt{x} is in radians.\n",
"\n",
"\\rule{\\textwidth}{1pt}\n",
"\\begin{verbatim}\n",
"cos(A::AbstractMatrix)\n",
"\\end{verbatim}\n",
"Compute the matrix cosine of a square matrix \\texttt{A}.\n",
"\n",
"If \\texttt{A} is symmetric or Hermitian, its eigendecomposition (\\href{@ref}{\\texttt{eigen}}) is used to compute the cosine. Otherwise, the cosine is determined by calling \\href{@ref}{\\texttt{exp}}.\n",
"\n",
"\\section{Examples}\n",
"\\begin{verbatim}\n",
"julia> cos(fill(1.0, (2,2)))\n",
"2×2 Matrix{Float64}:\n",
" 0.291927 -0.708073\n",
" -0.708073 0.291927\n",
"\\end{verbatim}\n"
],
"text/markdown": [
"```\n",
"cos(x)\n",
"```\n",
"\n",
"Compute cosine of `x`, where `x` is in radians.\n",
"\n",
"---\n",
"\n",
"```\n",
"cos(A::AbstractMatrix)\n",
"```\n",
"\n",
"Compute the matrix cosine of a square matrix `A`.\n",
"\n",
"If `A` is symmetric or Hermitian, its eigendecomposition ([`eigen`](@ref)) is used to compute the cosine. Otherwise, the cosine is determined by calling [`exp`](@ref).\n",
"\n",
"# Examples\n",
"\n",
"```jldoctest\n",
"julia> cos(fill(1.0, (2,2)))\n",
"2×2 Matrix{Float64}:\n",
" 0.291927 -0.708073\n",
" -0.708073 0.291927\n",
"```\n"
],
"text/plain": [
"\u001b[36m cos(x)\u001b[39m\n",
"\n",
" Compute cosine of \u001b[36mx\u001b[39m, where \u001b[36mx\u001b[39m is in radians.\n",
"\n",
" ────────────────────────────────────────────────────────────────────────────\n",
"\n",
"\u001b[36m cos(A::AbstractMatrix)\u001b[39m\n",
"\n",
" Compute the matrix cosine of a square matrix \u001b[36mA\u001b[39m.\n",
"\n",
" If \u001b[36mA\u001b[39m is symmetric or Hermitian, its eigendecomposition (\u001b[36meigen\u001b[39m) is used to\n",
" compute the cosine. Otherwise, the cosine is determined by calling \u001b[36mexp\u001b[39m.\n",
"\n",
"\u001b[1m Examples\u001b[22m\n",
"\u001b[1m ≡≡≡≡≡≡≡≡≡≡\u001b[22m\n",
"\n",
"\u001b[36m julia> cos(fill(1.0, (2,2)))\u001b[39m\n",
"\u001b[36m 2×2 Matrix{Float64}:\u001b[39m\n",
"\u001b[36m 0.291927 -0.708073\u001b[39m\n",
"\u001b[36m -0.708073 0.291927\u001b[39m"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"? cos #to get help on the cos() function"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Load Packages and Extra Functions\n",
"\n",
"There are many packages for Julia, for instance, for plotting or statistical methods (see [JuliaHub](https://juliahub.com/) for a list). To install a package, you do either \n",
"\n",
"1. (works everywhere) run `import Pkg` and then `Pkg.add(\"Packagename\")`\n",
"\n",
"2. (works in the Julia console, REPL) enter the \"package manager mode\" by typing `]`, then run `add PackageName`. You leave the package manager mode by ctrl-c or backspace.\n",
"\n",
"Once a package is installed, you can use it by running\n",
"\n",
"```\n",
"using PackageName\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"printyellow (generic function with 1 method)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"using Printf\n",
"\n",
"include(\"jlFiles/printmat.jl\") #just a function for prettier matrix printing"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"using Plots #this loads the Plots package\n",
"\n",
"#pyplot(size=(600,400)) #choice of plotting backend\n",
"gr(size=(480,320))\n",
"default(fmt = :svg) #try :png or :svg"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Scalars and Matrices\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Create a Scalar and a Matrix"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"q is a scalar. To print, use println() or printlnPs()\n",
"1\n",
"\n",
"Q is a matrix. To print, use display() or printmat()\n",
" 1 2 3 \n",
" 4 5 6 \n",
"\n"
]
}
],
"source": [
"q = 1 #create a scalar\n",
"Q = [ 1 2 3; #create 2x3 matrix\n",
" 4 5 6 ] \n",
"println(\"q is a scalar. To print, use println() or printlnPs()\")\n",
"println(q)\n",
"\n",
"println(\"\\nQ is a matrix. To print, use display() or printmat()\")\n",
"printmat(Q) #case sensitive (q and Q are different)\n",
" #the \\n adds a line break"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Picking Out Parts of a Matrix"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"element [1,2] of Q: 2\n",
"\n",
"columns 2 and 3 of Q: \n",
" 2 3 \n",
" 5 6 \n",
"\n",
"\n",
"line 1 of Q (as a vector): \n",
" 1 \n",
" 2 \n",
" 3 \n",
"\n"
]
}
],
"source": [
"println(\"\\n\",\"element [1,2] of Q: \", #commands continue on\n",
" Q[1,2]) #the next line (until finished)\n",
"\n",
"println(\"\\ncolumns 2 and 3 of Q: \")\n",
"printmat(Q[:,2:3])\n",
"\n",
"println(\"\\nline 1 of Q (as a vector): \")\n",
"printmat(Q[1,:])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Task\n",
"Create a 2x2 matrix A\n",
"\n",
"```\n",
"10 10\n",
"21 22\n",
"```\n",
"\n",
"Print it\n",
"\n",
"Change the second row to `[1 2]`. Print again."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 10 10 \n",
" 21 22 \n",
"\n",
" 10 10 \n",
" 1 2 \n",
"\n"
]
}
],
"source": [
"A = [10 10;\n",
" 21 22]\n",
"printmat(A)\n",
"A[2,:] = [1 2]\n",
"printmat(A)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Basic Linear Algebra\n",
"\n",
"The syntax for linear algebra is similar to the standard text book approach. For instance, \n",
"* `Q'Q` (or `Q'*Q`) multiplies the transpose ($Q'$) with the matrix ($Q$)\n",
"* `A*B` does matrix multiplication\n",
"* `100*Q` multiplies each element of the matrix ($Q$) by 100. (You can also do `100Q`.)\n",
"\n",
"However, to add a scalar to each element of a matrix, use `100 .+ Q`. Notice the dot."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"transpose of Q:\n",
" 1 4 \n",
" 2 5 \n",
" 3 6 \n",
"\n",
"Q'Q:\n",
" 17 22 27 \n",
" 22 29 36 \n",
" 27 36 45 \n",
"\n",
"scalar * matrix:\n",
" 100 200 300 \n",
" 400 500 600 \n",
"\n",
"scalar .+ matrix:\n",
" 101 102 103 \n",
" 104 105 106 \n",
"\n"
]
}
],
"source": [
"println(\"transpose of Q:\")\n",
"printmat(Q')\n",
"\n",
"println(\"Q'Q:\")\n",
"printmat(Q'Q)\n",
"\n",
"println(\"scalar * matrix:\")\n",
"printmat(100*Q)\n",
"\n",
"println(\"scalar .+ matrix:\") #notice the dot\n",
"printmat(100 .+ Q)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Task\n",
"\n",
"Consider the system of linear equations\n",
"\n",
"$\n",
"Ax = q\n",
"$, \n",
"\n",
"where \n",
"$ \n",
"q = \\begin{bmatrix} 1 \\\\2 \\end{bmatrix}\n",
"$\n",
"\n",
"You could solve it as\n",
"$\n",
"x = A^{-1}q\n",
"$\n",
"\n",
"\n",
"Solve (numrically) for the vector $x$. Hint: `inv()` Then check that $Ax$ indeed equals $q$"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" x\n",
" -1.800\n",
" 1.900\n",
"\n",
" A*x q\n",
" 1.000 1.000\n",
" 2.000 2.000\n",
"\n"
]
}
],
"source": [
"\n",
"\n",
"\n",
"q = [1,2]\n",
"x = inv(A)*q\n",
"printmat(x,colNames=[\"x\"])\n",
"\n",
"printmat([A*x q],colNames=[\"A*x\",\"q\"])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Creating a Sequence and a Vector"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"θ is a sequence: 1:10:21\n",
"\n",
"ρ is a vector: \n",
" 1 \n",
" 11 \n",
" 21 \n",
"\n"
]
}
],
"source": [
"θ = 1:10:21 #a range, type \\theta[TAB] to get this symbol\n",
"println(\"\\n\",\"θ is a sequence: \",θ)\n",
"\n",
"ρ = collect(θ) #make the sequence into a vector, \\rho[TAB]\n",
"println(\"\\n\",\"ρ is a vector: \")\n",
"printmat(ρ)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Task\n",
"\n",
"Create a sequence $\\alpha$ which starts at 0 and ends at 1, taking 11 steps. (Hint: you can also use `range()`)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0.000\n",
" 0.100\n",
" 0.200\n",
" 0.300\n",
" 0.400\n",
" 0.500\n",
" 0.600\n",
" 0.700\n",
" 0.800\n",
" 0.900\n",
" 1.000\n",
"\n"
]
}
],
"source": [
"α = 0:0.1:1\n",
"#α = range(0,1,length=11)\n",
"printmat(α)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Comparing Things\n",
"\n",
"To see if the scalar z <= 0, do \n",
"```\n",
"vv = z <= 0\n",
"```\n",
"to get a single output (true or false).\n",
"\n",
"Instead, if x is an array, do \n",
"```\n",
"vv = x .<= 0 #notice the dot.\n",
"```\n",
"to get an array of outputs (same dimension as x)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"x values: \n",
" -1.500\n",
" -1.000\n",
" -0.500\n",
" 0.000\n",
" 0.500\n",
"\n",
"true if x is in (-1,0]: \n",
" 0 \n",
" 0 \n",
" 1 \n",
" 1 \n",
" 0 \n",
"\n",
"x values that are in (-1,0]: \n",
" -0.500\n",
" 0.000\n",
"\n"
]
}
],
"source": [
"x = [-1.5,-1.0,-0.5,0,0.5] #this is a vector\n",
"\n",
"println(\"x values: \")\n",
"printmat(x)\n",
"\n",
"vv = -1 .< x .<= 0 #true for x values (-1,0], vv is a vector\n",
"println(\"true if x is in (-1,0]: \")\n",
"printmat(vv)\n",
"\n",
"x2 = x[vv] #x values for which vv==true\n",
"println(\"x values that are in (-1,0]: \")\n",
"printmat(x2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Task\n",
"\n",
"Which elements of $\\alpha$ are (weakly) between 0.6 and 0.99?"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" vv[-1.5, -1.0, -0.5, 0.0, 0.5]\n",
" 0 0.000\n",
" 0 0.100\n",
" 0 0.200\n",
" 0 0.300\n",
" 0 0.400\n",
" 0 0.500\n",
" 1 0.600\n",
" 1 0.700\n",
" 1 0.800\n",
" 1 0.900\n",
" 0 1.000\n",
"\n"
]
}
],
"source": [
"vv = 0.6 .<= α .<= 0.99\n",
"printmat(vv,α,colNames=[\"vv\",x])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Finding Things\n",
"\n",
"can be done by, for instance, `findfirst()`, `findall()` and `indexin()`. \n",
"\n",
"Instead, if you just need to check if the number `z` is in an array (or any collection) `x`, then use `in(z,x)`."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"x values: \n",
" -1.500\n",
" -1.000\n",
" -0.500\n",
" 0.000\n",
" 0.500\n",
"\n",
"(first) index v in x such x[v]==0: 4\n",
"\n",
"all indices v in x such x[v]>=0: \n",
" 4 \n",
" 5 \n",
"\n",
"\n",
"indices in x so that x[v] equals the vector y=[-1.0, 0.0]: \n",
" 2 \n",
" 4 \n",
"\n",
"\n",
"testing if 0 is in x: true\n"
]
}
],
"source": [
"x = [-1.5,-1.0,-0.5,0,0.5] #this is a vector\n",
"\n",
"println(\"x values: \")\n",
"printmat(x)\n",
"\n",
"v1 = findfirst(x.==0)\n",
"println(\"(first) index v in x such x[v]==0: \",v1)\n",
"\n",
"v2 = findall(x.>=0)\n",
"println(\"\\nall indices v in x such x[v]>=0: \")\n",
"printmat(v2)\n",
"\n",
"y = [-1.0,0]\n",
"v3 = indexin(y,x)\n",
"println(\"\\nindices in x so that x[v] equals the vector y=$y: \")\n",
"printmat(v3)\n",
"\n",
"v4 = in(0,x)\n",
"println(\"\\ntesting if 0 is in x: \",v4)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# if-else\n",
"\n",
"allows you to run different comman ddepending on a condition which you specify.\n",
"\n",
"(extra) There are also other (more compact) possibilities for `if-else` case\n",
"\n",
"1. `y = ifelse(z <= 2,z,2)` or \n",
"2. `z <= 2 ? y = z : y = 2`\n",
"(In this partcular case, `y=minimum(z,2)` also works.)\n",
"\n",
"You can also insert an `ifelse` command."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.05\n"
]
}
],
"source": [
"z = 1.05\n",
"\n",
"if z <= 2 #(a) if true, run the next command (y=z) and then jump to end\n",
" y = z\n",
"else #(b) if (a) is false, do this instead\n",
" y = 2\n",
"end\n",
"\n",
"#y = ifelse(z <= 2,z,2) #these two versions also work\n",
"#z <= 2 ? y = z : y = 2\n",
"\n",
"println(y)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.05\n"
]
}
],
"source": [
"if z < 1 #(a) if true, run the next command (y=1) and then jump to end\n",
" y = 1\n",
"elseif 1 <= z <= 2 #(b) if (a) is false, try this instead \n",
" y = z\n",
"else #(c) if also (b) is false, do this\n",
" y = 2\n",
"end\n",
"\n",
"println(y)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Task\n",
"\n",
"\n",
"Use `if-else` to calculate the tax paid by someone with an income of $X$. The tax schedule is progressive so the first 100 of the income pays 40% tax, while income above 100 has a marginal tax rate of 0.6 (that is, $X-100$ pays 60% if $X>100)$. What is the total tax paid and the average tax rate.\n",
"Report the results for an income of 150."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 70.000 0.467\n",
"\n"
]
}
],
"source": [
"X = 150\n",
"\n",
"if X <= 100\n",
" tax = 0.4*X\n",
"else\n",
" tax = 0.4*100 + 0.6*(X-100)\n",
"end\n",
"\n",
"avgtax = tax/X\n",
"printmat(tax,avgtax)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Loops\n",
"\n",
"The are two types of loops: \"for loops\" and \"while loops\". \n",
"\n",
"The *for loop* is best when you know how many times you want to loop (for instance, over all $m$ rows in a matrix). \n",
"\n",
"The *while loop* is best when you want to keep looping until something happens, for instance, that $x_0$ and $x_1$ get really close.\n",
"\n",
"The default behaviour in *IJulia*, *inside functions* and at the *REPL* promt is that assignments of `x` inside the loop overwrites `x` defined before the loop. To get the same behavior in scripts, you need to add `global x` somewhere inside the loop.\n",
"\n",
"To make sure that the `y` calculated inside the loop does not affect `y` outside the loop, add `local y`.\n",
"\n",
"A variable (here `z2`) that does not exist before the loop is local to the loop."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### A Simple \"for loop\"\n",
"\n",
"The \"for loop\" in the next cell makes 3 iterations and changes a global $x$ variable."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"i=3, x=3 and z2=-998\n",
"i=6, x=9 and z2=-998\n",
"i=9, x=18 and z2=-998\n",
"\n",
"After loop: x=18 and y=-999\n"
]
}
],
"source": [
"x = 0\n",
"y = -999\n",
"for i = 3:3:9 #or `i in 3:3:9`, or `v=[3,6,9]; i in v`\n",
" #global x #only needed in script\n",
" local y #don't overwrite y outside loop\n",
" x = x + i #adding i to the \"old\" x\n",
" y = i\n",
" z2 = -998 #notice: z2 has not been used before \n",
" println(\"i=$i, x=$x and z2=$z2\") #$x prints the value of x\n",
"end\n",
"\n",
"println(\"\\nAfter loop: x=$x and y=$y\")\n",
"#println(z2) #does not work: z2 is local to the loop"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Task\n",
"\n",
"You have the following financial data\n",
"\n",
"```\n",
"P = [100;108;109] #price series, after dividends\n",
"D = [0;2;0] #dividends\n",
"```\n",
"\n",
"For each $t$, calculate the returns\n",
"\n",
"$\n",
"R_t = (P_t+D_t)/P_{t-1} - 1\n",
"$,\n",
"\n",
"by using a loop."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Return\n",
"period 2 0.100\n",
"period 3 0.009\n",
"\n"
]
}
],
"source": [
"P = [100;108;109] #price series, after dividends\n",
"D = [0;2;0] #dividends\n",
"\n",
"R = zeros(length(P)) #where to store the results\n",
"for t = 2:length(P) #P[2] is the 2nd element of P \n",
" R[t] = (P[t] + D[t])/P[t-1] - 1\n",
"end\n",
"R = R[2:end]\n",
"\n",
"printmat(R,colNames=[\"Return\"],rowNames=string.(\"period \",2:3))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### A Double \"for loop\"\n",
"\n",
"An example of a nested for for loop\n",
"\n",
"```\n",
"for j = 1:n, i = 1:m\n",
" #do something\n",
"end\n",
"```\n",
"\n",
"If you prefer, could also write a longer version to do the same thing\n",
"```\n",
"for j = 1:n \n",
" for i = 1:m\n",
" #do something\n",
" end \n",
"end\n",
"```\n",
"\n",
"The next cell uses a double loop to fill a matrix. "
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"new x matrix: \n",
"\n",
" 11 12 13 \n",
" 21 22 23 \n",
" 31 32 33 \n",
" 41 42 43 \n",
"\n"
]
}
],
"source": [
"(m,n) = (4,3) #same as m=4;n=3\n",
"x = fill(-999,(m,n)) #to put results in, initialized as -999\n",
"for i = 1:m, j = 1:n\n",
" x[i,j] = 10*i + j\n",
"end\n",
"\n",
"println(\"new x matrix: \\n\")\n",
"printmat(x)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## A Simple \"while loop\"\n",
"\n",
"The \"while loop\" in the next cell iterates until two variables ($x_0$ and $x_1$) get close.\n",
"\n",
"The background to the example is that we want to solve a function $f(x)=x^2$ for the $x$ value that makes $f(x)=2$. The Newton-Raphson algorithm starts with a value $x_0$ and updates it to\n",
"$\n",
"x_1 = x_0 + (2-f(x_0))/f'(x_0)\n",
"$\n",
"where $f'(x_0)$ is the derivative of $f()$ evaluated at $x_0$. The algorithm iterates until $x_0$ and $x_1$ are close. Clearly, we are trying to find the square root of 2."
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Solving x^2 = 2 with Newton-Raphson:\n",
"\n",
" 10 is changed to 5.100\n",
" 5.100 is changed to 2.746\n",
" 2.746 is changed to 1.737\n",
" 1.737 is changed to 1.444\n",
" 1.444 is changed to 1.415\n",
" 1.415 is changed to 1.414\n",
"\n",
"The result should be close to 1.414\n"
]
}
],
"source": [
"println(\"Solving x^2 = 2 with Newton-Raphson:\\n\")\n",
"\n",
"x₀ = Inf #x\\_0[TAB]\n",
"x₁ = 10\n",
"\n",
"while abs(x₁-x₀) > 0.001 #keep going until they get similar\n",
" #global x₀, x₁ #only needed in script\n",
" local y, dy #don't overwrite any y,dy outside loop\n",
" x₀ = x₁ #initial guess is taken from old guess\n",
" y = x₀^2 #value of function\n",
" dy = 2*x₀ #derivative of function\n",
" x₁ = x₀ + (2 - y)/dy #updating the guess, Newton-Raphson\n",
" printlnPs(x₀,\" is changed to \",x₁)\n",
"end\n",
"\n",
"printlnPs(\"\\nThe result should be close to \",sqrt(2))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Task\n",
"\n",
"Start at `x=1` and create a while loop that multiplies the previous $x$ by 1.1.(That is, you earn a 10% return each year.) Continue while `x<2`. Print the iterations (iteration number, `x`). So, how many years did it take to double the investment?"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 1 1.100\n",
" 2 1.210\n",
" 3 1.331\n",
" 4 1.464\n",
" 5 1.611\n",
" 6 1.772\n",
" 7 1.949\n",
" 8 2.144\n"
]
}
],
"source": [
"x = 1\n",
"iter = 0\n",
"while x < 2\n",
" x = x*1.1\n",
" iter = iter + 1 \n",
" printlnPs(iter,x)\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# A Simple Function\n",
"\n",
"The next cell defines a new function, `fn1()`. It takes a scalar input (`x`) and returns a scalar output (`y`).\n",
"\n",
"If you instead use a vector as the input, then the computation fails. (The reason is that you cannot do x^2 on a vector. You could on a square matrix, though.)\n",
"\n",
"However, using the \"dot\" syntax\n",
"```\n",
"y = fn1.(x)\n",
"```\n",
"gives an array as output where element `y[i,j] = fn1(x[i,j])`."
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"fn1 (generic function with 1 method)"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function fn1(x) #define a new function \n",
" y = (x-1.1)^2 - 0.5\n",
" return y\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"result from fn1(1.5): -0.340\n",
"\n",
"result from fn1.(x): \n",
" -0.490\n",
" -0.340\n",
"\n"
]
}
],
"source": [
"y = fn1(1.5)\n",
"printlnPs(\"result from fn1(1.5): \",y)\n",
"\n",
"x = [1;1.5]\n",
"#y = fn1(x) #would give an error \n",
"y = fn1.(x) #calling on the function, dot. to do for each element in x\n",
"printlnPs(\"\\nresult from fn1.(x): \")\n",
"printmat(y)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Task\n",
"\n",
"Write a function to calculate \n",
"$B =\\exp{(-my)}$, \n",
"where $B$ is the price of a bond and $m$ is the time to maturity (measured in years) and $y$ is the (continously compounded) interest rate.\n",
"\n",
"If $y=0.103$ and $m=0.5$, what is $B$?"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0.950\n"
]
}
],
"source": [
"BondPrice(y,m) = exp(-m*y) #B as fn of y\n",
"\n",
"printlnPs(BondPrice(0.103,0.5))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# A First Plot\n",
"\n",
"With the Plots package you create a a simple plot like this:\n",
"\n",
"1. Plot two curve by using the `plot([x1 x2],[y1 y2])` command\n",
"2. Configure curves by `linecolor =`, `linestyle =` etc\n",
"2. Add titles and labels by `title = `, `xlabel = `, etc\n",
"\n",
"Notice: the *first plot is slow*."
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"480\" height=\"320\" viewBox=\"0 0 1920 1280\">\n",
"<defs>\n",
" <clipPath id=\"clip760\">\n",
" <rect x=\"0\" y=\"0\" width=\"1920\" height=\"1280\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip760)\" d=\"\n",
"M0 1280 L1920 1280 L1920 0 L0 0 Z\n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<defs>\n",
" <clipPath id=\"clip761\">\n",
" <rect x=\"384\" y=\"0\" width=\"1345\" height=\"1280\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip760)\" d=\"\n",
"M199.164 1106.38 L1872.76 1106.38 L1872.76 123.472 L199.164 123.472 Z\n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<defs>\n",
" <clipPath id=\"clip762\">\n",
" <rect x=\"199\" y=\"123\" width=\"1675\" height=\"984\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<polyline clip-path=\"url(#clip762)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 422.551,1106.38 422.551,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip762)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 774.594,1106.38 774.594,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip762)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1126.64,1106.38 1126.64,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip762)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1478.68,1106.38 1478.68,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip762)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1830.72,1106.38 1830.72,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip760)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 199.164,1106.38 1872.76,1106.38 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip760)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 422.551,1106.38 422.551,1087.48 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip760)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 774.594,1106.38 774.594,1087.48 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip760)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1126.64,1106.38 1126.64,1087.48 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip760)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1478.68,1106.38 1478.68,1087.48 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip760)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1830.72,1106.38 1830.72,1087.48 \n",
" \"/>\n",
"<path clip-path=\"url(#clip760)\" d=\"M392.493 1146.38 L422.169 1146.38 L422.169 1150.32 L392.493 1150.32 L392.493 1146.38 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M436.289 1159.28 L452.609 1159.28 L452.609 1163.21 L430.664 1163.21 L430.664 1159.28 Q433.326 1156.52 437.91 1151.89 Q442.516 1147.24 443.697 1145.9 Q445.942 1143.37 446.822 1141.64 Q447.725 1139.88 447.725 1138.19 Q447.725 1135.43 445.78 1133.7 Q443.859 1131.96 440.757 1131.96 Q438.558 1131.96 436.104 1132.73 Q433.674 1133.49 430.896 1135.04 L430.896 1130.32 Q433.72 1129.18 436.174 1128.61 Q438.627 1128.03 440.664 1128.03 Q446.035 1128.03 449.229 1130.71 Q452.424 1133.4 452.424 1137.89 Q452.424 1140.02 451.613 1141.94 Q450.826 1143.84 448.72 1146.43 Q448.141 1147.1 445.039 1150.32 Q441.937 1153.51 436.289 1159.28 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M774.594 1131.73 Q770.983 1131.73 769.155 1135.3 Q767.349 1138.84 767.349 1145.97 Q767.349 1153.07 769.155 1156.64 Q770.983 1160.18 774.594 1160.18 Q778.229 1160.18 780.034 1156.64 Q781.863 1153.07 781.863 1145.97 Q781.863 1138.84 780.034 1135.3 Q778.229 1131.73 774.594 1131.73 M774.594 1128.03 Q780.404 1128.03 783.46 1132.63 Q786.539 1137.22 786.539 1145.97 Q786.539 1154.69 783.46 1159.3 Q780.404 1163.88 774.594 1163.88 Q768.784 1163.88 765.705 1159.3 Q762.65 1154.69 762.65 1145.97 Q762.65 1137.22 765.705 1132.63 Q768.784 1128.03 774.594 1128.03 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M1121.29 1159.28 L1137.61 1159.28 L1137.61 1163.21 L1115.67 1163.21 L1115.67 1159.28 Q1118.33 1156.52 1122.91 1151.89 Q1127.52 1147.24 1128.7 1145.9 Q1130.94 1143.37 1131.82 1141.64 Q1132.73 1139.88 1132.73 1138.19 Q1132.73 1135.43 1130.78 1133.7 Q1128.86 1131.96 1125.76 1131.96 Q1123.56 1131.96 1121.11 1132.73 Q1118.67 1133.49 1115.9 1135.04 L1115.9 1130.32 Q1118.72 1129.18 1121.17 1128.61 Q1123.63 1128.03 1125.67 1128.03 Q1131.04 1128.03 1134.23 1130.71 Q1137.42 1133.4 1137.42 1137.89 Q1137.42 1140.02 1136.61 1141.94 Q1135.83 1143.84 1133.72 1146.43 Q1133.14 1147.1 1130.04 1150.32 Q1126.94 1153.51 1121.29 1159.28 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M1481.69 1132.73 L1469.88 1151.17 L1481.69 1151.17 L1481.69 1132.73 M1480.46 1128.65 L1486.34 1128.65 L1486.34 1151.17 L1491.27 1151.17 L1491.27 1155.06 L1486.34 1155.06 L1486.34 1163.21 L1481.69 1163.21 L1481.69 1155.06 L1466.09 1155.06 L1466.09 1150.55 L1480.46 1128.65 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M1831.13 1144.07 Q1827.98 1144.07 1826.13 1146.22 Q1824.3 1148.37 1824.3 1152.12 Q1824.3 1155.85 1826.13 1158.03 Q1827.98 1160.18 1831.13 1160.18 Q1834.28 1160.18 1836.11 1158.03 Q1837.96 1155.85 1837.96 1152.12 Q1837.96 1148.37 1836.11 1146.22 Q1834.28 1144.07 1831.13 1144.07 M1840.41 1129.42 L1840.41 1133.67 Q1838.65 1132.84 1836.85 1132.4 Q1835.06 1131.96 1833.31 1131.96 Q1828.68 1131.96 1826.22 1135.09 Q1823.79 1138.21 1823.44 1144.53 Q1824.81 1142.52 1826.87 1141.45 Q1828.93 1140.36 1831.41 1140.36 Q1836.62 1140.36 1839.62 1143.54 Q1842.66 1146.68 1842.66 1152.12 Q1842.66 1157.45 1839.51 1160.67 Q1836.36 1163.88 1831.13 1163.88 Q1825.13 1163.88 1821.96 1159.3 Q1818.79 1154.69 1818.79 1145.97 Q1818.79 1137.77 1822.68 1132.91 Q1826.57 1128.03 1833.12 1128.03 Q1834.88 1128.03 1836.66 1128.37 Q1838.47 1128.72 1840.41 1129.42 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M1052.57 1208.4 L1039.68 1225.74 L1053.24 1244.04 L1046.34 1244.04 L1035.96 1230.04 L1025.58 1244.04 L1018.68 1244.04 L1032.52 1225.39 L1019.85 1208.4 L1026.76 1208.4 L1036.21 1221.1 L1045.67 1208.4 L1052.57 1208.4 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><polyline clip-path=\"url(#clip762)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n
" 199.164,1040.27 1872.76,1040.27 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip762)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 199.164,848.798 1872.76,848.798 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip762)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 199.164,657.322 1872.76,657.322 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip762)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 199.164,465.846 1872.76,465.846 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip762)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 199.164,274.369 1872.76,274.369 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip760)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 199.164,1106.38 199.164,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip760)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 199.164,1040.27 218.061,1040.27 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip760)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 199.164,848.798 218.061,848.798 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip760)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 199.164,657.322 218.061,657.322 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip760)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 199.164,465.846 218.061,465.846 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip760)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 199.164,274.369 218.061,274.369 \n",
" \"/>\n",
"<path clip-path=\"url(#clip760)\" d=\"M158.419 1026.07 Q154.808 1026.07 152.979 1029.64 Q151.174 1033.18 151.174 1040.31 Q151.174 1047.42 152.979 1050.98 Q154.808 1054.52 158.419 1054.52 Q162.053 1054.52 163.859 1050.98 Q165.688 1047.42 165.688 1040.31 Q165.688 1033.18 163.859 1029.64 Q162.053 1026.07 158.419 1026.07 M158.419 1022.37 Q164.229 1022.37 167.285 1026.98 Q170.364 1031.56 170.364 1040.31 Q170.364 1049.04 167.285 1053.64 Q164.229 1058.23 158.419 1058.23 Q152.609 1058.23 149.53 1053.64 Q146.475 1049.04 146.475 1040.31 Q146.475 1031.56 149.53 1026.98 Q152.609 1022.37 158.419 1022.37 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M149.461 831.518 L167.817 831.518 L167.817 835.453 L153.743 835.453 L153.743 843.925 Q154.762 843.578 155.78 843.416 Q156.799 843.231 157.817 843.231 Q163.604 843.231 166.984 846.402 Q170.364 849.574 170.364 854.99 Q170.364 860.569 166.891 863.671 Q163.419 866.749 157.1 866.749 Q154.924 866.749 152.655 866.379 Q150.41 866.009 148.003 865.268 L148.003 860.569 Q150.086 861.703 152.308 862.259 Q154.53 862.814 157.007 862.814 Q161.012 862.814 163.35 860.708 Q165.688 858.601 165.688 854.99 Q165.688 851.379 163.35 849.273 Q161.012 847.166 157.007 847.166 Q155.132 847.166 153.257 847.583 Q151.405 848 149.461 848.879 L149.461 831.518 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M119.068 670.667 L126.706 670.667 L126.706 644.301 L118.396 645.968 L118.396 641.708 L126.66 640.042 L131.336 640.042 L131.336 670.667 L138.975 670.667 L138.975 674.602 L119.068 674.602 L119.068 670.667 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M158.419 643.121 Q154.808 643.121 152.979 646.685 Q151.174 650.227 151.174 657.357 Q151.174 664.463 152.979 668.028 Q154.808 671.569 158.419 671.569 Q162.053 671.569 163.859 668.028 Q165.688 664.463 165.688 657.357 Q165.688 650.227 163.859 646.685 Q162.053 643.121 158.419 643.121 M158.419 639.417 Q164.229 639.417 167.285 644.023 Q170.364 648.607 170.364 657.357 Q170.364 666.083 167.285 670.69 Q164.229 675.273 158.419 675.273 Q152.609 675.273 149.53 670.69 Q146.475 666.083 146.475 657.357 Q146.475 648.607 149.53 644.023 Q152.609 639.417 158.419 639.417 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M120.063 479.19 L127.702 479.19 L127.702 452.825 L119.392 454.491 L119.392 450.232 L127.655 448.566 L132.331 448.566 L132.331 479.19 L139.97 479.19 L139.97 483.126 L120.063 483.126 L120.063 479.19 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M149.461 448.566 L167.817 448.566 L167.817 452.501 L153.743 452.501 L153.743 460.973 Q154.762 460.626 155.78 460.464 Q156.799 460.278 157.817 460.278 Q163.604 460.278 166.984 463.45 Q170.364 466.621 170.364 472.038 Q170.364 477.616 166.891 480.718 Q163.419 483.797 157.1 483.797 Q154.924 483.797 152.655 483.426 Q150.41 483.056 148.003 482.315 L148.003 477.616 Q150.086 478.751 152.308 479.306 Q154.53 479.862 157.007 479.862 Q161.012 479.862 163.35 477.755 Q165.688 475.649 165.688 472.038 Q165.688 468.427 163.35 466.32 Q161.012 464.214 157.007 464.214 Q155.132 464.214 153.257 464.63 Q151.405 465.047 149.461 465.927 L149.461 448.566 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M122.285 287.714 L138.604 287.714 L138.604 291.649 L116.66 291.649 L116.66 287.714 Q119.322 284.959 123.905 280.33 Q128.512 275.677 129.692 274.335 Q131.938 271.811 132.817 270.075 Q133.72 268.316 133.72 266.626 Q133.72 263.872 131.776 262.136 Q129.855 260.399 126.753 260.399 Q124.554 260.399 122.1 261.163 Q119.669 261.927 116.892 263.478 L116.892 258.756 Q119.716 257.622 122.169 257.043 Q124.623 256.464 126.66 256.464 Q132.03 256.464 135.225 259.149 Q138.419 261.835 138.419 266.325 Q138.419 268.455 137.609 270.376 Q136.822 272.274 134.716 274.867 Q134.137 275.538 131.035 278.756 Q127.933 281.95 122.285 287.714 Z\" fill=\"#000000\" fill-rul
" 246.529,415.679 257.197,434.57 267.865,453.179 278.533,471.508 289.201,489.554 299.869,507.32 310.537,524.804 321.205,542.007 331.873,558.929 342.541,575.569 \n",
" 353.209,591.928 363.877,608.006 374.545,623.802 385.213,639.317 395.881,654.551 406.549,669.504 417.217,684.175 427.885,698.564 438.553,712.673 449.221,726.5 \n",
" 459.889,740.046 470.557,753.31 481.225,766.293 491.893,778.995 502.561,791.415 513.229,803.554 523.897,815.412 534.565,826.989 545.233,838.284 555.901,849.298 \n",
" 566.569,860.03 577.237,870.482 587.905,880.651 598.573,890.54 609.241,900.147 619.909,909.473 630.577,918.518 641.245,927.281 651.913,935.763 662.581,943.963 \n",
" 673.248,951.883 683.916,959.521 694.584,966.877 705.252,973.953 715.92,980.747 726.588,987.259 737.256,993.491 747.924,999.441 758.592,1005.11 769.26,1010.5 \n",
" 779.928,1015.6 790.596,1020.43 801.264,1024.97 811.932,1029.23 822.6,1033.21 833.268,1036.91 843.936,1040.33 854.604,1043.47 865.272,1046.32 875.94,1048.9 \n",
" 886.608,1051.19 897.276,1053.2 907.944,1054.93 918.612,1056.38 929.28,1057.55 939.948,1058.43 950.616,1059.04 961.284,1059.36 971.952,1059.4 982.62,1059.17 \n",
" 993.288,1058.65 1003.96,1057.84 1014.62,1056.76 1025.29,1055.4 1035.96,1053.75 1046.63,1051.82 1057.3,1049.61 1067.96,1047.12 1078.63,1044.35 1089.3,1041.3 \n",
" 1099.97,1037.97 1110.64,1034.35 1121.3,1030.46 1131.97,1026.28 1142.64,1021.82 1153.31,1017.08 1163.98,1012.06 1174.64,1006.75 1185.31,1001.17 1195.98,995.305 \n",
" 1206.65,989.158 1217.32,982.73 1227.98,976.02 1238.65,969.029 1249.32,961.757 1259.99,954.204 1270.66,946.369 1281.32,938.253 1291.99,929.855 1302.66,921.176 \n",
" 1313.33,912.216 1324,902.974 1334.66,893.452 1345.33,883.647 1356,873.562 1366.67,863.195 1377.34,852.547 1388,841.618 1398.67,830.407 1409.34,818.915 \n",
" 1420.01,807.141 1430.67,795.087 1441.34,782.751 1452.01,770.133 1462.68,757.234 1473.35,744.054 1484.01,730.593 1494.68,716.85 1505.35,702.826 1516.02,688.521 \n",
" 1526.69,673.934 1537.35,659.066 1548.02,643.917 1558.69,628.486 1569.36,612.774 1580.03,596.781 1590.69,580.507 1601.36,563.951 1612.03,547.113 1622.7,529.995 \n",
" 1633.37,512.595 1644.03,494.914 1654.7,476.951 1665.37,458.707 1676.04,440.182 1686.71,421.376 1697.37,402.288 1708.04,382.919 1718.71,363.268 1729.38,343.336 \n",
" 1740.05,323.123 1750.71,302.629 1761.38,281.853 1772.05,260.796 1782.72,239.457 1793.39,217.838 1804.05,195.936 1814.72,173.754 1825.39,151.29 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip762)\" style=\"stroke:#0000ff; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" stroke-dasharray=\"16, 10\" points=\"\n",
" 246.529,1078.19 257.197,1077.79 267.865,1077.25 278.533,1076.58 289.201,1075.78 299.869,1074.85 310.537,1073.79 321.205,1072.6 331.873,1071.3 342.541,1069.88 \n",
" 353.209,1068.36 363.877,1066.73 374.545,1065 385.213,1063.18 395.881,1061.28 406.549,1059.31 417.217,1057.26 427.885,1055.15 438.553,1052.98 449.221,1050.77 \n",
" 459.889,1048.52 470.557,1046.24 481.225,1043.94 491.893,1041.62 502.561,1039.3 513.229,1036.99 523.897,1034.68 534.565,1032.4 545.233,1030.14 555.901,1027.92 \n",
" 566.569,1025.75 577.237,1023.63 587.905,1021.57 598.573,1019.58 609.241,1017.67 619.909,1015.84 630.577,1014.1 641.245,1012.45 651.913,1010.91 662.581,1009.47 \n",
" 673.248,1008.15 683.916,1006.95 694.584,1005.87 705.252,1004.91 715.92,1004.09 726.588,1003.39 737.256,1002.84 747.924,1002.42 758.592,1002.14 769.26,1002 \n",
" 779.928,1002 790.596,1002.14 801.264,1002.42 811.932,1002.84 822.6,1003.39 833.268,1004.09 843.936,1004.91 854.604,1005.87 865.272,1006.95 875.94,1008.15 \n",
" 886.608,1009.47 897.276,1010.91 907.944,1012.45 918.612,1014.1 929.28,1015.84 939.948,1017.67 950.616,1019.58 961.284,1021.57 971.952,1023.63 982.62,1025.75 \n",
" 993.288,1027.92 1003.96,1030.14 1014.62,1032.4 1025.29,1034.68 1035.96,1036.99 1046.63,1039.3 1057.3,1041.62 1067.96,1043.94 1078.63,1046.24 1089.3,1048.52 \n",
" 1099.97,1050.77 1110.64,1052.98 1121.3,1055.15 1131.97,1057.26 1142.64,1059.31 1153.31,1061.28 1163.98,1063.18 1174.64,1065 1185.31,1066.73 1195.98,1068.36 \n",
" 1206.65,1069.88 1217.32,1071.3 1227.98,1072.6 1238.65,1073.79 1249.32,1074.85 1259.99,1075.78 1270.66,1076.58 1281.32,1077.25 1291.99,1077.79 1302.66,1078.19 \n",
" 1313.33,1078.44 1324,1078.56 1334.66,1078.54 1345.33,1078.38 1356,1078.07 1366.67,1077.63 1377.34,1077.05 1388,1076.34 1398.67,1075.49 1409.34,1074.51 \n",
" 1420.01,1073.41 1430.67,1072.19 1441.34,1070.85 1452.01,1069.39 1462.68,1067.83 1473.35,1066.17 1484.01,1064.42 1494.68,1062.57 1505.35,1060.64 1516.02,1058.64 \n",
" 1526.69,1056.57 1537.35,1054.45 1548.02,1052.26 1558.69,1050.04 1569.36,1047.78 1580.03,1045.49 1590.69,1043.18 1601.36,1040.86 1612.03,1038.54 1622.7,1036.23 \n",
" 1633.37,1033.93 1644.03,1031.66 1654.7,1029.41 1665.37,1027.21 1676.04,1025.05 1686.71,1022.95 1697.37,1020.91 1708.04,1018.95 1718.71,1017.06 1729.38,1015.26 \n",
" 1740.05,1013.55 1750.71,1011.94 1761.38,1010.43 1772.05,1009.03 1782.72,1007.75 1793.39,1006.58 1804.05,1005.54 1814.72,1004.63 1825.39,1003.85 \n",
" \"/>\n",
"<path clip-path=\"url(#clip760)\" d=\"\n",
"M1522.29 311.756 L1816.97 311.756 L1816.97 156.236 L1522.29 156.236 Z\n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip760)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1522.29,311.756 1816.97,311.756 1816.97,156.236 1522.29,156.236 1522.29,311.756 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip760)\" style=\"stroke:#ff0000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1540.88,208.076 1652.46,208.076 \n",
" \"/>\n",
"<path clip-path=\"url(#clip760)\" d=\"M1687.56 189.337 L1687.56 192.879 L1683.48 192.879 Q1681.19 192.879 1680.29 193.805 Q1679.41 194.731 1679.41 197.138 L1679.41 199.43 L1686.42 199.43 L1686.42 202.74 L1679.41 202.74 L1679.41 225.356 L1675.13 225.356 L1675.13 202.74 L1671.05 202.74 L1671.05 199.43 L1675.13 199.43 L1675.13 197.624 Q1675.13 193.296 1677.14 191.328 Q1679.15 189.337 1683.53 189.337 L1687.56 189.337 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M1712.67 209.708 L1712.67 225.356 L1708.41 225.356 L1708.41 209.847 Q1708.41 206.166 1706.98 204.337 Q1705.54 202.509 1702.67 202.509 Q1699.22 202.509 1697.23 204.708 Q1695.24 206.907 1695.24 210.703 L1695.24 225.356 L1690.96 225.356 L1690.96 199.43 L1695.24 199.43 L1695.24 203.458 Q1696.77 201.12 1698.83 199.962 Q1700.91 198.805 1703.62 198.805 Q1708.09 198.805 1710.38 201.583 Q1712.67 204.337 1712.67 209.708 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M1722.58 221.421 L1730.22 221.421 L1730.22 195.055 L1721.91 196.722 L1721.91 192.462 L1730.17 190.796 L1734.85 190.796 L1734.85 221.421 L1742.49 221.421 L1742.49 225.356 L1722.58 225.356 L1722.58 221.421 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M1761.56 189.384 Q1758.46 194.708 1756.95 199.916 Q1755.45 205.124 1755.45 210.472 Q1755.45 215.819 1756.95 221.073 Q1758.48 226.305 1761.56 231.606 L1757.86 231.606 Q1754.39 226.166 1752.65 220.911 Q1750.94 215.657 1750.94 210.472 Q1750.94 205.31 1752.65 200.078 Q1754.36 194.847 1757.86 189.384 L1761.56 189.384 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M1769.15 189.384 L1772.86 189.384 Q1776.33 194.847 1778.04 200.078 Q1779.78 205.31 1779.78 210.472 Q1779.78 215.657 1778.04 220.911 Q1776.33 226.166 1772.86 231.606 L1769.15 231.606 Q1772.23 226.305 1773.74 221.073 Q1775.26 215.819 1775.26 210.472 Q1775.26 205.124 1773.74 199.916 Q1772.23 194.708 1769.15 189.384 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><polyline clip-path=\"url(#clip760)\" style=\"stroke:#0000ff; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" stroke-dasharray=\"16, 10\" points=\"\n",
" 1540.88,259.916 1652.46,259.916 \n",
" \"/>\n",
"<path clip-path=\"url(#clip760)\" d=\"M1691.56 252.265 L1691.56 256.247 Q1689.76 255.251 1687.93 254.765 Q1686.12 254.256 1684.27 254.256 Q1680.13 254.256 1677.83 256.895 Q1675.54 259.511 1675.54 264.256 Q1675.54 269.001 1677.83 271.64 Q1680.13 274.256 1684.27 274.256 Q1686.12 274.256 1687.93 273.77 Q1689.76 273.261 1691.56 272.265 L1691.56 276.2 Q1689.78 277.034 1687.86 277.45 Q1685.96 277.867 1683.81 277.867 Q1677.95 277.867 1674.5 274.186 Q1671.05 270.506 1671.05 264.256 Q1671.05 257.913 1674.52 254.279 Q1678.02 250.645 1684.08 250.645 Q1686.05 250.645 1687.93 251.062 Q1689.8 251.455 1691.56 252.265 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M1709.02 254.256 Q1705.59 254.256 1703.6 256.941 Q1701.61 259.603 1701.61 264.256 Q1701.61 268.909 1703.58 271.594 Q1705.57 274.256 1709.02 274.256 Q1712.42 274.256 1714.41 271.571 Q1716.4 268.886 1716.4 264.256 Q1716.4 259.65 1714.41 256.964 Q1712.42 254.256 1709.02 254.256 M1709.02 250.645 Q1714.57 250.645 1717.74 254.256 Q1720.91 257.867 1720.91 264.256 Q1720.91 270.622 1717.74 274.256 Q1714.57 277.867 1709.02 277.867 Q1703.44 277.867 1700.27 274.256 Q1697.12 270.622 1697.12 264.256 Q1697.12 257.867 1700.27 254.256 Q1703.44 250.645 1709.02 250.645 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip760)\" d=\"M1744.5 252.034 L1744.5 256.062 Q1742.7 255.136 1740.75 254.673 Q1738.81 254.21 1736.72 254.21 Q1733.55 254.21 1731.95 255.182 Q1730.38 256.154 1730.38 258.099 Q1730.38 259.58 1731.51 260.437 Q1732.65 261.27 1736.08 262.034 L1737.53 262.358 Q1742.07 263.33 1743.97 265.112 Q1745.89 266.872 1745.89 270.043 Q1745.89 273.654 1743.02 275.761 Q1740.17 277.867 1735.17 277.867 Q1733.09 277.867 1730.82 277.45 Q1728.58 277.057 1726.08 276.247 L1726.08 271.849 Q1728.44 273.075 1730.73 273.7 Q1733.02 274.302 1735.26 274.302 Q1738.27 274.302 1739.89 273.284 Q1741.51 272.242 1741.51 270.367 Q1741.51 268.631 1740.33 267.705 Q1739.18 266.779 1735.22 265.923 L1733.74 265.575 Q1729.78 264.742 1728.02 263.029 Q1726.26 261.293 1726.26 258.284 Q1726.26 254.626 1728.85 252.636 Q1731.45 250.645 1736.21 250.645 Q1738.58 250.645 1740.66 250.992 Q1742.74 251.339 1744.5 252.034 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /></svg>\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"x = -3:6/99:6 \n",
"\n",
"p1 = plot( [x x],[fn1.(x) cos.(x)],\n",
" linecolor = [:red :blue],\n",
" linestyle = [:solid :dash],\n",
" linewidth = [2 1],\n",
" label = [\"fn1()\" \"cos\"],\n",
" title = \"My Results\",\n",
" xlabel = \"x\",\n",
" ylabel = \"my output value\" )\n",
"display(p1) #not needed in notebook, but useful in script"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Task\n",
"\n",
"Consider different interest rates in the interval (-0.05,0.1). Plot the prices of 3-month and 10-year bonds as functions of the interest rate."
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"480\" height=\"320\" viewBox=\"0 0 1920 1280\">\n",
"<defs>\n",
" <clipPath id=\"clip800\">\n",
" <rect x=\"0\" y=\"0\" width=\"1920\" height=\"1280\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip800)\" d=\"\n",
"M0 1280 L1920 1280 L1920 0 L0 0 Z\n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<defs>\n",
" <clipPath id=\"clip801\">\n",
" <rect x=\"384\" y=\"0\" width=\"1345\" height=\"1280\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip800)\" d=\"\n",
"M244.742 1106.38 L1872.76 1106.38 L1872.76 47.2441 L244.742 47.2441 Z\n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<defs>\n",
" <clipPath id=\"clip802\">\n",
" <rect x=\"244\" y=\"47\" width=\"1629\" height=\"1060\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<polyline clip-path=\"url(#clip802)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 495.6,1106.38 495.6,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip802)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 802.772,1106.38 802.772,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip802)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1109.94,1106.38 1109.94,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip802)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1417.12,1106.38 1417.12,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip802)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1724.29,1106.38 1724.29,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip800)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 244.742,1106.38 1872.76,1106.38 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip800)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 495.6,1106.38 495.6,1087.48 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip800)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 802.772,1106.38 802.772,1087.48 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip800)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1109.94,1106.38 1109.94,1087.48 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip800)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1417.12,1106.38 1417.12,1087.48 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip800)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1724.29,1106.38 1724.29,1087.48 \n",
" \"/>\n",
"<path clip-path=\"url(#clip800)\" d=\"M427.371 1146.38 L457.046 1146.38 L457.046 1150.32 L427.371 1150.32 L427.371 1146.38 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800)\" d=\"M477.139 1131.73 Q473.528 1131.73 471.699 1135.3 Q469.894 1138.84 469.894 1145.97 Q469.894 1153.07 471.699 1156.64 Q473.528 1160.18 477.139 1160.18 Q480.773 1160.18 482.579 1156.64 Q484.407 1153.07 484.407 1145.97 Q484.407 1138.84 482.579 1135.3 Q480.773 1131.73 477.139 1131.73 M477.139 1128.03 Q482.949 1128.03 486.005 1132.63 Q489.083 1137.22 489.083 1145.97 Q489.083 1154.69 486.005 1159.3 Q482.949 1163.88 477.139 1163.88 Q471.329 1163.88 468.25 1159.3 Q465.195 1154.69 465.195 1145.97 Q465.195 1137.22 468.25 1132.63 Q471.329 1128.03 477.139 1128.03 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800)\" d=\"M497.301 1157.33 L502.185 1157.33 L502.185 1163.21 L497.301 1163.21 L497.301 1157.33 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800)\" d=\"M522.37 1131.73 Q518.759 1131.73 516.93 1135.3 Q515.125 1138.84 515.125 1145.97 Q515.125 1153.07 516.93 1156.64 Q518.759 1160.18 522.37 1160.18 Q526.004 1160.18 527.81 1156.64 Q529.639 1153.07 529.639 1145.97 Q529.639 1138.84 527.81 1135.3 Q526.004 1131.73 522.37 1131.73 M522.37 1128.03 Q528.18 1128.03 531.236 1132.63 Q534.315 1137.22 534.315 1145.97 Q534.315 1154.69 531.236 1159.3 Q528.18 1163.88 522.37 1163.88 Q516.56 1163.88 513.481 1159.3 Q510.426 1154.69 510.426 1145.97 Q510.426 1137.22 513.481 1132.63 Q516.56 1128.03 522.37 1128.03 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800)\" d=\"M556.699 1144.58 Q560.055 1145.3 561.93 1147.56 Q563.828 1149.83 563.828 1153.17 Q563.828 1158.28 560.31 1161.08 Q556.791 1163.88 550.31 1163.88 Q548.134 1163.88 545.819 1163.44 Q543.528 1163.03 541.074 1162.17 L541.074 1157.66 Q543.018 1158.79 545.333 1159.37 Q547.648 1159.95 550.171 1159.95 Q554.569 1159.95 556.861 1158.21 Q559.176 1156.48 559.176 1153.17 Q559.176 1150.11 557.023 1148.4 Q554.893 1146.66 551.074 1146.66 L547.046 1146.66 L547.046 1142.82 L551.259 1142.82 Q554.708 1142.82 556.537 1141.45 Q558.365 1140.06 558.365 1137.47 Q558.365 1134.81 556.467 1133.4 Q554.592 1131.96 551.074 1131.96 Q549.152 1131.96 546.953 1132.38 Q544.754 1132.8 542.115 1133.67 L542.115 1129.51 Q544.777 1128.77 547.092 1128.4 Q549.43 1128.03 551.49 1128.03 Q556.814 1128.03 559.916 1130.46 Q563.018 1132.86 563.018 1136.99 Q563.018 1139.86 561.375 1141.85 Q559.731 1143.81 556.699 1144.58 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800)\" d=\"M765.075 1131.73 Q761.464 1131.73 759.636 1135.3 Q757.83 1138.84 757.83 1145.97 Q757.83 1153.07 759.636 1156.64 Q761.464 1160.18 765.075 1160.18 Q768.71 1160.18 770.515 1156.64 Q772.344 1153.07 772.344 1145.97 Q772.344 1138.84 770.515 1135.3 Q768.71 1131.73 765.075 1131.73 M765.075 1128.03 Q770.886 1128.03 773.941 1132.63 Q777.02 1137.22 777.02 1145.97 Q777.02 1154.69 773.941 1159.3 Q770.886 1163.88 765.075 1163.88 Q759.265 1163.88 756.187 1159.3 Q753.131 1154.69 753.131 1145.97 Q753.131 1137.22 756.187 1132.63 Q759.265 1128.03 765.075 1128.03 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800)\" d=\"M785.237 1157.33 L790.122 1157.33 L790.122 1163.21 L785.237 1163.21 L785.237 1157.33 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800)\" d=\"M810.307 1131.73 Q806.696 1131.73 804.867 1135.3 Q803.061 1138.84 803.061 1145.97 Q803.061 1153.07 804.867 1156.64 Q806.696 1160.18 810.307 1160.18 Q813.941 1160.18 815.746 1156.64 Q817.575 1153.07 817.575 1145.97 Q817.575 1138.84 815.746 1135.3 Q813.941 1131.73 810.307 1131.73 M810.307 1128.03 Q816.117 1128.03 819.172 1132.63 Q822.251 1137.22 822.251 1145.97 Q822.251 1154.69 819.172 1159.3 Q816.117 1163.88 810.307 1163.88 Q804.496 1163.88 801.418 1159.3 Q798.362 1154.69 798.362 1145.97 Q798.362 1137.22 801.418 1132.63 Q804.496 1128.03 810.
" 244.742,973.337 1872.76,973.337 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip802)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 244.742,778.312 1872.76,778.312 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip802)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 244.742,583.287 1872.76,583.287 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip802)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 244.742,388.262 1872.76,388.262 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip802)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 244.742,193.237 1872.76,193.237 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip800)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 244.742,1106.38 244.742,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip800)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 244.742,973.337 263.64,973.337 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip800)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 244.742,778.312 263.64,778.312 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip800)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 244.742,583.287 263.64,583.287 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip800)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 244.742,388.262 263.64,388.262 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip800)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 244.742,193.237 263.64,193.237 \n",
" \"/>\n",
"<path clip-path=\"url(#clip800)\" d=\"M128.605 959.136 Q124.993 959.136 123.165 962.701 Q121.359 966.242 121.359 973.372 Q121.359 980.478 123.165 984.043 Q124.993 987.585 128.605 987.585 Q132.239 987.585 134.044 984.043 Q135.873 980.478 135.873 973.372 Q135.873 966.242 134.044 962.701 Q132.239 959.136 128.605 959.136 M128.605 955.432 Q134.415 955.432 137.47 960.039 Q140.549 964.622 140.549 973.372 Q140.549 982.099 137.47 986.705 Q134.415 991.288 128.605 991.288 Q122.794 991.288 119.716 986.705 Q116.66 982.099 116.66 973.372 Q116.66 964.622 119.716 960.039 Q122.794 955.432 128.605 955.432 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800)\" d=\"M148.766 984.737 L153.651 984.737 L153.651 990.617 L148.766 990.617 L148.766 984.737 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800)\" d=\"M163.882 956.057 L182.239 956.057 L182.239 959.992 L168.165 959.992 L168.165 968.464 Q169.183 968.117 170.202 967.955 Q171.22 967.77 172.239 967.77 Q178.026 967.77 181.405 970.941 Q184.785 974.113 184.785 979.529 Q184.785 985.108 181.313 988.21 Q177.84 991.288 171.521 991.288 Q169.345 991.288 167.077 990.918 Q164.831 990.548 162.424 989.807 L162.424 985.108 Q164.507 986.242 166.729 986.798 Q168.952 987.353 171.428 987.353 Q175.433 987.353 177.771 985.247 Q180.109 983.14 180.109 979.529 Q180.109 975.918 177.771 973.812 Q175.433 971.705 171.428 971.705 Q169.553 971.705 167.678 972.122 Q165.827 972.538 163.882 973.418 L163.882 956.057 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800)\" d=\"M203.998 959.136 Q200.387 959.136 198.558 962.701 Q196.752 966.242 196.752 973.372 Q196.752 980.478 198.558 984.043 Q200.387 987.585 203.998 987.585 Q207.632 987.585 209.437 984.043 Q211.266 980.478 211.266 973.372 Q211.266 966.242 209.437 962.701 Q207.632 959.136 203.998 959.136 M203.998 955.432 Q209.808 955.432 212.863 960.039 Q215.942 964.622 215.942 973.372 Q215.942 982.099 212.863 986.705 Q209.808 991.288 203.998 991.288 Q198.187 991.288 195.109 986.705 Q192.053 982.099 192.053 973.372 Q192.053 964.622 195.109 960.039 Q198.187 955.432 203.998 955.432 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800)\" d=\"M129.6 764.111 Q125.989 764.111 124.16 767.676 Q122.355 771.217 122.355 778.347 Q122.355 785.453 124.16 789.018 Q125.989 792.56 129.6 792.56 Q133.234 792.56 135.04 789.018 Q136.868 785.453 136.868 778.347 Q136.868 771.217 135.04 767.676 Q133.234 764.111 129.6 764.111 M129.6 760.407 Q135.41 760.407 138.466 765.014 Q141.544 769.597 141.544 778.347 Q141.544 787.074 138.466 791.68 Q135.41 796.263 129.6 796.263 Q123.79 796.263 120.711 791.68 Q117.656 787.074 117.656 778.347 Q117.656 769.597 120.711 765.014 Q123.79 760.407 129.6 760.407 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800)\" d=\"M149.762 789.712 L154.646 789.712 L154.646 795.592 L149.762 795.592 L149.762 789.712 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800)\" d=\"M163.651 761.032 L185.873 761.032 L185.873 763.023 L173.327 795.592 L168.442 795.592 L180.248 764.967 L163.651 764.967 L163.651 761.032 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800)\" d=\"M195.039 761.032 L213.396 761.032 L213.396 764.967 L199.322 764.967 L199.322 773.439 Q200.34 773.092 201.359 772.93 Q202.377 772.745 203.396 772.745 Q209.183 772.745 212.562 775.916 Q215.942 779.088 215.942 784.504 Q215.942 790.083 212.47 793.185 Q208.998 796.263 202.678 796.263 Q200.502 796.263 198.234 795.893 Q195.988 795.523 193.581 794.782 L193.581 790.083 Q195.664 791.217 197.887 791.773 Q200.109 792.328 202.586 792.328 Q206.59 792.328 208.928 790.222 Q211.266 788.115 211.266 784.504 Q211.266 780.893 208.928 778.787 Q206.59 776.68 202.586 776.68 Q200.711 776.68 198.836 777.097 Q196.984 777.513 195.039 778.393 L195.039 761.032 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800
" 290.818,573.475 301.057,573.672 311.296,573.869 321.535,574.067 331.774,574.264 342.013,574.461 352.252,574.659 362.491,574.856 372.731,575.053 382.97,575.25 \n",
" 393.209,575.447 403.448,575.644 413.687,575.841 423.926,576.038 434.165,576.234 444.404,576.431 454.643,576.628 464.882,576.825 475.121,577.021 485.36,577.218 \n",
" 495.6,577.414 505.839,577.611 516.078,577.807 526.317,578.004 536.556,578.2 546.795,578.396 557.034,578.592 567.273,578.789 577.512,578.985 587.751,579.181 \n",
" 597.99,579.377 608.229,579.573 618.468,579.769 628.708,579.965 638.947,580.16 649.186,580.356 659.425,580.552 669.664,580.748 679.903,580.943 690.142,581.139 \n",
" 700.381,581.334 710.62,581.53 720.859,581.725 731.098,581.921 741.337,582.116 751.577,582.311 761.816,582.507 772.055,582.702 782.294,582.897 792.533,583.092 \n",
" 802.772,583.287 813.011,583.482 823.25,583.677 833.489,583.872 843.728,584.067 853.967,584.262 864.206,584.456 874.446,584.651 884.685,584.846 894.924,585.04 \n",
" 905.163,585.235 915.402,585.429 925.641,585.624 935.88,585.818 946.119,586.013 956.358,586.207 966.597,586.401 976.836,586.595 987.075,586.79 997.314,586.984 \n",
" 1007.55,587.178 1017.79,587.372 1028.03,587.566 1038.27,587.76 1048.51,587.954 1058.75,588.147 1068.99,588.341 1079.23,588.535 1089.47,588.729 1099.71,588.922 \n",
" 1109.94,589.116 1120.18,589.309 1130.42,589.503 1140.66,589.696 1150.9,589.89 1161.14,590.083 1171.38,590.276 1181.62,590.47 1191.86,590.663 1202.1,590.856 \n",
" 1212.34,591.049 1222.57,591.242 1232.81,591.435 1243.05,591.628 1253.29,591.821 1263.53,592.014 1273.77,592.207 1284.01,592.4 1294.25,592.592 1304.49,592.785 \n",
" 1314.73,592.978 1324.97,593.17 1335.2,593.363 1345.44,593.555 1355.68,593.748 1365.92,593.94 1376.16,594.132 1386.4,594.325 1396.64,594.517 1406.88,594.709 \n",
" 1417.12,594.901 1427.36,595.093 1437.59,595.285 1447.83,595.477 1458.07,595.669 1468.31,595.861 1478.55,596.053 1488.79,596.245 1499.03,596.437 1509.27,596.628 \n",
" 1519.51,596.82 1529.75,597.012 1539.99,597.203 1550.22,597.395 1560.46,597.586 1570.7,597.778 1580.94,597.969 1591.18,598.16 1601.42,598.352 1611.66,598.543 \n",
" 1621.9,598.734 1632.14,598.925 1642.38,599.116 1652.62,599.307 1662.85,599.498 1673.09,599.689 1683.33,599.88 1693.57,600.071 1703.81,600.262 1714.05,600.453 \n",
" 1724.29,600.643 1734.53,600.834 1744.77,601.025 1755.01,601.215 1765.25,601.406 1775.48,601.596 1785.72,601.787 1795.96,601.977 1806.2,602.167 1816.44,602.358 \n",
" 1826.68,602.548 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip802)\" style=\"stroke:#e26f46; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 290.818,77.2196 301.057,90.0172 311.296,102.687 321.535,115.232 331.774,127.651 342.013,139.947 352.252,152.12 362.491,164.172 372.731,176.105 382.97,187.919 \n",
" 393.209,199.615 403.448,211.194 413.687,222.659 423.926,234.009 434.165,245.247 444.404,256.372 454.643,267.387 464.882,278.293 475.121,289.09 485.36,299.779 \n",
" 495.6,310.362 505.839,320.84 516.078,331.214 526.317,341.484 536.556,351.652 546.795,361.719 557.034,371.686 567.273,381.553 577.512,391.323 587.751,400.995 \n",
" 597.99,410.571 608.229,420.051 618.468,429.438 628.708,438.731 638.947,447.931 649.186,457.04 659.425,466.058 669.664,474.987 679.903,483.827 690.142,492.579 \n",
" 700.381,501.243 710.62,509.822 720.859,518.315 731.098,526.723 741.337,535.048 751.577,543.29 761.816,551.451 772.055,559.529 782.294,567.528 792.533,575.447 \n",
" 802.772,583.287 813.011,591.049 823.25,598.734 833.489,606.343 843.728,613.875 853.967,621.333 864.206,628.717 874.446,636.027 884.685,643.264 894.924,650.429 \n",
" 905.163,657.523 915.402,664.547 925.641,671.5 935.88,678.385 946.119,685.201 956.358,691.949 966.597,698.63 976.836,705.244 987.075,711.793 997.314,718.276 \n",
" 1007.55,724.695 1017.79,731.05 1028.03,737.342 1038.27,743.571 1048.51,749.739 1058.75,755.845 1068.99,761.89 1079.23,767.875 1089.47,773.8 1099.71,779.667 \n",
" 1109.94,785.475 1120.18,791.225 1130.42,796.918 1140.66,802.555 1150.9,808.135 1161.14,813.66 1171.38,819.13 1181.62,824.545 1191.86,829.907 1202.1,835.215 \n",
" 1212.34,840.47 1222.57,845.674 1232.81,850.825 1243.05,855.925 1253.29,860.974 1263.53,865.973 1273.77,870.923 1284.01,875.823 1294.25,880.674 1304.49,885.477 \n",
" 1314.73,890.232 1324.97,894.94 1335.2,899.602 1345.44,904.216 1355.68,908.785 1365.92,913.309 1376.16,917.787 1386.4,922.221 1396.64,926.61 1406.88,930.956 \n",
" 1417.12,935.259 1427.36,939.519 1437.59,943.737 1447.83,947.912 1458.07,952.046 1468.31,956.139 1478.55,960.191 1488.79,964.203 1499.03,968.175 1509.27,972.108 \n",
" 1519.51,976.001 1529.75,979.855 1539.99,983.672 1550.22,987.45 1560.46,991.19 1570.7,994.894 1580.94,998.56 1591.18,1002.19 1601.42,1005.78 1611.66,1009.34 \n",
" 1621.9,1012.87 1632.14,1016.35 1642.38,1019.81 1652.62,1023.23 1662.85,1026.61 1673.09,1029.96 1683.33,1033.28 1693.57,1036.56 1703.81,1039.81 1714.05,1043.03 \n",
" 1724.29,1046.22 1734.53,1049.38 1744.77,1052.5 1755.01,1055.6 1765.25,1058.66 1775.48,1061.69 1785.72,1064.69 1795.96,1067.66 1806.2,1070.61 1816.44,1073.52 \n",
" 1826.68,1076.4 \n",
" \"/>\n",
"<path clip-path=\"url(#clip800)\" d=\"\n",
"M1555.84 238.069 L1818.49 238.069 L1818.49 82.5486 L1555.84 82.5486 Z\n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip800)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1555.84,238.069 1818.49,238.069 1818.49,82.5486 1555.84,82.5486 1555.84,238.069 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip800)\" style=\"stroke:#009af9; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1573.93,134.389 1682.46,134.389 \n",
" \"/>\n",
"<path clip-path=\"url(#clip800)\" d=\"M1716.18 133.034 Q1719.53 133.752 1721.41 136.021 Q1723.31 138.289 1723.31 141.622 Q1723.31 146.738 1719.79 149.539 Q1716.27 152.34 1709.79 152.34 Q1707.61 152.34 1705.3 151.9 Q1703.01 151.483 1700.55 150.627 L1700.55 146.113 Q1702.5 147.247 1704.81 147.826 Q1707.13 148.405 1709.65 148.405 Q1714.05 148.405 1716.34 146.669 Q1718.65 144.933 1718.65 141.622 Q1718.65 138.567 1716.5 136.854 Q1714.37 135.118 1710.55 135.118 L1706.52 135.118 L1706.52 131.275 L1710.74 131.275 Q1714.19 131.275 1716.01 129.909 Q1717.84 128.521 1717.84 125.928 Q1717.84 123.266 1715.95 121.854 Q1714.07 120.419 1710.55 120.419 Q1708.63 120.419 1706.43 120.835 Q1704.23 121.252 1701.59 122.132 L1701.59 117.965 Q1704.26 117.224 1706.57 116.854 Q1708.91 116.484 1710.97 116.484 Q1716.29 116.484 1719.39 118.914 Q1722.5 121.322 1722.5 125.442 Q1722.5 128.312 1720.85 130.303 Q1719.21 132.271 1716.18 133.034 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800)\" d=\"M1751.76 130.72 Q1753.35 127.849 1755.57 126.484 Q1757.8 125.118 1760.81 125.118 Q1764.86 125.118 1767.06 127.965 Q1769.26 130.789 1769.26 136.021 L1769.26 151.669 L1764.97 151.669 L1764.97 136.159 Q1764.97 132.433 1763.65 130.627 Q1762.33 128.822 1759.63 128.822 Q1756.32 128.822 1754.39 131.021 Q1752.47 133.22 1752.47 137.016 L1752.47 151.669 L1748.19 151.669 L1748.19 136.159 Q1748.19 132.409 1746.87 130.627 Q1745.55 128.822 1742.8 128.822 Q1739.53 128.822 1737.61 131.044 Q1735.69 133.243 1735.69 137.016 L1735.69 151.669 L1731.41 151.669 L1731.41 125.743 L1735.69 125.743 L1735.69 129.771 Q1737.15 127.386 1739.19 126.252 Q1741.22 125.118 1744.02 125.118 Q1746.85 125.118 1748.82 126.553 Q1750.81 127.988 1751.76 130.72 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><polyline clip-path=\"url(#clip800)\" style=\"stroke:#e26f46; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1573.93,186.229 1682.46,186.229 \n",
" \"/>\n",
"<path clip-path=\"url(#clip800)\" d=\"M1701.22 199.573 L1708.86 199.573 L1708.86 173.208 L1700.55 174.875 L1700.55 170.615 L1708.82 168.949 L1713.49 168.949 L1713.49 199.573 L1721.13 199.573 L1721.13 203.509 L1701.22 203.509 L1701.22 199.573 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800)\" d=\"M1740.57 172.027 Q1736.96 172.027 1735.14 175.592 Q1733.33 179.134 1733.33 186.263 Q1733.33 193.37 1735.14 196.935 Q1736.96 200.476 1740.57 200.476 Q1744.21 200.476 1746.01 196.935 Q1747.84 193.37 1747.84 186.263 Q1747.84 179.134 1746.01 175.592 Q1744.21 172.027 1740.57 172.027 M1740.57 168.324 Q1746.38 168.324 1749.44 172.93 Q1752.52 177.513 1752.52 186.263 Q1752.52 194.99 1749.44 199.597 Q1746.38 204.18 1740.57 204.18 Q1734.76 204.18 1731.69 199.597 Q1728.63 194.99 1728.63 186.263 Q1728.63 177.513 1731.69 172.93 Q1734.76 168.324 1740.57 168.324 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip800)\" d=\"M1770.92 205.916 Q1769.12 210.546 1767.4 211.958 Q1765.69 213.37 1762.82 213.37 L1759.42 213.37 L1759.42 209.805 L1761.92 209.805 Q1763.68 209.805 1764.65 208.972 Q1765.62 208.138 1766.8 205.036 L1767.57 203.092 L1757.08 177.583 L1761.59 177.583 L1769.7 197.861 L1777.8 177.583 L1782.31 177.583 L1770.92 205.916 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /></svg>\n"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y = -0.05:0.001:0.10\n",
"\n",
"B3m = BondPrice.(y,3/12)\n",
"B10y = BondPrice.(y,10)\n",
"\n",
"plot([y y],[B3m B10y],label = [\"3m\" \"10y\"],xlabel=\"interest rate\",ylabel=\"Bond price\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Types: Integers, Floats, Bools and Others\n",
"\n",
"Julia has many different types of variables: signed integers (like 2 or -5), floating point numbers (2.0 and -5.1), bools (false/true), bitarrays (similar to bools, but with more efficient use of memory), strings (\"hello\"), Dates (2017-04-23) and many more types."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Integers and Floats"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Finding the type of a, b, A and B:\n",
"Int64 Float64 Vector{Int64} Vector{Float64}\n"
]
}
],
"source": [
"a = 2 #integer, Int (Int64 on most machines)\n",
"b = 2.0 #floating point, (Float64 on most machines)\n",
"A = [1,2]\n",
"B = [1.0,2.0]\n",
"\n",
"println(\"Finding the type of a, b, A and B:\")\n",
"println(typeof(a),\" \",typeof(b),\" \",typeof(A),\" \",typeof(B))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Bools and BitArrays\n",
"\n",
"Bools are \"true\" or \"false\". BitArrays are (more memory efficient) versions of this."
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Finding the type of c and C:\n",
"Bool BitVector\n"
]
}
],
"source": [
"c = 2 > 1.1\n",
"C = A .> 1.5 #A is an array, so C is too\n",
"\n",
"println(\"Finding the type of c and C:\")\n",
"println(typeof(c),\" \",typeof(C))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Calculations with Mixed Types\n",
"\n",
"A calculation like \"integer\" + \"float\" works and the type of the result will be a float (the more flexible type). Similarly, \"bool\" + \"integer\" will give an integer. These promotion rules make it easy to have mixed types in calculations, and also provide a simple way of converting a variable from one type to another. (There are also an explicit convert() function that might be quicker.)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3.0\n",
"3\n"
]
}
],
"source": [
"println(1+2.0) #integer + Float\n",
"println((1>0) + 2) #bool + integer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"@webio": {
"lastCommId": null,
"lastKernelId": null
},
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Julia 1.6.3",
"language": "julia",
"name": "julia-1.6"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}