HSG-MCS-HS21_Julia/JuliaTutorial-master/Tutorial_05_Finance.ipynb

1643 lines
343 KiB
Plaintext
Raw Normal View History

2021-11-15 20:14:51 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# Some Typical Financial Calculations\n",
"\n",
"This notebook (a) estimates CAPM equations and autocorrelations; (b) implements a simple trading strategy; (c) calculates Value at Risk using a simple model for time-varying volatility; (d) calculates the Black-Scholes option price and implied volatility; (e) calculates and draws the mean-variance frontier (w/w.o short selling restrictions)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Load Packages and Extra Functions\n",
"\n",
"The [Roots](https://github.com/JuliaMath/Roots.jl) package solves non-linear equations and the [StatsBase](https://github.com/JuliaStats/StatsBase.jl) package has methods for estimating autocorrelations etc."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"printyellow (generic function with 1 method)"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"using Printf, Dates, DelimitedFiles, LinearAlgebra, Roots, Distributions, StatsBase\n",
"\n",
"include(\"jlFiles/printmat.jl\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"using Plots\n",
"\n",
"#pyplot(size=(600,400)) #use pyplot or gr\n",
"gr(size=(480,320))\n",
"default(fmt = :svg)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Load Data"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1979-01-01 10.190 4.180\n",
"1979-02-01 -2.820 -3.410\n",
"1979-03-01 10.900 5.750\n",
"1979-04-01 2.470 0.050\n",
"\n"
]
}
],
"source": [
"x = readdlm(\"Data/MyData.csv\",',',skipstart=1) #monthly return data\n",
"ym = round.(Int,x[:,1]) #yearmonth, like 200712\n",
"Rme = x[:,2] #market excess return\n",
"Rf = x[:,3] #interest rate\n",
"R = x[:,4] #return small growth stocks\n",
"Re = R - Rf #excess returns\n",
"T = size(Rme,1)\n",
"\n",
"dN = Date.(string.(ym),\"yyyymm\") #convert to string and then Julia Date\n",
"printmat([dN[1:4] Re[1:4] Rme[1:4]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# CAPM\n",
"\n",
"The CAPM regression is\n",
"\n",
"$R_{it}^{e} =\\alpha_{i}+\\beta_{i}R_{mt}^{e}+\\varepsilon_{it}$,\n",
"\n",
"where $R_{it}^{e}$ is the excess return of asset $i$ and $R_{mt}^{e}$ is the market excess return. Theory says that $\\alpha=0$, which is easily tested."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" coeff std t-stat\n",
"α -0.504 0.304 -1.656\n",
"β 1.341 0.066 20.427\n",
"\n",
" R2: 0.519\n",
"no. of observations: 388 \n"
]
}
],
"source": [
"x = [ones(T) Rme] #regressors\n",
"y = copy(Re) #to get standard OLS notation\n",
"b = x\\y #OLS\n",
"u = y - x*b #residuals\n",
"covb = inv(x'x)*var(u) #cov(b), see any textbook\n",
"stdb = sqrt.(diag(covb)) #std(b)\n",
"R2 = 1 - var(u)/var(y)\n",
"\n",
"printmat([b stdb b./stdb],colNames=[\"coeff\",\"std\",\"t-stat\"],rowNames=[\"α\",\"β\"])\n",
"printlnPs(\"R2: \",R2)\n",
"printlnPs(\"no. of observations: \",T)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Return Autocorrelation\n",
"\n",
"That is, the correlation of $R_{t}^{e}$ and $R_{t-s}^{e}$. \n",
"\n",
"It can be shown that the t-stat of an autocorrelation is $\\sqrt{T}$ times the autocorrelation."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Autocorrelations (different lags) of the excess returns in Re\n",
"lag autocorr t-stat\n",
"1 0.216 4.253\n",
"2 0.002 0.046\n",
"3 -0.018 -0.359\n",
"4 -0.065 -1.289\n",
"5 -0.027 -0.536\n",
"\n"
]
}
],
"source": [
"plags = 1:5\n",
"xCorr = autocor(Re,plags) #using the StatsBase package\n",
"\n",
"println(\"Autocorrelations (different lags) of the excess returns in Re\")\n",
"printmat([xCorr sqrt(T)*xCorr],colNames=[\"autocorr\",\"t-stat\"],rowNames=string.(plags),cell00=\"lag\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# A Trading Strategy\n",
"\n",
"The next cell implements a very simple momentum trading strategy. \n",
"\n",
"1. If $R_{t-1}^{e}\\ge0$, then we hold the market index and shorten the riskfree from $t-1$ to $t$. This means that we will earn $R_{t}^{e}$.\n",
"\n",
"2. Instead, if $R_{t-1}^{e}<0$, then we do the opposite. This means that we will earn $-R_{t}^{e}$. \n",
"\n",
"This simple strategy could be coded without using a loop, but \"vectorization\" does not speed up much. "
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The annualized mean excess return of the strategy and a passive portfolio are: 26.733 3.329\n",
"The annualized Sharpe ratios are: 0.932 0.112\n"
]
}
],
"source": [
"(w,Rp) = (fill(NaN,T),fill(NaN,T))\n",
"for t = 2:T\n",
" w[t] = (Re[t-1] < 0)*(-1) + (Re[t-1] >= 0)*1 #w is -1 or 1\n",
" Rp[t] = w[t]*Re[t] \n",
"end\n",
"\n",
"μ = [mean(Rp[2:end]) mean(Re[2:end])]\n",
"σ = [std(Rp[2:end]) std(Re[2:end])]\n",
"\n",
"printlnPs(\"The annualized mean excess return of the strategy and a passive portfolio are: \",μ*12)\n",
"printlnPs(\"The annualized Sharpe ratios are: \",sqrt(12)*μ./σ)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Value at Risk\n",
"\n",
"The next cell constructs an simple estimate of $\\sigma_t^2$ as a backward looking moving average (the RiskMetrics approach):\n",
"\n",
"$\\sigma_t^2 = \\lambda \\sigma_{t-1}^2 + (1-\\lambda) (R_{t-1} -\\mu)^2$,\n",
"where $\\mu$ is the average return (for all data).\n",
"\n",
"Then, we calculate the 95% VaR by assuming a $N(\\mu,\\sigma_t^2)$ distribution:\n",
"\n",
"$\\textrm{VaR}_{t} = - (\\mu-1.64\\sigma_t)$.\n",
"\n",
"If the model is correct, then $-R_t > \\text{VaR}_{t}$ should only happen 5% of the times."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"μ = mean(Rme)\n",
"\n",
"λ = 0.95 #weight on old volatility\n",
"σ² = fill(var(Rme),T) #RiskMetrics approach to estimate variance\n",
"for t = 2:T\n",
" σ²[t] = λ*σ²[t-1] + (1-λ)*(Rme[t-1]-μ)^2\n",
"end\n",
"\n",
"VaR95 = -(μ .- 1.64*sqrt.(σ²)); #VaR at 95% level"
]
},
{
"cell_type": "code",
"execution_count": 8,
"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=\"clip050\">\n",
" <rect x=\"0\" y=\"0\" width=\"1920\" height=\"1280\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip050)\" 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=\"clip051\">\n",
" <rect x=\"384\" y=\"0\" width=\"1345\" height=\"1280\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip050)\" d=\"\n",
"M242.659 1169.65 L1872.76 1169.65 L1872.76 123.472 L242.659 123.472 Z\n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<defs>\n",
" <clipPath id=\"clip052\">\n",
" <rect x=\"242\" y=\"123\" width=\"1631\" height=\"1047\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<polyline clip-path=\"url(#clip052)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 336.451,1169.65 336.451,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip052)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 813.415,1169.65 813.415,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip052)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1290.25,1169.65 1290.25,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip052)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1767.21,1169.65 1767.21,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip050)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 242.659,1169.65 1872.76,1169.65 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip050)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 336.451,1169.65 336.451,1157.09 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip050)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 813.415,1169.65 813.415,1157.09 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip050)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1290.25,1169.65 1290.25,1157.09 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip050)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1767.21,1169.65 1767.21,1157.09 \n",
" \"/>\n",
"<path clip-path=\"url(#clip050)\" d=\"M280.977 1222.54 L288.615 1222.54 L288.615 1196.18 L280.305 1197.85 L280.305 1193.59 L288.569 1191.92 L293.245 1191.92 L293.245 1222.54 L300.884 1222.54 L300.884 1226.48 L280.977 1226.48 L280.977 1222.54 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M310.467 1225.76 L310.467 1221.5 Q312.226 1222.34 314.032 1222.78 Q315.837 1223.22 317.574 1223.22 Q322.203 1223.22 324.634 1220.11 Q327.087 1216.99 327.435 1210.65 Q326.092 1212.64 324.032 1213.7 Q321.972 1214.77 319.472 1214.77 Q314.287 1214.77 311.254 1211.64 Q308.245 1208.49 308.245 1203.05 Q308.245 1197.73 311.393 1194.51 Q314.541 1191.29 319.773 1191.29 Q325.768 1191.29 328.916 1195.9 Q332.087 1200.48 332.087 1209.23 Q332.087 1217.41 328.199 1222.29 Q324.333 1227.15 317.782 1227.15 Q316.023 1227.15 314.217 1226.8 Q312.412 1226.46 310.467 1225.76 M319.773 1211.11 Q322.921 1211.11 324.749 1208.96 Q326.601 1206.8 326.601 1203.05 Q326.601 1199.33 324.749 1197.17 Q322.921 1195 319.773 1195 Q316.625 1195 314.773 1197.17 Q312.944 1199.33 312.944 1203.05 Q312.944 1206.8 314.773 1208.96 Q316.625 1211.11 319.773 1211.11 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M350.49 1210.07 Q347.157 1210.07 345.235 1211.85 Q343.337 1213.63 343.337 1216.76 Q343.337 1219.88 345.235 1221.67 Q347.157 1223.45 350.49 1223.45 Q353.823 1223.45 355.745 1221.67 Q357.666 1219.86 357.666 1216.76 Q357.666 1213.63 355.745 1211.85 Q353.847 1210.07 350.49 1210.07 M345.814 1208.08 Q342.805 1207.34 341.115 1205.28 Q339.448 1203.22 339.448 1200.25 Q339.448 1196.11 342.388 1193.7 Q345.351 1191.29 350.49 1191.29 Q355.652 1191.29 358.592 1193.7 Q361.532 1196.11 361.532 1200.25 Q361.532 1203.22 359.842 1205.28 Q358.175 1207.34 355.189 1208.08 Q358.569 1208.86 360.444 1211.16 Q362.342 1213.45 362.342 1216.76 Q362.342 1221.78 359.263 1224.47 Q356.208 1227.15 350.49 1227.15 Q344.772 1227.15 341.694 1224.47 Q338.638 1221.78 338.638 1216.76 Q338.638 1213.45 340.536 1211.16 Q342.435 1208.86 345.814 1208.08 M344.101 1200.69 Q344.101 1203.38 345.768 1204.88 Q347.458 1206.39 350.49 1206.39 Q353.499 1206.39 355.189 1204.88 Q356.902 1203.38 356.902 1200.69 Q356.902 1198.01 355.189 1196.5 Q353.499 1195 350.49 1195 Q347.458 1195 345.768 1196.5 Q344.101 1198.01 344.101 1200.69 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M380.652 1195 Q377.041 1195 375.212 1198.56 Q373.407 1202.11 373.407 1209.23 Q373.407 1216.34 375.212 1219.91 Q377.041 1223.45 380.652 1223.45 Q384.286 1223.45 386.092 1219.91 Q387.92 1216.34 387.92 1209.23 Q387.92 1202.11 386.092 1198.56 Q384.286 1195 380.652 1195 M380.652 1191.29 Q386.462 1191.29 389.518 1195.9 Q392.596 1200.48 392.596 1209.23 Q392.596 1217.96 389.518 1222.57 Q386.462 1227.15 380.652 1227.15 Q374.842 1227.15 371.763 1222.57 Q368.708 1217.96 368.708 1209.23 Q368.708 1200.48 371.763 1195.9 Q374.842 1191.29 380.652 1191.29 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M757.941 1222.54 L765.58 1222.54 L765.58 1196.18 L757.269 1197.85 L757.269 1193.59 L765.533 1191.92 L770.209 1191.92 L770.209 1222.54 L777.848 1222.54 L777.848 1226.48 L757.941 1226.48 L757.941 1222.54 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M787.431 1225.76 L787.431 1221.5 Q789.191 1222.34 790.996 1222.78 Q792.802 1223.22 794.538 1223.22 Q799.167 1223.22 801.598 1220.11 Q804.052 1216.99 804.399 1210.65 Q803.056 1212.64 800.996 1213.7 Q798.936 1214.77 796.436 1214.77 Q791.251 1214.77 788.218 1211.64 Q785.209 1208.49 785.209 1203.05 Q785.209 1197.73 788.357 1194.51 Q791.505 1191.29 796.737 1191.29 Q802.732 1191.29 805.88 1195.9 Q809.052 1200.48 809.052 1209.23 Q809.052 1217.41 805.163 1222.29 Q801.297 1227.15 794.746 1227.15 Q792.987 1227.15 791.181 1226.8 Q789.376 1226.46 787.431 1225.76 M796.737 1211.11 Q799.885 1211.11 801.714 1208.96 Q803.565 1206.8 803.565 1203.05 Q803.565 1199.33 801.714 1197.17 Q
" 242.659,1169.65 1872.76,1169.65 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip052)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 242.659,931.881 1872.76,931.881 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip052)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 242.659,694.113 1872.76,694.113 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip052)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 242.659,456.346 1872.76,456.346 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip052)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 242.659,218.579 1872.76,218.579 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip050)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 242.659,1169.65 242.659,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip050)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 242.659,1169.65 262.22,1169.65 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip050)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 242.659,931.881 262.22,931.881 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip050)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 242.659,694.113 262.22,694.113 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip050)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 242.659,456.346 262.22,456.346 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip050)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 242.659,218.579 262.22,218.579 \n",
" \"/>\n",
"<path clip-path=\"url(#clip050)\" d=\"M156.683 1155.45 Q153.072 1155.45 151.243 1159.01 Q149.438 1162.55 149.438 1169.68 Q149.438 1176.79 151.243 1180.35 Q153.072 1183.9 156.683 1183.9 Q160.317 1183.9 162.123 1180.35 Q163.952 1176.79 163.952 1169.68 Q163.952 1162.55 162.123 1159.01 Q160.317 1155.45 156.683 1155.45 M156.683 1151.74 Q162.493 1151.74 165.549 1156.35 Q168.627 1160.93 168.627 1169.68 Q168.627 1178.41 165.549 1183.02 Q162.493 1187.6 156.683 1187.6 Q150.873 1187.6 147.794 1183.02 Q144.739 1178.41 144.739 1169.68 Q144.739 1160.93 147.794 1156.35 Q150.873 1151.74 156.683 1151.74 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M176.845 1181.05 L181.729 1181.05 L181.729 1186.93 L176.845 1186.93 L176.845 1181.05 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M201.914 1155.45 Q198.303 1155.45 196.475 1159.01 Q194.669 1162.55 194.669 1169.68 Q194.669 1176.79 196.475 1180.35 Q198.303 1183.9 201.914 1183.9 Q205.549 1183.9 207.354 1180.35 Q209.183 1176.79 209.183 1169.68 Q209.183 1162.55 207.354 1159.01 Q205.549 1155.45 201.914 1155.45 M201.914 1151.74 Q207.724 1151.74 210.78 1156.35 Q213.859 1160.93 213.859 1169.68 Q213.859 1178.41 210.78 1183.02 Q207.724 1187.6 201.914 1187.6 Q196.104 1187.6 193.025 1183.02 Q189.97 1178.41 189.97 1169.68 Q189.97 1160.93 193.025 1156.35 Q196.104 1151.74 201.914 1151.74 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M151.706 945.225 L168.026 945.225 L168.026 949.161 L146.081 949.161 L146.081 945.225 Q148.743 942.471 153.327 937.841 Q157.933 933.189 159.114 931.846 Q161.359 929.323 162.239 927.587 Q163.141 925.827 163.141 924.138 Q163.141 921.383 161.197 919.647 Q159.276 917.911 156.174 917.911 Q153.975 917.911 151.521 918.675 Q149.091 919.439 146.313 920.99 L146.313 916.267 Q149.137 915.133 151.591 914.554 Q154.044 913.976 156.081 913.976 Q161.452 913.976 164.646 916.661 Q167.84 919.346 167.84 923.837 Q167.84 925.966 167.03 927.888 Q166.243 929.786 164.137 932.378 Q163.558 933.05 160.456 936.267 Q157.354 939.462 151.706 945.225 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M177.84 943.281 L182.725 943.281 L182.725 949.161 L177.84 949.161 L177.84 943.281 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M192.956 914.601 L211.312 914.601 L211.312 918.536 L197.238 918.536 L197.238 927.008 Q198.257 926.661 199.275 926.499 Q200.294 926.314 201.312 926.314 Q207.099 926.314 210.479 929.485 Q213.859 932.656 213.859 938.073 Q213.859 943.651 210.387 946.753 Q206.914 949.832 200.595 949.832 Q198.419 949.832 196.15 949.462 Q193.905 949.091 191.498 948.35 L191.498 943.651 Q193.581 944.786 195.803 945.341 Q198.025 945.897 200.502 945.897 Q204.507 945.897 206.845 943.79 Q209.183 941.684 209.183 938.073 Q209.183 934.462 206.845 932.355 Q204.507 930.249 200.502 930.249 Q198.627 930.249 196.752 930.665 Q194.9 931.082 192.956 931.962 L192.956 914.601 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M146.729 676.833 L165.086 676.833 L165.086 680.769 L151.012 680.769 L151.012 689.241 Q152.03 688.894 153.049 688.732 Q154.067 688.546 155.086 688.546 Q160.873 688.546 164.252 691.718 Q167.632 694.889 167.632 700.306 Q167.632 705.884 164.16 708.986 Q160.688 712.065 154.368 712.065 Q152.192 712.065 149.924 711.694 Q147.679 711.324 145.271 710.583 L145.271 705.884 Q147.354 707.018 149.577 707.574 Q151.799 708.13 154.276 708.13 Q158.28 708.13 160.618 706.023 Q162.956 703.917 162.956 700.306 Q162.956 696.694 160.618 694.588 Q158.28 692.482 154.276 692.482 Q152.401 692.482 150.526 692.898 Q148.674 693.315 146.729 694.194 L146.729 676.833 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M176.845 705.514 L181.729 705.514 L181.729 711.393 L176.845 711.393 L176.845 705.514 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path
" 288.794,508.779 292.841,515.924 296.497,519.941 300.545,514.832 304.462,532.595 308.509,543.255 312.426,550.827 316.474,567.93 320.522,560.458 324.439,575.771 \n",
" 328.486,522.818 332.403,520.784 336.451,537.243 340.498,531.048 344.285,546.932 348.332,407.164 352.249,419.33 356.297,423.607 360.214,438.88 364.262,432.568 \n",
" 368.309,451.699 372.226,469.275 376.274,488.285 380.191,442.39 384.239,439.801 388.286,434.81 391.942,454.855 395.99,468.056 399.907,480.797 403.954,499.56 \n",
" 407.871,510.439 411.919,524.558 415.967,493.919 419.884,457.077 423.931,462.349 427.848,474.837 431.896,478.821 435.943,484.392 439.599,467.128 443.647,480.869 \n",
" 447.564,494.134 451.612,495.782 455.529,501.087 459.576,507.779 463.624,435.468 467.541,455.253 471.588,387.788 475.505,397.466 479.553,418.444 483.601,432.458 \n",
" 487.257,450.038 491.304,465.695 495.221,454.99 499.269,474.534 503.186,488.385 507.233,490.159 511.281,507.946 515.198,526.097 519.246,528.589 523.163,543.818 \n",
" 527.21,555.951 531.258,566.382 535.044,557.841 539.092,574.782 543.009,590.003 547.057,564.68 550.974,580.529 555.021,585.297 559.069,513.592 562.986,529.887 \n",
" 567.034,545.213 570.951,557.214 574.998,572.985 579.046,540.336 582.702,557.485 586.749,572.632 590.666,586.934 594.714,585.214 598.631,601.159 602.679,615.442 \n",
" 606.726,628.213 610.643,616.025 614.691,621.198 618.608,603.871 622.655,610.35 626.703,625.928 630.359,603.488 634.407,601.962 638.324,614.147 642.371,613.678 \n",
" 646.288,629.115 650.336,593.923 654.383,580.211 658.3,523.496 662.348,528.159 666.265,545.612 670.313,550.226 674.36,448.969 678.016,457.42 682.064,475.539 \n",
" 685.981,488.346 690.028,506.858 693.945,515.782 697.993,523.961 702.041,535.609 705.958,544.316 710.005,164.687 713.922,152.975 717.97,159.193 722.017,178.689 \n",
" 725.804,195.232 729.852,216.948 733.769,242.519 737.816,266.716 741.733,280.386 745.781,302.118 749.828,314.845 753.745,333.679 757.793,356.086 761.71,372.488 \n",
" 765.758,393.559 769.805,392.65 773.461,407.712 777.509,427.867 781.426,438.329 785.473,453.214 789.39,470.19 793.438,456.231 797.486,475.134 801.403,492.54 \n",
" 805.45,496.215 809.367,514.513 813.415,532.216 817.463,492.129 821.118,510.648 825.166,527.595 829.083,530.306 833.131,497.933 837.048,514.059 841.095,527.8 \n",
" 845.143,454.12 849.06,439.482 853.108,454.356 857.025,450.737 861.072,467.937 865.12,475.448 868.776,460.212 872.823,476.85 876.74,495.306 880.788,506.204 \n",
" 884.705,499.444 888.753,506.905 892.8,522.869 896.717,536.566 900.765,553.526 904.682,550.229 908.729,485.685 912.777,503.505 916.564,521.64 920.611,529.86 \n",
" 924.528,547.353 928.576,564.505 932.493,573.66 936.54,581.213 940.588,589.252 944.505,605.258 948.553,620.926 952.47,625.894 956.517,640.274 960.565,654.933 \n",
" 964.221,669.328 968.268,680.378 972.185,681.313 976.233,689.924 980.15,703.408 984.198,715.65 988.245,717.014 992.162,729.138 996.21,740.519 1000.13,744.161 \n",
" 1004.17,754.771 1008.22,759.797 1011.88,757.878 1015.93,731.785 1019.84,744.313 1023.89,756.532 1027.81,750.608 1031.85,756.493 1035.9,754.279 1039.82,755.922 \n",
" 1043.87,767.557 1047.78,750.219 1051.83,762.227 1055.88,772.602 1059.54,772.244 1063.58,780.088 1067.5,788.442 1071.55,792.348 1075.46,797.369 1079.51,795.129 \n",
" 1083.56,806.032 1087.48,806.724 1091.52,810.225 1095.44,805.27 1099.49,815.675 1103.54,821.318 1107.32,830.961 1111.37,840.971 1115.29,847.179 1119.34,852.303 \n",
" 1123.25,856.239 1127.3,801.643 1131.35,805.124 1135.26,789.8 1139.31,800.695 1143.23,768.629 1147.28,773.679 1151.32,760.411 1154.98,770.602 1159.03,742.247 \n",
" 1162.94,741.448 1166.99,708.563 1170.91,707.652 1174.96,670.647 1179,661.076 1182.92,650.471 1186.97,643.912 1190.89,654.201 1194.93,668.171 1198.98,681.94 \n",
" 1202.64,651.575 1206.69,647.867 1210.6,662.525 1214.65,662.884 1218.57,671.941 1222.61,673.577 1226.66,430.239 1230.58,428.565 1234.63,416.25 1238.54,415.535 \n",
" 1242.59,414.539 1246.64,428.682 1250.29,431.364 1254.34,445.563 1258.26,453.06 1262.31,465.374 1266.22,471.151 1270.27,476.853 1274.32,492.551 1278.24,502.105 \n",
" 1282.28,497.391 1286.2,509.57 1290.25,482.362 1294.3,480.784 1298.08,495.826 1302.13,498.883 1306.05,476.356 1310.09,474.846 1314.01,479.68 1318.06,492.119 \n",
" 1322.11,475.825 1326.02,463.356 1330.07,472.045 1333.99,391.228 1338.04,411.73 1342.08,426.357 1345.74,358.608 1349.79,334.997 1353.7,320.194 1357.75,343.139 \n",
" 1361.67,360.639 1365.72,377.214 1369.76,365.324 1373.68,317.166 1377.73,337.574 1381.65,325.337 1385.69,347.419 1389.74,365.805 1393.4,381.528 1397.44,392.682 \n",
" 1401.36,389.756 1405.41,408.563 1409.33,384.595 1413.37,349.669 1417.42,371.878 1421.34,313.187 1425.39,305.749 1429.3,309.473 1433.35,308.209 1437.4,325.207 \n",
" 1441.05,344.598 1445.1,366.862 1449.02,347.957 1453.07,347.777 1456.98,369.426 1461.03,389.187 1465.08,407.912 1469,426.721 1473.04,424.905 1476.96,444.453 \n",
" 1481.01,452.424 1485.06,469.901 1488.84,488.418 1492.89,504.499 1496.81,514.527 1500.85,532.074 1504.77,547.708 1508.82,546.781 1512.87,563.822 1516.78,578.929 \n",
" 1520.83,594.238 1524.75,594.144 1528.8,602.708 1532.84,606.917 1536.5,620.331 1540.55,629.284 1544.46,632.937 1548.51,638.855 1552.43,653.637 1556.48,655.061 \n",
" 1560.52,667.117 1564.44,681.259 1568.49,685.201 1572.41,687.763 1576.45,701.036 1580.5,703.441 1584.16,715.25 1588.2,727.133 1592.12,739.644 1596.17,730.599 \n",
" 1600.09,741.802 1604.13,752.261 1608.18,761.377 1612.1,772.01 1616.15,773.652 1620.06,782.633 1624.11,793.873 1628.16,803.677 1631.81,806.111 1635.86,816.659 \n",
" 1639.78,814.037 1643.83,812.159 1647.74,813.569 1651.79,798.564 1655.84,809.377 1659.76,805.215 1663.8,811.843 1667.72,773.468 1671.77,782.623 1675.82,729.07 \n",
" 1679.6,731.018 1683.65,739.46 1687.57,728.291 1691.61,737.69 1695.53,662.989 1699.58,672.537 1703.63,686.404 1707.54,583.873 1711.59,310.937 1715.51,278.666 \n",
" 1719.56,301.278 1723.6,278.855 1727.26,230.061 1731.31,214.593 1735.22,175.205 1739.27,179.789 1743.19,205.839 1747.24,196.745 1751.28,218.811 1755.2,234.879 \n",
" 1759.25,252.574 1763.17,260.484 1767.21,281.52 1771.26,293.266 1774.92,311.193 1778.96,311.447 1782.88,333.257 1786.93,305.665 1790.85,306.395 1794.89,301.52 \n",
" 1798.94,308.235 1802.86,282.17 1806.91,299.02 1810.82,322.513 1814.87,319.541 1818.92,341.153 1822.57,356.179 1826.62,378.152 \n",
" \"/>\n",
"<path clip-path=\"url(#clip050)\" d=\"M442.521 1055.85 Q439.419 1061.17 437.914 1066.38 Q436.41 1071.59 436.41 1076.94 Q436.41 1082.28 437.914 1087.54 Q439.442 1092.77 442.521 1098.07 L438.817 1098.07 Q435.345 1092.63 433.609 1087.38 Q431.896 1082.12 431.896 1076.94 Q431.896 1071.77 433.609 1066.54 Q435.322 1061.31 438.817 1055.85 L442.521 1055.85 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M463.91 1055.8 L463.91 1059.34 L459.836 1059.34 Q457.544 1059.34 456.641 1060.27 Q455.761 1061.2 455.761 1063.6 L455.761 1065.9 L462.775 1065.9 L462.775 1069.21 L455.761 1069.21 L455.761 1091.82 L451.479 1091.82 L451.479 1069.21 L447.405 1069.21 L447.405 1065.9 L451.479 1065.9 L451.479 1064.09 Q451.479 1059.76 453.493 1057.79 Q455.507 1055.8 459.882 1055.8 L463.91 1055.8 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M477.521 1068.88 Q474.095 1068.88 472.104 1071.57 Q470.113 1074.23 470.113 1078.88 Q470.113 1083.53 472.081 1086.22 Q474.072 1088.88 477.521 1088.88 Q480.923 1088.88 482.914 1086.2 Q484.905 1083.51 484.905 1078.88 Q484.905 1074.27 482.914 1071.59 Q480.923 1068.88 477.521 1068.88 M477.521 1065.27 Q483.076 1065.27 486.247 1068.88 Q489.419 1072.49 489.419 1078.88 Q489.419 1085.25 486.247 1088.88 Q483.076 1092.49 477.521 1092.49 Q471.942 1092.49 468.771 1088.88 Q465.623 1085.25 465.623 1078.88 Q465.623 1072.49 468.771 1068.88 Q471.942 1065.27 477.521 1065.27 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M511.502 1069.88 Q510.784 1069.46 509.928 1069.27 Q509.095 1069.07 508.076 1069.07 Q504.465 1069.07 502.52 1071.43 Q500.599 1073.77 500.599 1078.16 L500.599 1091.82 L496.317 1091.82 L496.317 1065.9 L500.599 1065.9 L500.599 1069.92 Q501.942 1067.56 504.095 1066.43 Q506.247 1065.27 509.326 1065.27 Q509.766 1065.27 510.298 1065.34 Q510.831 1065.39 511.479 1065.5 L511.502 1069.88 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M530.692 1057.26 L535.391 1057.26 L535.391 1078.26 Q535.391 1083.81 537.405 1086.27 Q539.418 1088.7 543.932 1088.7 Q548.423 1088.7 550.437 1086.27 Q552.451 1083.81 552.451 1078.26 L552.451 1057.26 L557.15 1057.26 L557.15 1078.83 Q557.15 1085.59 553.793 1089.04 Q550.46 1092.49 543.932 1092.49 Q537.381 1092.49 534.025 1089.04 Q530.692 1085.59 530.692 1078.83 L530.692 1057.26 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M586.64 1058.4 L586.64 1062.96 Q583.978 1061.68 581.617 1061.06 Q579.256 1060.43 577.057 1060.43 Q573.238 1060.43 571.154 1061.91 Q569.094 1063.4 569.094 1066.13 Q569.094 1068.42 570.46 1069.6 Q571.849 1070.76 575.691 1071.47 L578.515 1072.05 Q583.747 1073.05 586.224 1075.57 Q588.724 1078.07 588.724 1082.28 Q588.724 1087.31 585.344 1089.9 Q581.988 1092.49 575.483 1092.49 Q573.029 1092.49 570.252 1091.94 Q567.497 1091.38 564.534 1090.29 L564.534 1085.48 Q567.381 1087.08 570.113 1087.89 Q572.844 1088.7 575.483 1088.7 Q579.488 1088.7 581.664 1087.12 Q583.839 1085.55 583.839 1082.63 Q583.839 1080.08 582.265 1078.65 Q580.714 1077.21 577.15 1076.5 L574.302 1075.94 Q569.071 1074.9 566.733 1072.68 Q564.395 1070.46 564.395 1066.5 Q564.395 1061.91 567.613 1059.27 Q570.853 1056.64 576.525 1056.64 Q578.955 1056.64 581.478 1057.08 Q584.002 1057.52 586.64 1058.4 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip050)\" d=\"M633.075 1077.79 L633.075 1079.88 L613.492 1079.88 Q613.77 1084.27 616.131 1086.59 Q618.515 1088.88 622.751 1088.88 Q625.205 1088.88 627.497 1088.28 Q629.811 1087.68 632.08 1086.47 L632.08 1090.5 Q629.788 1091.47 627.381 1091.98 Q624.974 1092.49 622.497 1092.49 Q616.293 1092.49 612.659 1088.88 Q609.048 1085.27 609.048 1079.11 Q609.048 1072.75 612.474 1069.02 Q615.923 1065.27 621.756 1065.27 Q626.987 1065.27 630.02 1068.65 Q633.075 1072.01 633.075 1077.79 M628.816 1076.54 Q628.77 1073.05 626.849 1070.96 Q624.95 1068.88 621.802 1068.88 Q618.237 1068.88 616.085 1070.9 Q6
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"xTicksLoc = [Date(1980);Date(1990);Date(2000);Date(2010)]\n",
"xTicksLab = Dates.format.(xTicksLoc,\"Y\")\n",
"\n",
"p1 = plot( dN,VaR95,\n",
" color = :blue,\n",
" legend = false,\n",
" xticks = (xTicksLoc,xTicksLab),\n",
" ylim = (0,11),\n",
" title = \"1-month Value at Risk (95%)\",\n",
" ylabel = \"%\",\n",
" annotation = (Date(1982),1,text(\"(for US equity market)\",8,:left)) )\n",
"display(p1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Options"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Black-Scholes Option Price\n",
"\n",
"Let $S$ be the the current spot price of an asset and $y$ be the interest rate.\n",
"\n",
"The Black-Scholes formula for a European call option with strike price $K$ and time to expiration $m$ is\n",
"\n",
"$C =S\\Phi(d_{1}) -e^{-ym}K\\Phi(d_{2})$, where\n",
"\n",
"$d_{1} =\\frac{\\ln(S/K)+(y+\\sigma^{2}/2)m}{\\sigma\\sqrt{m}} \\ \\text{ and } \\ d_{2}=d_{1}-\\sigma\\sqrt{m}$ \n",
"\n",
"and where $\\Phi(d)$ denotes the probability of $x\\leq d$ when $x$ has an $N(0,1)$ distribution. All variables except the volatility ($\\sigma$) are directly observable. "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"OptionBlackSPs"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\"\"\"\n",
"Pr(z<=x) for N(0,1)\n",
"\"\"\"\n",
"Φ(x) = cdf(Normal(0,1),x) #a one-line function\n",
"\n",
"\"\"\"\n",
"Calculate Black-Scholes european call option price\n",
"\"\"\"\n",
"function OptionBlackSPs(S,K,m,y,σ)\n",
"\n",
" d1 = ( log(S/K) + (y+1/2*σ^2)*m ) / (σ*sqrt(m))\n",
" d2 = d1 - σ*sqrt(m)\n",
" c = S*Φ(d1) - exp(-y*m)*K*Φ(d2)\n",
" return c\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" \n",
"call price according to Black-Scholes: 1.358\n"
]
}
],
"source": [
"σ = 0.4\n",
"c1 = OptionBlackSPs(10,10,0.5,0.1,σ)\n",
"printlnPs(\"\\n\",\"call price according to Black-Scholes: \",c1)\n",
"\n",
"K = range(7,stop=13,length=51)\n",
"c = OptionBlackSPs.(10,K,0.5,0.1,σ);"
]
},
{
"cell_type": "code",
"execution_count": 11,
"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=\"clip090\">\n",
" <rect x=\"0\" y=\"0\" width=\"1920\" height=\"1280\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip090)\" 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=\"clip091\">\n",
" <rect x=\"384\" y=\"0\" width=\"1345\" height=\"1280\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip090)\" d=\"\n",
"M214.233 1106.38 L1872.76 1106.38 L1872.76 123.472 L214.233 123.472 Z\n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<defs>\n",
" <clipPath id=\"clip092\">\n",
" <rect x=\"214\" y=\"123\" width=\"1660\" height=\"984\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<polyline clip-path=\"url(#clip092)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 261.172,1106.38 261.172,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip092)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 521.946,1106.38 521.946,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip092)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 782.72,1106.38 782.72,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip092)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1043.49,1106.38 1043.49,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip092)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1304.27,1106.38 1304.27,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip092)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1565.04,1106.38 1565.04,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip092)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1825.82,1106.38 1825.82,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip090)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 214.233,1106.38 1872.76,1106.38 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip090)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 261.172,1106.38 261.172,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip090)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 521.946,1106.38 521.946,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip090)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 782.72,1106.38 782.72,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip090)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1043.49,1106.38 1043.49,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip090)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1304.27,1106.38 1304.27,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip090)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1565.04,1106.38 1565.04,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip090)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1825.82,1106.38 1825.82,1094.58 \n",
" \"/>\n",
"<path clip-path=\"url(#clip090)\" d=\"M250.061 1128.65 L272.283 1128.65 L272.283 1130.64 L259.737 1163.21 L254.853 1163.21 L266.658 1132.59 L250.061 1132.59 L250.061 1128.65 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip090)\" d=\"M521.946 1146.8 Q518.613 1146.8 516.692 1148.58 Q514.794 1150.36 514.794 1153.49 Q514.794 1156.61 516.692 1158.4 Q518.613 1160.18 521.946 1160.18 Q525.28 1160.18 527.201 1158.4 Q529.122 1156.59 529.122 1153.49 Q529.122 1150.36 527.201 1148.58 Q525.303 1146.8 521.946 1146.8 M517.27 1144.81 Q514.261 1144.07 512.571 1142.01 Q510.905 1139.95 510.905 1136.99 Q510.905 1132.84 513.845 1130.43 Q516.807 1128.03 521.946 1128.03 Q527.108 1128.03 530.048 1130.43 Q532.988 1132.84 532.988 1136.99 Q532.988 1139.95 531.298 1142.01 Q529.631 1144.07 526.645 1144.81 Q530.025 1145.6 531.9 1147.89 Q533.798 1150.18 533.798 1153.49 Q533.798 1158.51 530.719 1161.2 Q527.664 1163.88 521.946 1163.88 Q516.229 1163.88 513.15 1161.2 Q510.095 1158.51 510.095 1153.49 Q510.095 1150.18 511.993 1147.89 Q513.891 1145.6 517.27 1144.81 M515.557 1137.42 Q515.557 1140.11 517.224 1141.61 Q518.914 1143.12 521.946 1143.12 Q524.956 1143.12 526.645 1141.61 Q528.358 1140.11 528.358 1137.42 Q528.358 1134.74 526.645 1133.24 Q524.956 1131.73 521.946 1131.73 Q518.914 1131.73 517.224 1133.24 Q515.557 1134.74 515.557 1137.42 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip090)\" d=\"M773.021 1162.49 L773.021 1158.24 Q774.781 1159.07 776.586 1159.51 Q778.392 1159.95 780.128 1159.95 Q784.757 1159.95 787.188 1156.85 Q789.642 1153.72 789.989 1147.38 Q788.646 1149.37 786.586 1150.43 Q784.526 1151.5 782.026 1151.5 Q776.841 1151.5 773.808 1148.37 Q770.799 1145.23 770.799 1139.79 Q770.799 1134.46 773.947 1131.24 Q777.095 1128.03 782.327 1128.03 Q788.322 1128.03 791.47 1132.63 Q794.642 1137.22 794.642 1145.97 Q794.642 1154.14 790.753 1159.02 Q786.887 1163.88 780.336 1163.88 Q778.577 1163.88 776.771 1163.54 Q774.966 1163.19 773.021 1162.49 M782.327 1147.84 Q785.475 1147.84 787.304 1145.69 Q789.156 1143.54 789.156 1139.79 Q789.156 1136.06 787.304 1133.91 Q785.475 1131.73 782.327 1131.73 Q779.179 1131.73 777.327 1133.91 Q775.498 1136.06 775.498 1139.79 Q775.498 1143.54 777.327 1145.69 Q779.179 1147.84 782.327 1147.84 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip090)\" d=\"M1018.18 1159.28 L1025.82 1159.28 L1025.82 1132.91 L1017.51 1134.58 L1017.51 1130.32 L1025.77 1128.65 L1030.45 1128.65 L1030.45 1159.28 L1038.09 1159.28 L1038.09 1163.21 L1018.18 1163.21 L1018.18 1159.28 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip090)\" d=\"M1057.53 1131.73 Q1053.92 1131.73 1052.09 1135.3 Q1050.29 1138.84 1050.29 1145.97 Q1050.29 1153.07 1052.09 1156.64 Q1053.92 1160.18 1057.53 1160.18 Q1061.17 1160.18 1062.97 1156.64 Q1064.8 1153.07 1064.8 1145.97 Q1064.8 1138.84 1062.97 1135.3 Q1061.17 1131.73 1057.53 1131.73 M1057.53 1128.03 Q1063.34 1128.03 1066.4 1132.63 Q1069.48 1137.22 1069.48 1145.97 Q1069.48 1154.69 1066.4 1159.3 Q1063.34 1163.88 1057.53 1163.88 Q1051.72 1163.88 1048.64 1159.3 Q1045.59 1154.69 1045.59 1145.97 Q1045.59 1137.22 1048.64 1132.63 Q1051.72 1128.03 1057.53 1128.03 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip090)\" d=\"M1279.57 1159.28 L1287.21 1159.28 L1287.21 1132.91 L1278.9 1134.58 L1278.9 1130.32 L1287.16 1128.65 L1291.84 1128.65 L1291.84 1159.28 L1299.48 1159.28 L1299.48 1163.21 L1279.57 1163.21 L1279.57 1159.28 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip090)\" d=\"M1309.73 1159.28 L1317.37 1159.28 L1317.37 1132.91 L1309.06 1134.58 L1309.06 1130.32 L1317.32 1128.65 L1322 1128.65 L1322 1159.28 L1329.64 1159.28 L1329.64 1163.21 L1309.73 1163.21 L1309.73 1159.28 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip090)\" d=\"M1540.53 1159.28 L1548.17 1159.28 L1548.17 1132.91 L1539.86 1134.58 L1539.86 1130.32 L1548.12 1128.65 L1552.8 11
" 214.233,1050.7 1872.76,1050.7 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip092)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 214.233,896.624 1872.76,896.624 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip092)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 214.233,742.545 1872.76,742.545 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip092)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 214.233,588.465 1872.76,588.465 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip092)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 214.233,434.386 1872.76,434.386 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip092)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 214.233,280.306 1872.76,280.306 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip092)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 214.233,126.226 1872.76,126.226 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip090)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 214.233,1106.38 214.233,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip090)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 214.233,1050.7 234.135,1050.7 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip090)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 214.233,896.624 234.135,896.624 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip090)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 214.233,742.545 234.135,742.545 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip090)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 214.233,588.465 234.135,588.465 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip090)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 214.233,434.386 234.135,434.386 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip090)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 214.233,280.306 234.135,280.306 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip090)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 214.233,126.226 234.135,126.226 \n",
" \"/>\n",
"<path clip-path=\"url(#clip090)\" d=\"M129.253 1036.5 Q125.642 1036.5 123.813 1040.07 Q122.007 1043.61 122.007 1050.74 Q122.007 1057.84 123.813 1061.41 Q125.642 1064.95 129.253 1064.95 Q132.887 1064.95 134.692 1061.41 Q136.521 1057.84 136.521 1050.74 Q136.521 1043.61 134.692 1040.07 Q132.887 1036.5 129.253 1036.5 M129.253 1032.8 Q135.063 1032.8 138.118 1037.41 Q141.197 1041.99 141.197 1050.74 Q141.197 1059.47 138.118 1064.07 Q135.063 1068.66 129.253 1068.66 Q123.443 1068.66 120.364 1064.07 Q117.308 1059.47 117.308 1050.74 Q117.308 1041.99 120.364 1037.41 Q123.443 1032.8 129.253 1032.8 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip090)\" d=\"M149.415 1062.1 L154.299 1062.1 L154.299 1067.98 L149.415 1067.98 L149.415 1062.1 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip090)\" d=\"M164.53 1033.42 L182.887 1033.42 L182.887 1037.36 L168.813 1037.36 L168.813 1045.83 Q169.831 1045.48 170.85 1045.32 Q171.868 1045.14 172.887 1045.14 Q178.674 1045.14 182.053 1048.31 Q185.433 1051.48 185.433 1056.9 Q185.433 1062.47 181.961 1065.58 Q178.489 1068.66 172.169 1068.66 Q169.993 1068.66 167.725 1068.28 Q165.479 1067.91 163.072 1067.17 L163.072 1062.47 Q165.155 1063.61 167.377 1064.16 Q169.6 1064.72 172.077 1064.72 Q176.081 1064.72 178.419 1062.61 Q180.757 1060.51 180.757 1056.9 Q180.757 1053.28 178.419 1051.18 Q176.081 1049.07 172.077 1049.07 Q170.202 1049.07 168.327 1049.49 Q166.475 1049.91 164.53 1050.78 L164.53 1033.42 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip090)\" d=\"M119.068 909.969 L126.706 909.969 L126.706 883.603 L118.396 885.27 L118.396 881.011 L126.66 879.344 L131.336 879.344 L131.336 909.969 L138.975 909.969 L138.975 913.904 L119.068 913.904 L119.068 909.969 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip090)\" d=\"M148.419 908.025 L153.303 908.025 L153.303 913.904 L148.419 913.904 L148.419 908.025 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip090)\" d=\"M173.489 882.423 Q169.877 882.423 168.049 885.988 Q166.243 889.529 166.243 896.659 Q166.243 903.765 168.049 907.33 Q169.877 910.872 173.489 910.872 Q177.123 910.872 178.928 907.33 Q180.757 903.765 180.757 896.659 Q180.757 889.529 178.928 885.988 Q177.123 882.423 173.489 882.423 M173.489 878.719 Q179.299 878.719 182.354 883.326 Q185.433 887.909 185.433 896.659 Q185.433 905.386 182.354 909.992 Q179.299 914.575 173.489 914.575 Q167.678 914.575 164.6 909.992 Q161.544 905.386 161.544 896.659 Q161.544 887.909 164.6 883.326 Q167.678 878.719 173.489 878.719 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip090)\" d=\"M120.063 755.889 L127.702 755.889 L127.702 729.524 L119.392 731.191 L119.392 726.931 L127.655 725.265 L132.331 725.265 L132.331 755.889 L139.97 755.889 L139.97 759.825 L120.063 759.825 L120.063 755.889 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip090)\" d=\"M149.415 753.945 L154.299 753.945 L154.299 759.825 L149.415 759.825 L149.415 753.945 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip090)\" d=\"M164.53 725.265 L182.887 725.265 L182.887 729.2 L168.813 729.2 L168.813 737.672 Q169.831 737.325 170.85 737.163 Q171.868 736.978 172.887 736.978 Q178.674 736.978 182.053 740.149 Q185.433 743.32 185.433 748.737 Q185.433 754.315 181.961 757.417 Q178.489 760.496 172.169 760.496 Q169.993 760.496 167.725 760.126 Q165.479 759.755 163.072 759.014 L163.072 754.315 Q165.155 755.45 167.377 756.005 Q169.6 756.561 172.077 756.561 Q176.081 756.561 178.419 754.454 Q180.757 752.348 180.757 748.737 Q180.757 745.126 178.419 743.019 Q176.081 740.913 172.077 740.913 Q170.202 740.913 168.327 741.329 Q166.475 741.746 164.53 742.626 L164.53 725.265 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip090)\" d=\"M122.285 601.81 L138.604 601.81 L138.604 605.745 L116.66 605.745 L116.66 601.81 Q119.322 59
" 261.172,151.29 292.465,182.852 323.758,214.024 355.051,244.785 386.344,275.113 417.637,304.989 448.93,334.392 480.222,363.305 511.515,391.709 542.808,419.588 \n",
" 574.101,446.928 605.394,473.714 636.687,499.935 667.98,525.58 699.273,550.638 730.566,575.102 761.858,598.966 793.151,622.224 824.444,644.872 855.737,666.908 \n",
" 887.03,688.33 918.323,709.14 949.616,729.337 980.909,748.926 1012.2,767.909 1043.49,786.291 1074.79,804.079 1106.08,821.278 1137.37,837.896 1168.67,853.943 \n",
" 1199.96,869.426 1231.25,884.355 1262.54,898.741 1293.84,912.595 1325.13,925.928 1356.42,938.752 1387.72,951.078 1419.01,962.92 1450.3,974.289 1481.59,985.199 \n",
" 1512.89,995.661 1544.18,1005.69 1575.47,1015.3 1606.77,1024.5 1638.06,1033.31 1669.35,1041.73 1700.65,1049.78 1731.94,1057.48 1763.23,1064.84 1794.52,1071.86 \n",
" 1825.82,1078.56 \n",
" \"/>\n",
"</svg>\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"p1 = plot( K,c,\n",
" color = :red,\n",
" legend = false,\n",
" title = \"Black-Scholes call option price\",\n",
" xlabel = \"strike price\",\n",
" ylabel = \"option price\" )\n",
"display(p1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Implied Volatility\n",
"\n",
"is the $\\sigma$ value that makes the Black-Scholes equation give the same option price as observed on the market. It is often interpreted as the \"market uncertainty.\"\n",
"\n",
"The next cell uses the call option price calculated above as the market price. The implied volatility should then equal the volatility used above (this is a way to check your coding).\n",
"\n",
"The next few cells instead use some data on options on German government bonds. "
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Implied volatility: 0.400, compare with: 0.4\n"
]
}
],
"source": [
" #solve for implied vol\n",
"iv = find_zero(σ->OptionBlackSPs(10,10,0.5,0.1,σ)-c1,(0.00001,5))\n",
"\n",
"printlnPs(\"Implied volatility: \",iv,\", compare with: $σ\")"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"21"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# LIFFE Bunds option data, trade date April 6, 1994\n",
"K = [ #strike prices; Mx1 vector\n",
" 92.00; 94.00; 94.50; 95.00; 95.50; 96.00; 96.50; 97.00;\n",
" 97.50; 98.00; 98.50; 99.00; 99.50; 100.0; 100.5; 101.0;\n",
" 101.5; 102.0; 102.5; 103.0; 103.5 ];\n",
"C = [ #call prices; Mx1 vector\n",
" 5.13; 3.25; 2.83; 2.40; 2.00; 1.64; 1.31; 1.02;\n",
" 0.770; 0.570; 0.400; 0.280; 0.190; 0.130; 0.0800; 0.0500;\n",
" 0.0400; 0.0300; 0.0200; 0.0100; 0.0100 ];\n",
"S = 97.05 #spot price\n",
"m = 48/365 #time to expiry in years\n",
"y = 0.0 #Interest rate: LIFFE=>no discounting\n",
"N = length(K)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Strike and iv for data: \n",
" 92.000 0.094\n",
" 94.000 0.081\n",
" 94.500 0.081\n",
" 95.000 0.078\n",
" 95.500 0.075\n",
" 96.000 0.074\n",
" 96.500 0.072\n",
" 97.000 0.071\n",
" 97.500 0.070\n",
" 98.000 0.069\n",
" 98.500 0.068\n",
" 99.000 0.067\n",
" 99.500 0.067\n",
" 100.000 0.068\n",
" 100.500 0.067\n",
" 101.000 0.067\n",
" 101.500 0.070\n",
" 102.000 0.073\n",
" 102.500 0.074\n",
" 103.000 0.072\n",
" 103.500 0.077\n",
"\n"
]
}
],
"source": [
"iv = fill(NaN,N) #looping over strikes\n",
"for i = 1:N\n",
" iv[i] = find_zero(sigma->OptionBlackSPs(S,K[i],m,y,sigma)-C[i],(0.00001,5))\n",
"end\n",
"\n",
"println(\"Strike and iv for data: \")\n",
"printmat([K iv])"
]
},
{
"cell_type": "code",
"execution_count": 15,
"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=\"clip130\">\n",
" <rect x=\"0\" y=\"0\" width=\"1920\" height=\"1280\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip130)\" 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=\"clip131\">\n",
" <rect x=\"384\" y=\"0\" width=\"1345\" height=\"1280\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip130)\" d=\"\n",
"M211.636 1106.38 L1872.76 1106.38 L1872.76 123.472 L211.636 123.472 Z\n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<defs>\n",
" <clipPath id=\"clip132\">\n",
" <rect x=\"211\" y=\"123\" width=\"1662\" height=\"984\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<polyline clip-path=\"url(#clip132)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 326.783,1106.38 326.783,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip132)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 667.456,1106.38 667.456,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip132)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1008.13,1106.38 1008.13,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip132)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1348.8,1106.38 1348.8,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip132)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1689.47,1106.38 1689.47,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip130)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 211.636,1106.38 1872.76,1106.38 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip130)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 326.783,1106.38 326.783,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip130)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 667.456,1106.38 667.456,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip130)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1008.13,1106.38 1008.13,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip130)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1348.8,1106.38 1348.8,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip130)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1689.47,1106.38 1689.47,1094.58 \n",
" \"/>\n",
"<path clip-path=\"url(#clip130)\" d=\"M279.793 1162.49 L279.793 1158.24 Q281.552 1159.07 283.358 1159.51 Q285.163 1159.95 286.899 1159.95 Q291.529 1159.95 293.959 1156.85 Q296.413 1153.72 296.76 1147.38 Q295.418 1149.37 293.357 1150.43 Q291.297 1151.5 288.797 1151.5 Q283.612 1151.5 280.58 1148.37 Q277.571 1145.23 277.571 1139.79 Q277.571 1134.46 280.719 1131.24 Q283.867 1128.03 289.098 1128.03 Q295.094 1128.03 298.242 1132.63 Q301.413 1137.22 301.413 1145.97 Q301.413 1154.14 297.524 1159.02 Q293.658 1163.88 287.108 1163.88 Q285.348 1163.88 283.543 1163.54 Q281.737 1163.19 279.793 1162.49 M289.098 1147.84 Q292.246 1147.84 294.075 1145.69 Q295.927 1143.54 295.927 1139.79 Q295.927 1136.06 294.075 1133.91 Q292.246 1131.73 289.098 1131.73 Q285.95 1131.73 284.098 1133.91 Q282.27 1136.06 282.27 1139.79 Q282.27 1143.54 284.098 1145.69 Q285.95 1147.84 289.098 1147.84 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M313.844 1159.28 L330.163 1159.28 L330.163 1163.21 L308.219 1163.21 L308.219 1159.28 Q310.881 1156.52 315.464 1151.89 Q320.07 1147.24 321.251 1145.9 Q323.496 1143.37 324.376 1141.64 Q325.279 1139.88 325.279 1138.19 Q325.279 1135.43 323.334 1133.7 Q321.413 1131.96 318.311 1131.96 Q316.112 1131.96 313.658 1132.73 Q311.228 1133.49 308.45 1135.04 L308.45 1130.32 Q311.274 1129.18 313.728 1128.61 Q316.181 1128.03 318.218 1128.03 Q323.589 1128.03 326.783 1130.71 Q329.978 1133.4 329.978 1137.89 Q329.978 1140.02 329.167 1141.94 Q328.38 1143.84 326.274 1146.43 Q325.695 1147.1 322.593 1150.32 Q319.492 1153.51 313.844 1159.28 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M339.978 1157.33 L344.862 1157.33 L344.862 1163.21 L339.978 1163.21 L339.978 1157.33 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M355.093 1128.65 L373.45 1128.65 L373.45 1132.59 L359.376 1132.59 L359.376 1141.06 Q360.394 1140.71 361.413 1140.55 Q362.431 1140.36 363.45 1140.36 Q369.237 1140.36 372.616 1143.54 Q375.996 1146.71 375.996 1152.12 Q375.996 1157.7 372.524 1160.8 Q369.052 1163.88 362.732 1163.88 Q360.556 1163.88 358.288 1163.51 Q356.042 1163.14 353.635 1162.4 L353.635 1157.7 Q355.718 1158.84 357.94 1159.39 Q360.163 1159.95 362.64 1159.95 Q366.644 1159.95 368.982 1157.84 Q371.32 1155.74 371.32 1152.12 Q371.32 1148.51 368.982 1146.41 Q366.644 1144.3 362.64 1144.3 Q360.765 1144.3 358.89 1144.72 Q357.038 1145.13 355.093 1146.01 L355.093 1128.65 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M619.968 1162.49 L619.968 1158.24 Q621.727 1159.07 623.533 1159.51 Q625.338 1159.95 627.074 1159.95 Q631.704 1159.95 634.134 1156.85 Q636.588 1153.72 636.935 1147.38 Q635.593 1149.37 633.533 1150.43 Q631.472 1151.5 628.972 1151.5 Q623.787 1151.5 620.755 1148.37 Q617.746 1145.23 617.746 1139.79 Q617.746 1134.46 620.894 1131.24 Q624.042 1128.03 629.273 1128.03 Q635.269 1128.03 638.417 1132.63 Q641.588 1137.22 641.588 1145.97 Q641.588 1154.14 637.699 1159.02 Q633.833 1163.88 627.283 1163.88 Q625.523 1163.88 623.718 1163.54 Q621.912 1163.19 619.968 1162.49 M629.273 1147.84 Q632.421 1147.84 634.25 1145.69 Q636.102 1143.54 636.102 1139.79 Q636.102 1136.06 634.25 1133.91 Q632.421 1131.73 629.273 1131.73 Q626.125 1131.73 624.273 1133.91 Q622.445 1136.06 622.445 1139.79 Q622.445 1143.54 624.273 1145.69 Q626.125 1147.84 629.273 1147.84 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M650.037 1128.65 L668.393 1128.65 L668.393 1132.59 L654.319 1132.59 L654.319 1141.06 Q655.338 1140.71 656.356 1140.55 Q657.375 1140.36 658.393 1140.36 Q664.18 1140.36 667.56 1143.54 Q670.94 1146.71 670.94 1152.12 Q670.94 1157.7 667.468 1160.8 Q663.995 1163.88 657.676 1163.88 Q655.5 1163.88 653.231 1163.51 Q650.986 1163.14 648.579 1162.4 L648.579 1157.7 Q650.662 1158.84 652.884 1159.39 Q655.106 1159.95 657.583 1159.95 Q661.588 1159.95 663.926 1157.84 Q666.264 1155.74 666.264 1152.12 Q666.264 1148.51 663.926 1146.41 Q661.588 11
" 211.636,969.212 1872.76,969.212 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip132)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 211.636,797.455 1872.76,797.455 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip132)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 211.636,625.697 1872.76,625.697 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip132)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 211.636,453.939 1872.76,453.939 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip132)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 211.636,282.182 1872.76,282.182 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip130)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 211.636,1106.38 211.636,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip130)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 211.636,969.212 231.569,969.212 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip130)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 211.636,797.455 231.569,797.455 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip130)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 211.636,625.697 231.569,625.697 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip130)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 211.636,453.939 231.569,453.939 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip130)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 211.636,282.182 231.569,282.182 \n",
" \"/>\n",
"<path clip-path=\"url(#clip130)\" d=\"M65.3365 955.011 Q61.7254 955.011 59.8967 958.576 Q58.0912 962.117 58.0912 969.247 Q58.0912 976.353 59.8967 979.918 Q61.7254 983.46 65.3365 983.46 Q68.9707 983.46 70.7763 979.918 Q72.605 976.353 72.605 969.247 Q72.605 962.117 70.7763 958.576 Q68.9707 955.011 65.3365 955.011 M65.3365 951.307 Q71.1467 951.307 74.2022 955.914 Q77.2809 960.497 77.2809 969.247 Q77.2809 977.974 74.2022 982.58 Q71.1467 987.164 65.3365 987.164 Q59.5264 987.164 56.4477 982.58 Q53.3921 977.974 53.3921 969.247 Q53.3921 960.497 56.4477 955.914 Q59.5264 951.307 65.3365 951.307 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M85.4984 980.613 L90.3827 980.613 L90.3827 986.492 L85.4984 986.492 L85.4984 980.613 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M110.568 955.011 Q106.957 955.011 105.128 958.576 Q103.322 962.117 103.322 969.247 Q103.322 976.353 105.128 979.918 Q106.957 983.46 110.568 983.46 Q114.202 983.46 116.008 979.918 Q117.836 976.353 117.836 969.247 Q117.836 962.117 116.008 958.576 Q114.202 955.011 110.568 955.011 M110.568 951.307 Q116.378 951.307 119.433 955.914 Q122.512 960.497 122.512 969.247 Q122.512 977.974 119.433 982.58 Q116.378 987.164 110.568 987.164 Q104.758 987.164 101.679 982.58 Q98.6234 977.974 98.6234 969.247 Q98.6234 960.497 101.679 955.914 Q104.758 951.307 110.568 951.307 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M129.549 951.932 L151.771 951.932 L151.771 953.923 L139.225 986.492 L134.341 986.492 L146.146 955.867 L129.549 955.867 L129.549 951.932 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M170.891 955.011 Q167.28 955.011 165.452 958.576 Q163.646 962.117 163.646 969.247 Q163.646 976.353 165.452 979.918 Q167.28 983.46 170.891 983.46 Q174.526 983.46 176.331 979.918 Q178.16 976.353 178.16 969.247 Q178.16 962.117 176.331 958.576 Q174.526 955.011 170.891 955.011 M170.891 951.307 Q176.702 951.307 179.757 955.914 Q182.836 960.497 182.836 969.247 Q182.836 977.974 179.757 982.58 Q176.702 987.164 170.891 987.164 Q165.081 987.164 162.003 982.58 Q158.947 977.974 158.947 969.247 Q158.947 960.497 162.003 955.914 Q165.081 951.307 170.891 951.307 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M66.3319 783.253 Q62.7208 783.253 60.8921 786.818 Q59.0865 790.36 59.0865 797.489 Q59.0865 804.596 60.8921 808.161 Q62.7208 811.702 66.3319 811.702 Q69.9661 811.702 71.7717 808.161 Q73.6004 804.596 73.6004 797.489 Q73.6004 790.36 71.7717 786.818 Q69.9661 783.253 66.3319 783.253 M66.3319 779.55 Q72.142 779.55 75.1976 784.156 Q78.2763 788.739 78.2763 797.489 Q78.2763 806.216 75.1976 810.823 Q72.142 815.406 66.3319 815.406 Q60.5217 815.406 57.443 810.823 Q54.3875 806.216 54.3875 797.489 Q54.3875 788.739 57.443 784.156 Q60.5217 779.55 66.3319 779.55 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M86.4938 808.855 L91.378 808.855 L91.378 814.735 L86.4938 814.735 L86.4938 808.855 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M111.563 783.253 Q107.952 783.253 106.123 786.818 Q104.318 790.36 104.318 797.489 Q104.318 804.596 106.123 808.161 Q107.952 811.702 111.563 811.702 Q115.197 811.702 117.003 808.161 Q118.832 804.596 118.832 797.489 Q118.832 790.36 117.003 786.818 Q115.197 783.253 111.563 783.253 M111.563 779.55 Q117.373 779.55 120.429 784.156 Q123.507 788.739 123.507 797.489 Q123.507 806.216 120.429 810.823 Q117.373 815.406 111.563 815.406 Q105.753 815.406 102.674 810.823 Q99.6187 806.216 99.6187 797.489 Q99.6187 788.739 102.674 784.156 Q105.753 779.55 111.563 779.55 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M130.544 780.175 L152.767 780.175 L152.767 782.165 L140.22 814.735 L135.336 814.735 L147.142 784.11 L130.544 784.11 L130.544 780.175 Z\" fill=\"#000000\" fill
" 258.649,151.29 531.187,580.027 599.321,588.209 667.456,705.258 735.59,789.91 803.725,837.387 871.86,892.471 939.994,939.229 1008.13,985.08 1076.26,1007.12 \n",
" 1144.4,1054.61 1212.53,1061.85 1280.67,1069.06 1348.8,1049.72 1416.94,1078.56 1485.07,1077.87 1553.2,959.568 1621.34,876.379 1689.47,843.715 1757.61,905.784 \n",
" 1825.74,732.676 \n",
" \"/>\n",
"<path clip-path=\"url(#clip130)\" d=\"M1080.94 282.957 L1080.94 295.619 L1088.44 295.619 Q1092.21 295.619 1094.02 294.068 Q1095.85 292.494 1095.85 289.277 Q1095.85 286.036 1094.02 284.508 Q1092.21 282.957 1088.44 282.957 L1080.94 282.957 M1080.94 268.744 L1080.94 279.161 L1087.86 279.161 Q1091.29 279.161 1092.95 277.888 Q1094.64 276.592 1094.64 273.953 Q1094.64 271.337 1092.95 270.041 Q1091.29 268.744 1087.86 268.744 L1080.94 268.744 M1076.26 264.902 L1088.21 264.902 Q1093.55 264.902 1096.45 267.124 Q1099.34 269.346 1099.34 273.443 Q1099.34 276.615 1097.86 278.49 Q1096.38 280.365 1093.51 280.828 Q1096.96 281.568 1098.86 283.93 Q1100.78 286.267 1100.78 289.786 Q1100.78 294.416 1097.63 296.939 Q1094.48 299.462 1088.67 299.462 L1076.26 299.462 L1076.26 264.902 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M1108.16 289.23 L1108.16 273.536 L1112.42 273.536 L1112.42 289.068 Q1112.42 292.749 1113.86 294.601 Q1115.29 296.429 1118.16 296.429 Q1121.61 296.429 1123.6 294.23 Q1125.61 292.031 1125.61 288.235 L1125.61 273.536 L1129.87 273.536 L1129.87 299.462 L1125.61 299.462 L1125.61 295.48 Q1124.06 297.841 1122 298.999 Q1119.97 300.133 1117.26 300.133 Q1112.79 300.133 1110.48 297.355 Q1108.16 294.578 1108.16 289.23 M1118.88 272.911 L1118.88 272.911 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M1160.2 283.814 L1160.2 299.462 L1155.94 299.462 L1155.94 283.953 Q1155.94 280.272 1154.5 278.443 Q1153.07 276.615 1150.2 276.615 Q1146.75 276.615 1144.76 278.814 Q1142.77 281.013 1142.77 284.809 L1142.77 299.462 L1138.49 299.462 L1138.49 273.536 L1142.77 273.536 L1142.77 277.564 Q1144.3 275.226 1146.36 274.068 Q1148.44 272.911 1151.15 272.911 Q1155.61 272.911 1157.91 275.689 Q1160.2 278.443 1160.2 283.814 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M1185.75 277.471 L1185.75 263.444 L1190.01 263.444 L1190.01 299.462 L1185.75 299.462 L1185.75 295.573 Q1184.41 297.888 1182.35 299.022 Q1180.31 300.133 1177.44 300.133 Q1172.74 300.133 1169.78 296.383 Q1166.84 292.633 1166.84 286.522 Q1166.84 280.411 1169.78 276.661 Q1172.74 272.911 1177.44 272.911 Q1180.31 272.911 1182.35 274.045 Q1184.41 275.156 1185.75 277.471 M1171.24 286.522 Q1171.24 291.221 1173.16 293.906 Q1175.11 296.568 1178.48 296.568 Q1181.86 296.568 1183.81 293.906 Q1185.75 291.221 1185.75 286.522 Q1185.75 281.823 1183.81 279.161 Q1181.86 276.476 1178.48 276.476 Q1175.11 276.476 1173.16 279.161 Q1171.24 281.823 1171.24 286.522 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M1215.31 274.3 L1215.31 278.328 Q1213.51 277.402 1211.56 276.939 Q1209.62 276.476 1207.54 276.476 Q1204.36 276.476 1202.77 277.448 Q1201.19 278.42 1201.19 280.365 Q1201.19 281.846 1202.33 282.703 Q1203.46 283.536 1206.89 284.3 L1208.35 284.624 Q1212.88 285.596 1214.78 287.379 Q1216.7 289.138 1216.7 292.309 Q1216.7 295.92 1213.83 298.027 Q1210.98 300.133 1205.98 300.133 Q1203.9 300.133 1201.63 299.716 Q1199.39 299.323 1196.89 298.513 L1196.89 294.115 Q1199.25 295.342 1201.54 295.967 Q1203.83 296.568 1206.08 296.568 Q1209.09 296.568 1210.71 295.55 Q1212.33 294.508 1212.33 292.633 Q1212.33 290.897 1211.15 289.971 Q1209.99 289.045 1206.03 288.189 L1204.55 287.842 Q1200.59 287.008 1198.83 285.295 Q1197.07 283.559 1197.07 280.55 Q1197.07 276.893 1199.67 274.902 Q1202.26 272.911 1207.03 272.911 Q1209.39 272.911 1211.47 273.258 Q1213.55 273.606 1215.31 274.3 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip130)\" d=\"M1248.6 276.522 Q1245.17 276.522 1243.18 279.207 Q1241.19 281.869 1241.19 286.522 Q1241.19 291.175 1243.16 293.86 Q1245.15 296.522 1248.6 296.522 Q1252 296.522 1253.99 293.837 Q1255.98 291.152 1255.98 286.522 Q1255.98 281.916 1253.99 279.23 Q1252 276.522 1248.6 276.522 M1248.6 272.911 Q1254.16 272.911 1257.33 276.522 Q1260.5 280.133 1260.5 286.522 Q1260.5 292.888 1257.33 296.522 Q1254.16 300.133 1248.6 300.133 Q1243.02 300.133 1239.85 296.522
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"p1 = plot( K,iv,\n",
" color = :red,\n",
" legend =false,\n",
" title = \"Implied volatility\",\n",
" xlabel = \"strike price\",\n",
" annotation = (98,0.09,text(\"Bunds options April 6, 1994\",8,:left)) )\n",
"display(p1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Mean-Variance Frontier\n",
"\n",
"Given a vector of average returns ($\\mu$) and a variance-covariance matrix ($\\Sigma$), the mean-variance frontier shows the lowest possible portfolio uncertainty for a given expected portfolio return (denoted $\\mu\\text{star}$ below).\n",
"\n",
"It is thus the solution to a quadratic minimization problem. The cells below will use the explicit (matrix) formulas for this solution, but we often have to resort to numerical methods when there are portfolio restrictions.\n",
"\n",
"It is typically plotted with the portfolio standard deviation on the horizontal axis and the portfolio expected return on the vertical axis.\n",
"\n",
"We calculate and plot two different mean-variance frontiers: (1) when we only consider risky assets; (2) when we also consider a risk-free asset."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"μ: \n",
" 0.115\n",
" 0.095\n",
" 0.060\n",
"\n",
"Σ: \n",
" 0.017 0.003 0.006\n",
" 0.003 0.006 0.000\n",
" 0.006 0.000 0.010\n",
"\n",
"Rf: \n",
" 0.030\n",
"\n"
]
}
],
"source": [
"μ = [11.5, 9.5, 6]/100 #expected returns\n",
"Σ = [166 34 58; #covariance matrix\n",
" 34 64 4;\n",
" 58 4 100]/100^2\n",
"Rf = 0.03 #riskfree return (an interest rate)\n",
"\n",
"println(\"μ: \")\n",
"printmat(μ)\n",
"println(\"Σ: \")\n",
"printmat(Σ)\n",
"println(\"Rf: \")\n",
"printmat(Rf)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"MVCalcRf"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\"\"\"\n",
" MVCalc(μstar,μ,Σ)\n",
"\n",
"Calculate the std and weights of a portfolio (with mean return μstar) on MVF of risky assets.\n",
"\n",
"# Input\n",
"- `μstar::Vector`: K vector, mean returns to calculate results for\n",
"- `μ::Vector`: n vector, mean returns\n",
"- `Σ::Matrix`: nxn, covariance matrix of returns, can contain riskfree assets\n",
"\n",
"# Output\n",
"- `StdRp::Vector`: K vector, standard deviation of mean-variance portfolio (risky only) with mean μstar\n",
"- `w_p::Matrix`: Kxn, portfolio weights of \"\"\n",
"\n",
"\"\"\"\n",
"function MVCalc(μstar,μ,Σ)\n",
"\n",
" (K,n) = (length(μstar),length(μ))\n",
"\n",
" Σ_1 = inv(Σ)\n",
" a = μ'Σ_1*μ\n",
" b = μ'Σ_1*ones(n)\n",
" c = ones(n)'Σ_1*ones(n)\n",
"\n",
" (w_p,StdRp) = (fill(NaN,K,n),fill(NaN,K))\n",
" for i = 1:K\n",
" λ = (c*μstar[i] - b)/(a*c-b^2)\n",
" δ = (a-b*μstar[i])/(a*c-b^2)\n",
" w = Σ_1 *(μ*λ.+δ)\n",
" StdRp[i] = sqrt(w'Σ*w)\n",
" w_p[i,:] = w\n",
" end\n",
"\n",
" return StdRp,w_p\n",
"\n",
"end\n",
"\n",
"\n",
"\"\"\"\n",
"Calculate the std of a portfolio (with mean μstar) on MVF of (Risky,Riskfree)\n",
"\"\"\"\n",
"function MVCalcRf(μstar,μ,Σ,Rf)\n",
"\n",
" (K,n) = (length(μstar),length(μ))\n",
"\n",
" μᵉ = μ .- Rf #expected excess returns\n",
" Σ_1 = inv(Σ)\n",
"\n",
" (w_p,StdRp) = (fill(NaN,K,n),fill(NaN,K))\n",
" for i = 1:K\n",
" w = (μstar[i]-Rf)/(μᵉ'Σ_1*μᵉ) * Σ_1*μᵉ\n",
" StdRp[i] = sqrt(w'Σ*w)\n",
" w_p[i,:] = w\n",
" end\n",
"\n",
" return StdRp,w_p\n",
"\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"μstar = range(Rf,stop=0.15,length=201)\n",
"L = length(μstar)\n",
"\n",
"StdRp = MVCalc(μstar,μ,Σ)[1] #risky assets only, [1] to get the first output\n",
"println()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"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=\"clip170\">\n",
" <rect x=\"0\" y=\"0\" width=\"1920\" height=\"1280\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip170)\" 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=\"clip171\">\n",
" <rect x=\"384\" y=\"0\" width=\"1345\" height=\"1280\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip170)\" d=\"\n",
"M197.427 1106.38 L1872.76 1106.38 L1872.76 123.472 L197.427 123.472 Z\n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<defs>\n",
" <clipPath id=\"clip172\">\n",
" <rect x=\"197\" y=\"123\" width=\"1676\" height=\"984\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<polyline clip-path=\"url(#clip172)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 197.427,1106.38 197.427,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip172)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 755.87,1106.38 755.87,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip172)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1314.31,1106.38 1314.31,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip172)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1872.76,1106.38 1872.76,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip170)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,1106.38 1872.76,1106.38 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip170)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,1106.38 197.427,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip170)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 755.87,1106.38 755.87,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip170)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1314.31,1106.38 1314.31,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip170)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1872.76,1106.38 1872.76,1094.58 \n",
" \"/>\n",
"<path clip-path=\"url(#clip170)\" d=\"M197.427 1131.73 Q193.816 1131.73 191.988 1135.3 Q190.182 1138.84 190.182 1145.97 Q190.182 1153.07 191.988 1156.64 Q193.816 1160.18 197.427 1160.18 Q201.062 1160.18 202.867 1156.64 Q204.696 1153.07 204.696 1145.97 Q204.696 1138.84 202.867 1135.3 Q201.062 1131.73 197.427 1131.73 M197.427 1128.03 Q203.238 1128.03 206.293 1132.63 Q209.372 1137.22 209.372 1145.97 Q209.372 1154.69 206.293 1159.3 Q203.238 1163.88 197.427 1163.88 Q191.617 1163.88 188.539 1159.3 Q185.483 1154.69 185.483 1145.97 Q185.483 1137.22 188.539 1132.63 Q191.617 1128.03 197.427 1128.03 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M746.148 1128.65 L764.504 1128.65 L764.504 1132.59 L750.43 1132.59 L750.43 1141.06 Q751.449 1140.71 752.468 1140.55 Q753.486 1140.36 754.505 1140.36 Q760.292 1140.36 763.671 1143.54 Q767.051 1146.71 767.051 1152.12 Q767.051 1157.7 763.579 1160.8 Q760.106 1163.88 753.787 1163.88 Q751.611 1163.88 749.343 1163.51 Q747.097 1163.14 744.69 1162.4 L744.69 1157.7 Q746.773 1158.84 748.995 1159.39 Q751.218 1159.95 753.694 1159.95 Q757.699 1159.95 760.037 1157.84 Q762.375 1155.74 762.375 1152.12 Q762.375 1148.51 760.037 1146.41 Q757.699 1144.3 753.694 1144.3 Q751.819 1144.3 749.944 1144.72 Q748.093 1145.13 746.148 1146.01 L746.148 1128.65 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M1289 1159.28 L1296.64 1159.28 L1296.64 1132.91 L1288.33 1134.58 L1288.33 1130.32 L1296.59 1128.65 L1301.27 1128.65 L1301.27 1159.28 L1308.91 1159.28 L1308.91 1163.21 L1289 1163.21 L1289 1159.28 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M1328.35 1131.73 Q1324.74 1131.73 1322.91 1135.3 Q1321.11 1138.84 1321.11 1145.97 Q1321.11 1153.07 1322.91 1156.64 Q1324.74 1160.18 1328.35 1160.18 Q1331.99 1160.18 1333.79 1156.64 Q1335.62 1153.07 1335.62 1145.97 Q1335.62 1138.84 1333.79 1135.3 Q1331.99 1131.73 1328.35 1131.73 M1328.35 1128.03 Q1334.16 1128.03 1337.22 1132.63 Q1340.3 1137.22 1340.3 1145.97 Q1340.3 1154.69 1337.22 1159.3 Q1334.16 1163.88 1328.35 1163.88 Q1322.54 1163.88 1319.46 1159.3 Q1316.41 1154.69 1316.41 1145.97 Q1316.41 1137.22 1319.46 1132.63 Q1322.54 1128.03 1328.35 1128.03 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M1847.94 1159.28 L1855.58 1159.28 L1855.58 1132.91 L1847.27 1134.58 L1847.27 1130.32 L1855.53 1128.65 L1860.21 1128.65 L1860.21 1159.28 L1867.85 1159.28 L1867.85 1163.21 L1847.94 1163.21 L1847.94 1159.28 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M1877.34 1128.65 L1895.7 1128.65 L1895.7 1132.59 L1881.62 1132.59 L1881.62 1141.06 Q1882.64 1140.71 1883.66 1140.55 Q1884.68 1140.36 1885.7 1140.36 Q1891.48 1140.36 1894.86 1143.54 Q1898.24 1146.71 1898.24 1152.12 Q1898.24 1157.7 1894.77 1160.8 Q1891.3 1163.88 1884.98 1163.88 Q1882.8 1163.88 1880.53 1163.51 Q1878.29 1163.14 1875.88 1162.4 L1875.88 1157.7 Q1877.96 1158.84 1880.19 1159.39 Q1882.41 1159.95 1884.89 1159.95 Q1888.89 1159.95 1891.23 1157.84 Q1893.57 1155.74 1893.57 1152.12 Q1893.57 1148.51 1891.23 1146.41 Q1888.89 1144.3 1884.89 1144.3 Q1883.01 1144.3 1881.14 1144.72 Q1879.28 1145.13 1877.34 1146.01 L1877.34 1128.65 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M895.014 1198.08 L895.014 1204.35 Q891.354 1202.6 888.108 1201.74 Q884.861 1200.88 881.837 1200.88 Q876.586 1200.88 873.721 1202.92 Q870.888 1204.96 870.888 1208.71 Q870.888 1211.87 872.766 1213.49 Q874.676 1215.08 879.959 1216.07 L883.842 1216.86 Q891.036 1218.23 894.441 1221.7 Q897.879 1225.14 897.879 1230.93 Q897.879 1237.84 893.232 1241.4 Q888.617 1244.97 879.673 1244.97 Q876.299 1244.97 872.48 1244.2 Q868.692 1243.44 864.618 1241.94 L864.618 1235.32 Q868.533 1237.52 872.289 1238.63 Q876.045 1239.75 879.673 1239.75 Q885.179 1239.75 888.171 1237.58 Q891.163 1235.42 891.163 1231.41 Q891.163 1227.91 888.999 1225.93 Q886.866 1223.96 881.965 1222.
" 197.427,1106.38 1872.76,1106.38 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip172)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 197.427,778.744 1872.76,778.744 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip172)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 197.427,451.108 1872.76,451.108 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip172)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 197.427,123.472 1872.76,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip170)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,1106.38 197.427,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip170)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,1106.38 217.531,1106.38 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip170)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,778.744 217.531,778.744 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip170)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,451.108 217.531,451.108 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip170)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,123.472 217.531,123.472 \n",
" \"/>\n",
"<path clip-path=\"url(#clip170)\" d=\"M156.683 1092.18 Q153.072 1092.18 151.243 1095.74 Q149.438 1099.28 149.438 1106.41 Q149.438 1113.52 151.243 1117.09 Q153.072 1120.63 156.683 1120.63 Q160.317 1120.63 162.123 1117.09 Q163.952 1113.52 163.952 1106.41 Q163.952 1099.28 162.123 1095.74 Q160.317 1092.18 156.683 1092.18 M156.683 1088.47 Q162.493 1088.47 165.549 1093.08 Q168.627 1097.66 168.627 1106.41 Q168.627 1115.14 165.549 1119.75 Q162.493 1124.33 156.683 1124.33 Q150.873 1124.33 147.794 1119.75 Q144.739 1115.14 144.739 1106.41 Q144.739 1097.66 147.794 1093.08 Q150.873 1088.47 156.683 1088.47 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M147.725 761.464 L166.081 761.464 L166.081 765.399 L152.007 765.399 L152.007 773.871 Q153.026 773.524 154.044 773.362 Q155.063 773.177 156.081 773.177 Q161.868 773.177 165.248 776.348 Q168.627 779.519 168.627 784.936 Q168.627 790.515 165.155 793.617 Q161.683 796.695 155.364 796.695 Q153.188 796.695 150.919 796.325 Q148.674 795.954 146.266 795.214 L146.266 790.515 Q148.35 791.649 150.572 792.205 Q152.794 792.76 155.271 792.76 Q159.276 792.76 161.614 790.654 Q163.952 788.547 163.952 784.936 Q163.952 781.325 161.614 779.218 Q159.276 777.112 155.271 777.112 Q153.396 777.112 151.521 777.529 Q149.669 777.945 147.725 778.825 L147.725 761.464 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M117.331 464.453 L124.97 464.453 L124.97 438.087 L116.66 439.754 L116.66 435.495 L124.924 433.828 L129.6 433.828 L129.6 464.453 L137.239 464.453 L137.239 468.388 L117.331 468.388 L117.331 464.453 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M156.683 436.907 Q153.072 436.907 151.243 440.472 Q149.438 444.013 149.438 451.143 Q149.438 458.249 151.243 461.814 Q153.072 465.356 156.683 465.356 Q160.317 465.356 162.123 461.814 Q163.952 458.249 163.952 451.143 Q163.952 444.013 162.123 440.472 Q160.317 436.907 156.683 436.907 M156.683 433.203 Q162.493 433.203 165.549 437.809 Q168.627 442.393 168.627 451.143 Q168.627 459.87 165.549 464.476 Q162.493 469.059 156.683 469.059 Q150.873 469.059 147.794 464.476 Q144.739 459.87 144.739 451.143 Q144.739 442.393 147.794 437.809 Q150.873 433.203 156.683 433.203 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M118.327 136.817 L125.966 136.817 L125.966 110.451 L117.656 112.118 L117.656 107.859 L125.919 106.192 L130.595 106.192 L130.595 136.817 L138.234 136.817 L138.234 140.752 L118.327 140.752 L118.327 136.817 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M147.725 106.192 L166.081 106.192 L166.081 110.127 L152.007 110.127 L152.007 118.599 Q153.026 118.252 154.044 118.09 Q155.063 117.905 156.081 117.905 Q161.868 117.905 165.248 121.076 Q168.627 124.248 168.627 129.664 Q168.627 135.243 165.155 138.345 Q161.683 141.423 155.364 141.423 Q153.188 141.423 150.919 141.053 Q148.674 140.683 146.266 139.942 L146.266 135.243 Q148.35 136.377 150.572 136.933 Q152.794 137.488 155.271 137.488 Q159.276 137.488 161.614 135.382 Q163.952 133.275 163.952 129.664 Q163.952 126.053 161.614 123.947 Q159.276 121.84 155.271 121.84 Q153.396 121.84 151.521 122.257 Q149.669 122.674 147.725 123.553 L147.725 106.192 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M26.0842 725.546 L26.0842 695.5 L31.495 695.5 L31.495 719.117 L45.5632 719.117 L45.5632 696.487 L50.9741 696.487 L50.9741 719.117 L68.1933 719.117 L68.1933 694.927 L73.6042 694.927 L73.6042 725.546 L26.0842 725.546 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M51.3242 661.825 Q52.0244 659.756 54.3161 657.815 Q56.6077 655.842 60.6181 653.868 L73.6042 647.343 L73.6042 654.25 L61.4138 660.329 Q56.6395 662.685 55.08 664.913 Q53.5204 667.109 53.5204 670.928 L53.5204 677.931 L73.6042 677.931 L73.6042 684.36 L26.0842 684.36 L26.0842 669.846 Q26.0842 661.698 29.4898 657.688
" 1631.87,909.798 1619.14,905.867 1606.44,901.935 1593.79,898.003 1581.18,894.072 1568.6,890.14 1556.07,886.209 1543.59,882.277 1531.15,878.345 1518.75,874.414 \n",
" 1506.41,870.482 1494.11,866.55 1481.87,862.619 1469.67,858.687 1457.53,854.755 1445.44,850.824 1433.42,846.892 1421.44,842.961 1409.53,839.029 1397.69,835.097 \n",
" 1385.9,831.166 1374.18,827.234 1362.53,823.302 1350.95,819.371 1339.44,815.439 1328,811.508 1316.64,807.576 1305.36,803.644 1294.16,799.713 1283.04,795.781 \n",
" 1272.01,791.849 1261.07,787.918 1250.22,783.986 1239.47,780.054 1228.81,776.123 1218.25,772.191 1207.8,768.26 1197.45,764.328 1187.21,760.396 1177.09,756.465 \n",
" 1167.08,752.533 1157.2,748.601 1147.44,744.67 1137.81,740.738 1128.31,736.807 1118.94,732.875 1109.72,728.943 1100.64,725.012 1091.72,721.08 1082.94,717.148 \n",
" 1074.33,713.217 1065.88,709.285 1057.6,705.353 1049.49,701.422 1041.56,697.49 1033.81,693.559 1026.25,689.627 1018.88,685.695 1011.72,681.764 1004.75,677.832 \n",
" 998.001,673.9 991.462,669.969 985.144,666.037 979.051,662.106 973.189,658.174 967.563,654.242 962.179,650.311 957.04,646.379 952.154,642.447 947.523,638.516 \n",
" 943.154,634.584 939.05,630.653 935.217,626.721 931.658,622.789 928.378,618.858 925.38,614.926 922.667,610.994 920.244,607.063 918.112,603.131 916.275,599.199 \n",
" 914.734,595.268 913.492,591.336 912.55,587.405 911.91,583.473 911.572,579.541 911.536,575.61 911.803,571.678 912.372,567.746 913.243,563.815 914.414,559.883 \n",
" 915.885,555.952 917.652,552.02 919.715,548.088 922.07,544.157 924.714,540.225 927.645,536.293 930.859,532.362 934.353,528.43 938.122,524.498 942.162,520.567 \n",
" 946.469,516.635 951.038,512.704 955.865,508.772 960.944,504.84 966.271,500.909 971.841,496.977 977.648,493.045 983.687,489.114 989.952,485.182 996.439,481.251 \n",
" 1003.14,477.319 1010.06,473.387 1017.18,469.456 1024.5,465.524 1032.01,461.592 1039.71,457.661 1047.6,453.729 1055.67,449.797 1063.91,445.866 1072.32,441.934 \n",
" 1080.9,438.003 1089.63,434.071 1098.53,430.139 1107.57,426.208 1116.76,422.276 1126.09,418.344 1135.55,414.413 1145.15,410.481 1154.88,406.55 1164.74,402.618 \n",
" 1174.72,398.686 1184.81,394.755 1195.02,390.823 1205.35,386.891 1215.77,382.96 1226.31,379.028 1236.94,375.097 1247.68,371.165 1258.5,367.233 1269.42,363.302 \n",
" 1280.43,359.37 1291.53,355.438 1302.71,351.507 1313.97,347.575 1325.32,343.643 1336.73,339.712 1348.23,335.78 1359.79,331.849 1371.43,327.917 1383.13,323.985 \n",
" 1394.9,320.054 1406.73,316.122 1418.63,312.19 1430.59,308.259 1442.6,304.327 1454.67,300.396 1466.8,296.464 1478.98,292.532 1491.22,288.601 1503.5,284.669 \n",
" 1515.84,280.737 1528.22,276.806 1540.65,272.874 1553.13,268.942 1565.65,265.011 1578.21,261.079 1590.81,257.148 1603.46,253.216 1616.14,249.284 1628.86,245.353 \n",
" 1641.63,241.421 1654.42,237.489 1667.26,233.558 1680.12,229.626 1693.02,225.695 1705.96,221.763 1718.93,217.831 1731.92,213.9 1744.95,209.968 1758.01,206.036 \n",
" 1771.1,202.105 1784.21,198.173 1797.36,194.241 1810.53,190.31 1823.72,186.378 1836.94,182.447 1850.19,178.515 1863.46,174.583 1876.76,170.652 1890.08,166.72 \n",
" 1903.42,162.788 1916.78,158.857 1930.16,154.925 1943.57,150.994 1957,147.062 1970.44,143.13 1983.91,139.199 1997.4,135.267 2010.9,131.335 2024.43,127.404 \n",
" 2037.97,123.472 \n",
" \"/>\n",
"<circle clip-path=\"url(#clip172)\" cx=\"1636.43\" cy=\"352.817\" r=\"14\" fill=\"#ff0000\" fill-rule=\"evenodd\" fill-opacity=\"1\" stroke=\"#000000\" stroke-opacity=\"1\" stroke-width=\"2.56\"/>\n",
"<circle clip-path=\"url(#clip172)\" cx=\"1090.94\" cy=\"483.872\" r=\"14\" fill=\"#ff0000\" fill-rule=\"evenodd\" fill-opacity=\"1\" stroke=\"#000000\" stroke-opacity=\"1\" stroke-width=\"2.56\"/>\n",
"<circle clip-path=\"url(#clip172)\" cx=\"1314.31\" cy=\"713.217\" r=\"14\" fill=\"#ff0000\" fill-rule=\"evenodd\" fill-opacity=\"1\" stroke=\"#000000\" stroke-opacity=\"1\" stroke-width=\"2.56\"/>\n",
"<path clip-path=\"url(#clip170)\" d=\"\n",
"M253.272 337.676 L585.159 337.676 L585.159 156.236 L253.272 156.236 Z\n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip170)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 253.272,337.676 585.159,337.676 585.159,156.236 253.272,156.236 253.272,337.676 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip170)\" style=\"stroke:#ff0000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 271.887,216.716 383.575,216.716 \n",
" \"/>\n",
"<path clip-path=\"url(#clip170)\" d=\"M402.19 199.436 L409.157 199.436 L417.977 222.954 L426.842 199.436 L433.81 199.436 L433.81 233.996 L429.25 233.996 L429.25 203.649 L420.338 227.352 L415.639 227.352 L406.727 203.649 L406.727 233.996 L402.19 233.996 L402.19 199.436 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M452.004 233.996 L438.81 199.436 L443.694 199.436 L454.643 228.533 L465.615 199.436 L470.477 199.436 L457.305 233.996 L452.004 233.996 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M475.523 199.436 L495.384 199.436 L495.384 203.371 L480.199 203.371 L480.199 213.556 L493.902 213.556 L493.902 217.491 L480.199 217.491 L480.199 233.996 L475.523 233.996 L475.523 199.436 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><circle clip-path=\"url(#clip170)\" cx=\"327.731\" cy=\"277.196\" r=\"23\" fill=\"#ff0000\" fill-rule=\"evenodd\" fill-opacity=\"1\" stroke=\"#000000\" stroke-opacity=\"1\" stroke-width=\"4.096\"/>\n",
"<path clip-path=\"url(#clip170)\" d=\"M415.593 281.443 Q410.431 281.443 408.44 282.624 Q406.449 283.804 406.449 286.652 Q406.449 288.92 407.931 290.263 Q409.435 291.582 412.005 291.582 Q415.546 291.582 417.676 289.082 Q419.829 286.559 419.829 282.392 L419.829 281.443 L415.593 281.443 M424.088 279.684 L424.088 294.476 L419.829 294.476 L419.829 290.541 Q418.37 292.902 416.194 294.036 Q414.018 295.147 410.87 295.147 Q406.889 295.147 404.528 292.925 Q402.19 290.679 402.19 286.929 Q402.19 282.554 405.106 280.332 Q408.046 278.11 413.856 278.11 L419.829 278.11 L419.829 277.693 Q419.829 274.754 417.884 273.156 Q415.963 271.536 412.468 271.536 Q410.245 271.536 408.139 272.068 Q406.032 272.601 404.088 273.666 L404.088 269.73 Q406.426 268.828 408.625 268.388 Q410.824 267.925 412.907 267.925 Q418.532 267.925 421.31 270.842 Q424.088 273.758 424.088 279.684 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M449.389 269.314 L449.389 273.342 Q447.583 272.416 445.639 271.953 Q443.694 271.49 441.611 271.49 Q438.44 271.49 436.842 272.462 Q435.268 273.434 435.268 275.379 Q435.268 276.86 436.403 277.717 Q437.537 278.55 440.963 279.314 L442.421 279.638 Q446.958 280.61 448.856 282.392 Q450.778 284.152 450.778 287.323 Q450.778 290.934 447.907 293.041 Q445.06 295.147 440.06 295.147 Q437.977 295.147 435.708 294.73 Q433.463 294.337 430.963 293.527 L430.963 289.129 Q433.324 290.355 435.616 290.98 Q437.907 291.582 440.153 291.582 Q443.162 291.582 444.782 290.564 Q446.403 289.522 446.403 287.647 Q446.403 285.911 445.222 284.985 Q444.065 284.059 440.106 283.203 L438.625 282.855 Q434.667 282.022 432.907 280.309 Q431.148 278.573 431.148 275.564 Q431.148 271.906 433.741 269.916 Q436.333 267.925 441.102 267.925 Q443.463 267.925 445.546 268.272 Q447.629 268.619 449.389 269.314 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M474.088 269.314 L474.088 273.342 Q472.282 272.416 470.338 271.953 Q468.393 271.49 466.31 271.49 Q463.139 271.49 461.541 272.462 Q459.967 273.434 459.967 275.379 Q459.967 276.86 461.102 277.717 Q462.236 278.55 465.662 279.314 L467.12 279.638 Q471.657 280.61 473.555 282.392 Q475.476 284.152 475.476 287.323 Q475.476 290.934 472.606 293.041 Q469.759 295.147 464.759 295.147 Q462.676 295.147 460.407 294.73 Q458.162 294.337 455.662 293.527 L455.662 289.129 Q458.023 290.355 460.315 290.98 Q462.606 291.582 464.852 291.582 Q467.861 291.582 469.481 290.564 Q471.102 289.522 471.102 287.647 Q471.102 285.911 469.921 284.985 Q468.764 284.059 464.805 283.203 L463.324 282.855 Q459.365 282.022 457.606 280.309 Q455.847 278.573 455.847 275.564 Q455.847 271.906 458.44 269.916 Q461.032 267.925 465.801 267.925 Q468.162 267.925 470.245 268.272 Q472.328 268.619 474.088 269.314 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M504.435 280.448 L504.435 282.531 L484.851 282.531 Q485.129 286.929 487.49 289.244 Q489.875 291.536 494.111 291.536 Q496.564 291.536 498.856 290.934 Q501.171 290.332 503.439 289.129 L503.439 293.156 Q501.148 294.128 498.74 294.638 Q496.333 295.147 493.856 295.147 Q487.652 295.147 484.018 291.536 Q480.407 287.925 480.407 281.767 Q480.407 275.402 483.833 271.675 Q487.282 267.925 493.115 267.925 Q498.347 267.925 501.379 271.305 Q504.435 274.661 504.435 280.448 M500.175 279.198 Q500.129 275.703 498.208 273.619 Q496.31 271.536 493.162 271.536 Q489.597 271.536 487.444 273.55 Q485.314 275.564 484.99 279.221 L500.175 279.198 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip170)\" d=\"M515.638 261.189 L515.638 268.55 L524.411 268.55 L524.411 271.86 L515.638 271.86 L515.638 285.934 Q515.638 289.105 516.495 290.008 Q517.374 290.911 520.036 290.911 L524.411 290.911 L524.411 294.476 L520.036 294.476 Q515.106 294.476 513.231 292.647 Q511.356 290.795 511.356 285.934 L511.356 271.86 L508.231 271.86 L508.231 268.55 L511.356 268.55 L511.356 261.189 L515.638 261.189 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"p1 = plot( StdRp*100,μstar*100,\n",
" linecolor = :red,\n",
" xlim = (0,15),\n",
" ylim = (0,15),\n",
" label = \"MVF\",\n",
" legend = :topleft,\n",
" title = \"MVF, only risky assets\",\n",
" xlabel = \"Std(Rp), %\",\n",
" ylabel = \"ERp, %\" )\n",
"scatter!(sqrt.(diag(Σ))*100,μ*100,color=:red,label=\"assets\")\n",
"display(p1)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"StdRpRf = MVCalcRf(μstar,μ,Σ,Rf)[1] #with riskfree too\n",
"println()"
]
},
{
"cell_type": "code",
"execution_count": 21,
"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=\"clip210\">\n",
" <rect x=\"0\" y=\"0\" width=\"1920\" height=\"1280\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip210)\" 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=\"clip211\">\n",
" <rect x=\"384\" y=\"0\" width=\"1345\" height=\"1280\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip210)\" d=\"\n",
"M197.427 1106.38 L1872.76 1106.38 L1872.76 123.472 L197.427 123.472 Z\n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<defs>\n",
" <clipPath id=\"clip212\">\n",
" <rect x=\"197\" y=\"123\" width=\"1676\" height=\"984\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<polyline clip-path=\"url(#clip212)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 197.427,1106.38 197.427,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip212)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 755.87,1106.38 755.87,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip212)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1314.31,1106.38 1314.31,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip212)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1872.76,1106.38 1872.76,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,1106.38 1872.76,1106.38 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,1106.38 197.427,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 755.87,1106.38 755.87,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1314.31,1106.38 1314.31,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1872.76,1106.38 1872.76,1094.58 \n",
" \"/>\n",
"<path clip-path=\"url(#clip210)\" d=\"M197.427 1131.73 Q193.816 1131.73 191.988 1135.3 Q190.182 1138.84 190.182 1145.97 Q190.182 1153.07 191.988 1156.64 Q193.816 1160.18 197.427 1160.18 Q201.062 1160.18 202.867 1156.64 Q204.696 1153.07 204.696 1145.97 Q204.696 1138.84 202.867 1135.3 Q201.062 1131.73 197.427 1131.73 M197.427 1128.03 Q203.238 1128.03 206.293 1132.63 Q209.372 1137.22 209.372 1145.97 Q209.372 1154.69 206.293 1159.3 Q203.238 1163.88 197.427 1163.88 Q191.617 1163.88 188.539 1159.3 Q185.483 1154.69 185.483 1145.97 Q185.483 1137.22 188.539 1132.63 Q191.617 1128.03 197.427 1128.03 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M746.148 1128.65 L764.504 1128.65 L764.504 1132.59 L750.43 1132.59 L750.43 1141.06 Q751.449 1140.71 752.468 1140.55 Q753.486 1140.36 754.505 1140.36 Q760.292 1140.36 763.671 1143.54 Q767.051 1146.71 767.051 1152.12 Q767.051 1157.7 763.579 1160.8 Q760.106 1163.88 753.787 1163.88 Q751.611 1163.88 749.343 1163.51 Q747.097 1163.14 744.69 1162.4 L744.69 1157.7 Q746.773 1158.84 748.995 1159.39 Q751.218 1159.95 753.694 1159.95 Q757.699 1159.95 760.037 1157.84 Q762.375 1155.74 762.375 1152.12 Q762.375 1148.51 760.037 1146.41 Q757.699 1144.3 753.694 1144.3 Q751.819 1144.3 749.944 1144.72 Q748.093 1145.13 746.148 1146.01 L746.148 1128.65 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1289 1159.28 L1296.64 1159.28 L1296.64 1132.91 L1288.33 1134.58 L1288.33 1130.32 L1296.59 1128.65 L1301.27 1128.65 L1301.27 1159.28 L1308.91 1159.28 L1308.91 1163.21 L1289 1163.21 L1289 1159.28 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1328.35 1131.73 Q1324.74 1131.73 1322.91 1135.3 Q1321.11 1138.84 1321.11 1145.97 Q1321.11 1153.07 1322.91 1156.64 Q1324.74 1160.18 1328.35 1160.18 Q1331.99 1160.18 1333.79 1156.64 Q1335.62 1153.07 1335.62 1145.97 Q1335.62 1138.84 1333.79 1135.3 Q1331.99 1131.73 1328.35 1131.73 M1328.35 1128.03 Q1334.16 1128.03 1337.22 1132.63 Q1340.3 1137.22 1340.3 1145.97 Q1340.3 1154.69 1337.22 1159.3 Q1334.16 1163.88 1328.35 1163.88 Q1322.54 1163.88 1319.46 1159.3 Q1316.41 1154.69 1316.41 1145.97 Q1316.41 1137.22 1319.46 1132.63 Q1322.54 1128.03 1328.35 1128.03 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1847.94 1159.28 L1855.58 1159.28 L1855.58 1132.91 L1847.27 1134.58 L1847.27 1130.32 L1855.53 1128.65 L1860.21 1128.65 L1860.21 1159.28 L1867.85 1159.28 L1867.85 1163.21 L1847.94 1163.21 L1847.94 1159.28 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1877.34 1128.65 L1895.7 1128.65 L1895.7 1132.59 L1881.62 1132.59 L1881.62 1141.06 Q1882.64 1140.71 1883.66 1140.55 Q1884.68 1140.36 1885.7 1140.36 Q1891.48 1140.36 1894.86 1143.54 Q1898.24 1146.71 1898.24 1152.12 Q1898.24 1157.7 1894.77 1160.8 Q1891.3 1163.88 1884.98 1163.88 Q1882.8 1163.88 1880.53 1163.51 Q1878.29 1163.14 1875.88 1162.4 L1875.88 1157.7 Q1877.96 1158.84 1880.19 1159.39 Q1882.41 1159.95 1884.89 1159.95 Q1888.89 1159.95 1891.23 1157.84 Q1893.57 1155.74 1893.57 1152.12 Q1893.57 1148.51 1891.23 1146.41 Q1888.89 1144.3 1884.89 1144.3 Q1883.01 1144.3 1881.14 1144.72 Q1879.28 1145.13 1877.34 1146.01 L1877.34 1128.65 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M895.014 1198.08 L895.014 1204.35 Q891.354 1202.6 888.108 1201.74 Q884.861 1200.88 881.837 1200.88 Q876.586 1200.88 873.721 1202.92 Q870.888 1204.96 870.888 1208.71 Q870.888 1211.87 872.766 1213.49 Q874.676 1215.08 879.959 1216.07 L883.842 1216.86 Q891.036 1218.23 894.441 1221.7 Q897.879 1225.14 897.879 1230.93 Q897.879 1237.84 893.232 1241.4 Q888.617 1244.97 879.673 1244.97 Q876.299 1244.97 872.48 1244.2 Q868.692 1243.44 864.618 1241.94 L864.618 1235.32 Q868.533 1237.52 872.289 1238.63 Q876.045 1239.75 879.673 1239.75 Q885.179 1239.75 888.171 1237.58 Q891.163 1235.42 891.163 1231.41 Q891.163 1227.91 888.999 1225.93 Q886.866 1223.96 881.965 1222.
" 197.427,1106.38 1872.76,1106.38 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip212)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 197.427,778.744 1872.76,778.744 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip212)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 197.427,451.108 1872.76,451.108 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip212)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 197.427,123.472 1872.76,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,1106.38 197.427,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,1106.38 217.531,1106.38 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,778.744 217.531,778.744 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,451.108 217.531,451.108 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,123.472 217.531,123.472 \n",
" \"/>\n",
"<path clip-path=\"url(#clip210)\" d=\"M156.683 1092.18 Q153.072 1092.18 151.243 1095.74 Q149.438 1099.28 149.438 1106.41 Q149.438 1113.52 151.243 1117.09 Q153.072 1120.63 156.683 1120.63 Q160.317 1120.63 162.123 1117.09 Q163.952 1113.52 163.952 1106.41 Q163.952 1099.28 162.123 1095.74 Q160.317 1092.18 156.683 1092.18 M156.683 1088.47 Q162.493 1088.47 165.549 1093.08 Q168.627 1097.66 168.627 1106.41 Q168.627 1115.14 165.549 1119.75 Q162.493 1124.33 156.683 1124.33 Q150.873 1124.33 147.794 1119.75 Q144.739 1115.14 144.739 1106.41 Q144.739 1097.66 147.794 1093.08 Q150.873 1088.47 156.683 1088.47 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M147.725 761.464 L166.081 761.464 L166.081 765.399 L152.007 765.399 L152.007 773.871 Q153.026 773.524 154.044 773.362 Q155.063 773.177 156.081 773.177 Q161.868 773.177 165.248 776.348 Q168.627 779.519 168.627 784.936 Q168.627 790.515 165.155 793.617 Q161.683 796.695 155.364 796.695 Q153.188 796.695 150.919 796.325 Q148.674 795.954 146.266 795.214 L146.266 790.515 Q148.35 791.649 150.572 792.205 Q152.794 792.76 155.271 792.76 Q159.276 792.76 161.614 790.654 Q163.952 788.547 163.952 784.936 Q163.952 781.325 161.614 779.218 Q159.276 777.112 155.271 777.112 Q153.396 777.112 151.521 777.529 Q149.669 777.945 147.725 778.825 L147.725 761.464 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M117.331 464.453 L124.97 464.453 L124.97 438.087 L116.66 439.754 L116.66 435.495 L124.924 433.828 L129.6 433.828 L129.6 464.453 L137.239 464.453 L137.239 468.388 L117.331 468.388 L117.331 464.453 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M156.683 436.907 Q153.072 436.907 151.243 440.472 Q149.438 444.013 149.438 451.143 Q149.438 458.249 151.243 461.814 Q153.072 465.356 156.683 465.356 Q160.317 465.356 162.123 461.814 Q163.952 458.249 163.952 451.143 Q163.952 444.013 162.123 440.472 Q160.317 436.907 156.683 436.907 M156.683 433.203 Q162.493 433.203 165.549 437.809 Q168.627 442.393 168.627 451.143 Q168.627 459.87 165.549 464.476 Q162.493 469.059 156.683 469.059 Q150.873 469.059 147.794 464.476 Q144.739 459.87 144.739 451.143 Q144.739 442.393 147.794 437.809 Q150.873 433.203 156.683 433.203 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M118.327 136.817 L125.966 136.817 L125.966 110.451 L117.656 112.118 L117.656 107.859 L125.919 106.192 L130.595 106.192 L130.595 136.817 L138.234 136.817 L138.234 140.752 L118.327 140.752 L118.327 136.817 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M147.725 106.192 L166.081 106.192 L166.081 110.127 L152.007 110.127 L152.007 118.599 Q153.026 118.252 154.044 118.09 Q155.063 117.905 156.081 117.905 Q161.868 117.905 165.248 121.076 Q168.627 124.248 168.627 129.664 Q168.627 135.243 165.155 138.345 Q161.683 141.423 155.364 141.423 Q153.188 141.423 150.919 141.053 Q148.674 140.683 146.266 139.942 L146.266 135.243 Q148.35 136.377 150.572 136.933 Q152.794 137.488 155.271 137.488 Q159.276 137.488 161.614 135.382 Q163.952 133.275 163.952 129.664 Q163.952 126.053 161.614 123.947 Q159.276 121.84 155.271 121.84 Q153.396 121.84 151.521 122.257 Q149.669 122.674 147.725 123.553 L147.725 106.192 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M26.0842 725.546 L26.0842 695.5 L31.495 695.5 L31.495 719.117 L45.5632 719.117 L45.5632 696.487 L50.9741 696.487 L50.9741 719.117 L68.1933 719.117 L68.1933 694.927 L73.6042 694.927 L73.6042 725.546 L26.0842 725.546 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M51.3242 661.825 Q52.0244 659.756 54.3161 657.815 Q56.6077 655.842 60.6181 653.868 L73.6042 647.343 L73.6042 654.25 L61.4138 660.329 Q56.6395 662.685 55.08 664.913 Q53.5204 667.109 53.5204 670.928 L53.5204 677.931 L73.6042 677.931 L73.6042 684.36 L26.0842 684.36 L26.0842 669.846 Q26.0842 661.698 29.4898 657.688
" 1631.87,909.798 1619.14,905.867 1606.44,901.935 1593.79,898.003 1581.18,894.072 1568.6,890.14 1556.07,886.209 1543.59,882.277 1531.15,878.345 1518.75,874.414 \n",
" 1506.41,870.482 1494.11,866.55 1481.87,862.619 1469.67,858.687 1457.53,854.755 1445.44,850.824 1433.42,846.892 1421.44,842.961 1409.53,839.029 1397.69,835.097 \n",
" 1385.9,831.166 1374.18,827.234 1362.53,823.302 1350.95,819.371 1339.44,815.439 1328,811.508 1316.64,807.576 1305.36,803.644 1294.16,799.713 1283.04,795.781 \n",
" 1272.01,791.849 1261.07,787.918 1250.22,783.986 1239.47,780.054 1228.81,776.123 1218.25,772.191 1207.8,768.26 1197.45,764.328 1187.21,760.396 1177.09,756.465 \n",
" 1167.08,752.533 1157.2,748.601 1147.44,744.67 1137.81,740.738 1128.31,736.807 1118.94,732.875 1109.72,728.943 1100.64,725.012 1091.72,721.08 1082.94,717.148 \n",
" 1074.33,713.217 1065.88,709.285 1057.6,705.353 1049.49,701.422 1041.56,697.49 1033.81,693.559 1026.25,689.627 1018.88,685.695 1011.72,681.764 1004.75,677.832 \n",
" 998.001,673.9 991.462,669.969 985.144,666.037 979.051,662.106 973.189,658.174 967.563,654.242 962.179,650.311 957.04,646.379 952.154,642.447 947.523,638.516 \n",
" 943.154,634.584 939.05,630.653 935.217,626.721 931.658,622.789 928.378,618.858 925.38,614.926 922.667,610.994 920.244,607.063 918.112,603.131 916.275,599.199 \n",
" 914.734,595.268 913.492,591.336 912.55,587.405 911.91,583.473 911.572,579.541 911.536,575.61 911.803,571.678 912.372,567.746 913.243,563.815 914.414,559.883 \n",
" 915.885,555.952 917.652,552.02 919.715,548.088 922.07,544.157 924.714,540.225 927.645,536.293 930.859,532.362 934.353,528.43 938.122,524.498 942.162,520.567 \n",
" 946.469,516.635 951.038,512.704 955.865,508.772 960.944,504.84 966.271,500.909 971.841,496.977 977.648,493.045 983.687,489.114 989.952,485.182 996.439,481.251 \n",
" 1003.14,477.319 1010.06,473.387 1017.18,469.456 1024.5,465.524 1032.01,461.592 1039.71,457.661 1047.6,453.729 1055.67,449.797 1063.91,445.866 1072.32,441.934 \n",
" 1080.9,438.003 1089.63,434.071 1098.53,430.139 1107.57,426.208 1116.76,422.276 1126.09,418.344 1135.55,414.413 1145.15,410.481 1154.88,406.55 1164.74,402.618 \n",
" 1174.72,398.686 1184.81,394.755 1195.02,390.823 1205.35,386.891 1215.77,382.96 1226.31,379.028 1236.94,375.097 1247.68,371.165 1258.5,367.233 1269.42,363.302 \n",
" 1280.43,359.37 1291.53,355.438 1302.71,351.507 1313.97,347.575 1325.32,343.643 1336.73,339.712 1348.23,335.78 1359.79,331.849 1371.43,327.917 1383.13,323.985 \n",
" 1394.9,320.054 1406.73,316.122 1418.63,312.19 1430.59,308.259 1442.6,304.327 1454.67,300.396 1466.8,296.464 1478.98,292.532 1491.22,288.601 1503.5,284.669 \n",
" 1515.84,280.737 1528.22,276.806 1540.65,272.874 1553.13,268.942 1565.65,265.011 1578.21,261.079 1590.81,257.148 1603.46,253.216 1616.14,249.284 1628.86,245.353 \n",
" 1641.63,241.421 1654.42,237.489 1667.26,233.558 1680.12,229.626 1693.02,225.695 1705.96,221.763 1718.93,217.831 1731.92,213.9 1744.95,209.968 1758.01,206.036 \n",
" 1771.1,202.105 1784.21,198.173 1797.36,194.241 1810.53,190.31 1823.72,186.378 1836.94,182.447 1850.19,178.515 1863.46,174.583 1876.76,170.652 1890.08,166.72 \n",
" 1903.42,162.788 1916.78,158.857 1930.16,154.925 1943.57,150.994 1957,147.062 1970.44,143.13 1983.91,139.199 1997.4,135.267 2010.9,131.335 2024.43,127.404 \n",
" 2037.97,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip212)\" style=\"stroke:#0000ff; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" stroke-dasharray=\"16, 10\" points=\"\n",
" 197.427,909.798 204.746,905.867 212.065,901.935 219.384,898.003 226.703,894.072 234.022,890.14 241.341,886.209 248.66,882.277 255.979,878.345 263.298,874.414 \n",
" 270.617,870.482 277.936,866.55 285.255,862.619 292.574,858.687 299.893,854.755 307.212,850.824 314.531,846.892 321.85,842.961 329.169,839.029 336.488,835.097 \n",
" 343.807,831.166 351.126,827.234 358.445,823.302 365.764,819.371 373.083,815.439 380.402,811.508 387.721,807.576 395.039,803.644 402.358,799.713 409.677,795.781 \n",
" 416.996,791.849 424.315,787.918 431.634,783.986 438.953,780.054 446.272,776.123 453.591,772.191 460.91,768.26 468.229,764.328 475.548,760.396 482.867,756.465 \n",
" 490.186,752.533 497.505,748.601 504.824,744.67 512.143,740.738 519.462,736.807 526.781,732.875 534.1,728.943 541.419,725.012 548.738,721.08 556.057,717.148 \n",
" 563.376,713.217 570.695,709.285 578.014,705.353 585.332,701.422 592.651,697.49 599.97,693.559 607.289,689.627 614.608,685.695 621.927,681.764 629.246,677.832 \n",
" 636.565,673.9 643.884,669.969 651.203,666.037 658.522,662.106 665.841,658.174 673.16,654.242 680.479,650.311 687.798,646.379 695.117,642.447 702.436,638.516 \n",
" 709.755,634.584 717.074,630.653 724.393,626.721 731.712,622.789 739.031,618.858 746.35,614.926 753.669,610.994 760.988,607.063 768.307,603.131 775.626,599.199 \n",
" 782.944,595.268 790.263,591.336 797.582,587.405 804.901,583.473 812.22,579.541 819.539,575.61 826.858,571.678 834.177,567.746 841.496,563.815 848.815,559.883 \n",
" 856.134,555.952 863.453,552.02 870.772,548.088 878.091,544.157 885.41,540.225 892.729,536.293 900.048,532.362 907.367,528.43 914.686,524.498 922.005,520.567 \n",
" 929.324,516.635 936.643,512.704 943.962,508.772 951.281,504.84 958.6,500.909 965.919,496.977 973.238,493.045 980.556,489.114 987.875,485.182 995.194,481.251 \n",
" 1002.51,477.319 1009.83,473.387 1017.15,469.456 1024.47,465.524 1031.79,461.592 1039.11,457.661 1046.43,453.729 1053.75,449.797 1061.07,445.866 1068.38,441.934 \n",
" 1075.7,438.003 1083.02,434.071 1090.34,430.139 1097.66,426.208 1104.98,422.276 1112.3,418.344 1119.62,414.413 1126.94,410.481 1134.25,406.55 1141.57,402.618 \n",
" 1148.89,398.686 1156.21,394.755 1163.53,390.823 1170.85,386.891 1178.17,382.96 1185.49,379.028 1192.81,375.097 1200.13,371.165 1207.44,367.233 1214.76,363.302 \n",
" 1222.08,359.37 1229.4,355.438 1236.72,351.507 1244.04,347.575 1251.36,343.643 1258.68,339.712 1266,335.78 1273.31,331.849 1280.63,327.917 1287.95,323.985 \n",
" 1295.27,320.054 1302.59,316.122 1309.91,312.19 1317.23,308.259 1324.55,304.327 1331.87,300.396 1339.19,296.464 1346.5,292.532 1353.82,288.601 1361.14,284.669 \n",
" 1368.46,280.737 1375.78,276.806 1383.1,272.874 1390.42,268.942 1397.74,265.011 1405.06,261.079 1412.38,257.148 1419.69,253.216 1427.01,249.284 1434.33,245.353 \n",
" 1441.65,241.421 1448.97,237.489 1456.29,233.558 1463.61,229.626 1470.93,225.695 1478.25,221.763 1485.56,217.831 1492.88,213.9 1500.2,209.968 1507.52,206.036 \n",
" 1514.84,202.105 1522.16,198.173 1529.48,194.241 1536.8,190.31 1544.12,186.378 1551.44,182.447 1558.75,178.515 1566.07,174.583 1573.39,170.652 1580.71,166.72 \n",
" 1588.03,162.788 1595.35,158.857 1602.67,154.925 1609.99,150.994 1617.31,147.062 1624.63,143.13 1631.94,139.199 1639.26,135.267 1646.58,131.335 1653.9,127.404 \n",
" 1661.22,123.472 \n",
" \"/>\n",
"<circle clip-path=\"url(#clip212)\" cx=\"1636.43\" cy=\"352.817\" r=\"14\" fill=\"#ff0000\" fill-rule=\"evenodd\" fill-opacity=\"1\" stroke=\"#000000\" stroke-opacity=\"1\" stroke-width=\"2.56\"/>\n",
"<circle clip-path=\"url(#clip212)\" cx=\"1090.94\" cy=\"483.872\" r=\"14\" fill=\"#ff0000\" fill-rule=\"evenodd\" fill-opacity=\"1\" stroke=\"#000000\" stroke-opacity=\"1\" stroke-width=\"2.56\"/>\n",
"<circle clip-path=\"url(#clip212)\" cx=\"1314.31\" cy=\"713.217\" r=\"14\" fill=\"#ff0000\" fill-rule=\"evenodd\" fill-opacity=\"1\" stroke=\"#000000\" stroke-opacity=\"1\" stroke-width=\"2.56\"/>\n",
"</svg>\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"p1 = plot( [StdRp StdRpRf]*100,[μstar μstar]*100,\n",
" legend = nothing,\n",
" linestyle = [:solid :dash],\n",
" linecolor = [:red :blue],\n",
" xlim = (0,15),\n",
" ylim = (0,15),\n",
" title = \"MVF, risky and riskfree assets\",\n",
" xlabel = \"Std(Rp), %\",\n",
" ylabel = \"ERp, %\" )\n",
"scatter!(sqrt.(diag(Σ))*100,μ*100,color=:red)\n",
"display(p1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Mean-Variance Frontier without Short Selling (extra)\n",
"\n",
"The code below solves (numerically) the following minimization problem \n",
"\n",
"$\\min \\text{Var}(R_p) \\: \\text{ s.t. } \\: \\text{E}R_p = \\mu^*$,\n",
" \n",
"and where we also require $w_i\\ge 0$ and $\\sum_{i=1}^{n}w_{i}=1$.\n",
"\n",
"To solve this, we use the packages [Convex.jl](https://github.com/jump-dev/Convex.jl) (for the interface) and [SCS.jl](https://github.com/jump-dev/SCS.jl) (for the optimization algorithm). To check for convergence, we also need a function from the [MathOptInterface.jl](https://github.com/jump-dev/MathOptInterface.jl) package."
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"MathOptInterface"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"using Convex, SCS\n",
"import MathOptInterface\n",
"const MOI = MathOptInterface"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"MeanVarNoSSPs"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\"\"\"\n",
" MeanVarNoSSPs(μ,Σ,μstar)\n",
"\n",
"Calculate mean variance frontier when short sales are not allowed, using Convex and SCS\n",
"\n",
"\n",
"# Input\n",
"- `μ::Vector`: n vector, mean returns\n",
"- `Σ::Matrix`: nxn, covariance matrix of returns, can contain riskfree assets\n",
"- `μstar::Vector`: K vector, mean returns to calculate results for\n",
"\n",
"# Output\n",
"- `StdRp::Vector`: K vector, standard deviation of mean-variance portfolio (risky only) with mean μstar\n",
"- `w_p::Matrix`: Kxn, portfolio weights of \"\"\n",
"\n",
"# Requires\n",
"- Convex and SCS\n",
"\n",
"\"\"\"\n",
"function MeanVarNoSSPs(μ,Σ,μstar) #MV with no short-sales, numerical minimization\n",
"\n",
" (K,n) = (length(μstar),length(μ))\n",
"\n",
" n = length(μ)\n",
" vv = findall( minimum(μ) .<= μstar .<= maximum(μ) ) #solve only if feasible\n",
"\n",
" w = Variable(n)\n",
" Varp = quadform(w,Σ)\n",
" c1 = sum(w) == 1\n",
" c3 = 0 <= w #replace 0 and 1 to get other restrictions\n",
" c4 = w <= 1\n",
"\n",
" (w_p,StdRp) = (fill(NaN,K,n),fill(NaN,K))\n",
" for i in vv #loop over (feasible) μstar elements\n",
" c2 = dot(w,μ) == μstar[i]\n",
" problem = minimize(Varp,c1,c2,c3,c4)\n",
" Convex.solve!(problem,()->SCS.Optimizer(verbose=false))\n",
" if problem.status == MOI.OPTIMAL #check if solution has been found\n",
" w_p[i,:] = evaluate(w)\n",
" StdRp[i] = sqrt(evaluate(Varp))\n",
" end\n",
" end\n",
"\n",
" return StdRp, w_p\n",
"\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"Std_no_ss = MeanVarNoSSPs(μ,Σ,μstar)[1]\n",
"println()"
]
},
{
"cell_type": "code",
"execution_count": 25,
"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=\"clip250\">\n",
" <rect x=\"0\" y=\"0\" width=\"1920\" height=\"1280\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip250)\" 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=\"clip251\">\n",
" <rect x=\"384\" y=\"0\" width=\"1345\" height=\"1280\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip250)\" d=\"\n",
"M197.427 1106.38 L1872.76 1106.38 L1872.76 123.472 L197.427 123.472 Z\n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<defs>\n",
" <clipPath id=\"clip252\">\n",
" <rect x=\"197\" y=\"123\" width=\"1676\" height=\"984\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<polyline clip-path=\"url(#clip252)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 197.427,1106.38 197.427,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip252)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 755.87,1106.38 755.87,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip252)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1314.31,1106.38 1314.31,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip252)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1872.76,1106.38 1872.76,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip250)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,1106.38 1872.76,1106.38 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip250)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,1106.38 197.427,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip250)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 755.87,1106.38 755.87,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip250)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1314.31,1106.38 1314.31,1094.58 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip250)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1872.76,1106.38 1872.76,1094.58 \n",
" \"/>\n",
"<path clip-path=\"url(#clip250)\" d=\"M197.427 1131.73 Q193.816 1131.73 191.988 1135.3 Q190.182 1138.84 190.182 1145.97 Q190.182 1153.07 191.988 1156.64 Q193.816 1160.18 197.427 1160.18 Q201.062 1160.18 202.867 1156.64 Q204.696 1153.07 204.696 1145.97 Q204.696 1138.84 202.867 1135.3 Q201.062 1131.73 197.427 1131.73 M197.427 1128.03 Q203.238 1128.03 206.293 1132.63 Q209.372 1137.22 209.372 1145.97 Q209.372 1154.69 206.293 1159.3 Q203.238 1163.88 197.427 1163.88 Q191.617 1163.88 188.539 1159.3 Q185.483 1154.69 185.483 1145.97 Q185.483 1137.22 188.539 1132.63 Q191.617 1128.03 197.427 1128.03 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M746.148 1128.65 L764.504 1128.65 L764.504 1132.59 L750.43 1132.59 L750.43 1141.06 Q751.449 1140.71 752.468 1140.55 Q753.486 1140.36 754.505 1140.36 Q760.292 1140.36 763.671 1143.54 Q767.051 1146.71 767.051 1152.12 Q767.051 1157.7 763.579 1160.8 Q760.106 1163.88 753.787 1163.88 Q751.611 1163.88 749.343 1163.51 Q747.097 1163.14 744.69 1162.4 L744.69 1157.7 Q746.773 1158.84 748.995 1159.39 Q751.218 1159.95 753.694 1159.95 Q757.699 1159.95 760.037 1157.84 Q762.375 1155.74 762.375 1152.12 Q762.375 1148.51 760.037 1146.41 Q757.699 1144.3 753.694 1144.3 Q751.819 1144.3 749.944 1144.72 Q748.093 1145.13 746.148 1146.01 L746.148 1128.65 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M1289 1159.28 L1296.64 1159.28 L1296.64 1132.91 L1288.33 1134.58 L1288.33 1130.32 L1296.59 1128.65 L1301.27 1128.65 L1301.27 1159.28 L1308.91 1159.28 L1308.91 1163.21 L1289 1163.21 L1289 1159.28 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M1328.35 1131.73 Q1324.74 1131.73 1322.91 1135.3 Q1321.11 1138.84 1321.11 1145.97 Q1321.11 1153.07 1322.91 1156.64 Q1324.74 1160.18 1328.35 1160.18 Q1331.99 1160.18 1333.79 1156.64 Q1335.62 1153.07 1335.62 1145.97 Q1335.62 1138.84 1333.79 1135.3 Q1331.99 1131.73 1328.35 1131.73 M1328.35 1128.03 Q1334.16 1128.03 1337.22 1132.63 Q1340.3 1137.22 1340.3 1145.97 Q1340.3 1154.69 1337.22 1159.3 Q1334.16 1163.88 1328.35 1163.88 Q1322.54 1163.88 1319.46 1159.3 Q1316.41 1154.69 1316.41 1145.97 Q1316.41 1137.22 1319.46 1132.63 Q1322.54 1128.03 1328.35 1128.03 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M1847.94 1159.28 L1855.58 1159.28 L1855.58 1132.91 L1847.27 1134.58 L1847.27 1130.32 L1855.53 1128.65 L1860.21 1128.65 L1860.21 1159.28 L1867.85 1159.28 L1867.85 1163.21 L1847.94 1163.21 L1847.94 1159.28 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M1877.34 1128.65 L1895.7 1128.65 L1895.7 1132.59 L1881.62 1132.59 L1881.62 1141.06 Q1882.64 1140.71 1883.66 1140.55 Q1884.68 1140.36 1885.7 1140.36 Q1891.48 1140.36 1894.86 1143.54 Q1898.24 1146.71 1898.24 1152.12 Q1898.24 1157.7 1894.77 1160.8 Q1891.3 1163.88 1884.98 1163.88 Q1882.8 1163.88 1880.53 1163.51 Q1878.29 1163.14 1875.88 1162.4 L1875.88 1157.7 Q1877.96 1158.84 1880.19 1159.39 Q1882.41 1159.95 1884.89 1159.95 Q1888.89 1159.95 1891.23 1157.84 Q1893.57 1155.74 1893.57 1152.12 Q1893.57 1148.51 1891.23 1146.41 Q1888.89 1144.3 1884.89 1144.3 Q1883.01 1144.3 1881.14 1144.72 Q1879.28 1145.13 1877.34 1146.01 L1877.34 1128.65 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M895.014 1198.08 L895.014 1204.35 Q891.354 1202.6 888.108 1201.74 Q884.861 1200.88 881.837 1200.88 Q876.586 1200.88 873.721 1202.92 Q870.888 1204.96 870.888 1208.71 Q870.888 1211.87 872.766 1213.49 Q874.676 1215.08 879.959 1216.07 L883.842 1216.86 Q891.036 1218.23 894.441 1221.7 Q897.879 1225.14 897.879 1230.93 Q897.879 1237.84 893.232 1241.4 Q888.617 1244.97 879.673 1244.97 Q876.299 1244.97 872.48 1244.2 Q868.692 1243.44 864.618 1241.94 L864.618 1235.32 Q868.533 1237.52 872.289 1238.63 Q876.045 1239.75 879.673 1239.75 Q885.179 1239.75 888.171 1237.58 Q891.163 1235.42 891.163 1231.41 Q891.163 1227.91 888.999 1225.93 Q886.866 1223.96 881.965 1222.
" 197.427,1106.38 1872.76,1106.38 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip252)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 197.427,778.744 1872.76,778.744 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip252)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 197.427,451.108 1872.76,451.108 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip252)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 197.427,123.472 1872.76,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip250)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,1106.38 197.427,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip250)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,1106.38 217.531,1106.38 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip250)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,778.744 217.531,778.744 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip250)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,451.108 217.531,451.108 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip250)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 197.427,123.472 217.531,123.472 \n",
" \"/>\n",
"<path clip-path=\"url(#clip250)\" d=\"M156.683 1092.18 Q153.072 1092.18 151.243 1095.74 Q149.438 1099.28 149.438 1106.41 Q149.438 1113.52 151.243 1117.09 Q153.072 1120.63 156.683 1120.63 Q160.317 1120.63 162.123 1117.09 Q163.952 1113.52 163.952 1106.41 Q163.952 1099.28 162.123 1095.74 Q160.317 1092.18 156.683 1092.18 M156.683 1088.47 Q162.493 1088.47 165.549 1093.08 Q168.627 1097.66 168.627 1106.41 Q168.627 1115.14 165.549 1119.75 Q162.493 1124.33 156.683 1124.33 Q150.873 1124.33 147.794 1119.75 Q144.739 1115.14 144.739 1106.41 Q144.739 1097.66 147.794 1093.08 Q150.873 1088.47 156.683 1088.47 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M147.725 761.464 L166.081 761.464 L166.081 765.399 L152.007 765.399 L152.007 773.871 Q153.026 773.524 154.044 773.362 Q155.063 773.177 156.081 773.177 Q161.868 773.177 165.248 776.348 Q168.627 779.519 168.627 784.936 Q168.627 790.515 165.155 793.617 Q161.683 796.695 155.364 796.695 Q153.188 796.695 150.919 796.325 Q148.674 795.954 146.266 795.214 L146.266 790.515 Q148.35 791.649 150.572 792.205 Q152.794 792.76 155.271 792.76 Q159.276 792.76 161.614 790.654 Q163.952 788.547 163.952 784.936 Q163.952 781.325 161.614 779.218 Q159.276 777.112 155.271 777.112 Q153.396 777.112 151.521 777.529 Q149.669 777.945 147.725 778.825 L147.725 761.464 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M117.331 464.453 L124.97 464.453 L124.97 438.087 L116.66 439.754 L116.66 435.495 L124.924 433.828 L129.6 433.828 L129.6 464.453 L137.239 464.453 L137.239 468.388 L117.331 468.388 L117.331 464.453 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M156.683 436.907 Q153.072 436.907 151.243 440.472 Q149.438 444.013 149.438 451.143 Q149.438 458.249 151.243 461.814 Q153.072 465.356 156.683 465.356 Q160.317 465.356 162.123 461.814 Q163.952 458.249 163.952 451.143 Q163.952 444.013 162.123 440.472 Q160.317 436.907 156.683 436.907 M156.683 433.203 Q162.493 433.203 165.549 437.809 Q168.627 442.393 168.627 451.143 Q168.627 459.87 165.549 464.476 Q162.493 469.059 156.683 469.059 Q150.873 469.059 147.794 464.476 Q144.739 459.87 144.739 451.143 Q144.739 442.393 147.794 437.809 Q150.873 433.203 156.683 433.203 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M118.327 136.817 L125.966 136.817 L125.966 110.451 L117.656 112.118 L117.656 107.859 L125.919 106.192 L130.595 106.192 L130.595 136.817 L138.234 136.817 L138.234 140.752 L118.327 140.752 L118.327 136.817 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M147.725 106.192 L166.081 106.192 L166.081 110.127 L152.007 110.127 L152.007 118.599 Q153.026 118.252 154.044 118.09 Q155.063 117.905 156.081 117.905 Q161.868 117.905 165.248 121.076 Q168.627 124.248 168.627 129.664 Q168.627 135.243 165.155 138.345 Q161.683 141.423 155.364 141.423 Q153.188 141.423 150.919 141.053 Q148.674 140.683 146.266 139.942 L146.266 135.243 Q148.35 136.377 150.572 136.933 Q152.794 137.488 155.271 137.488 Q159.276 137.488 161.614 135.382 Q163.952 133.275 163.952 129.664 Q163.952 126.053 161.614 123.947 Q159.276 121.84 155.271 121.84 Q153.396 121.84 151.521 122.257 Q149.669 122.674 147.725 123.553 L147.725 106.192 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M26.0842 725.546 L26.0842 695.5 L31.495 695.5 L31.495 719.117 L45.5632 719.117 L45.5632 696.487 L50.9741 696.487 L50.9741 719.117 L68.1933 719.117 L68.1933 694.927 L73.6042 694.927 L73.6042 725.546 L26.0842 725.546 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M51.3242 661.825 Q52.0244 659.756 54.3161 657.815 Q56.6077 655.842 60.6181 653.868 L73.6042 647.343 L73.6042 654.25 L61.4138 660.329 Q56.6395 662.685 55.08 664.913 Q53.5204 667.109 53.5204 670.928 L53.5204 677.931 L73.6042 677.931 L73.6042 684.36 L26.0842 684.36 L26.0842 669.846 Q26.0842 661.698 29.4898 657.688
" 1631.87,909.798 1619.14,905.867 1606.44,901.935 1593.79,898.003 1581.18,894.072 1568.6,890.14 1556.07,886.209 1543.59,882.277 1531.15,878.345 1518.75,874.414 \n",
" 1506.41,870.482 1494.11,866.55 1481.87,862.619 1469.67,858.687 1457.53,854.755 1445.44,850.824 1433.42,846.892 1421.44,842.961 1409.53,839.029 1397.69,835.097 \n",
" 1385.9,831.166 1374.18,827.234 1362.53,823.302 1350.95,819.371 1339.44,815.439 1328,811.508 1316.64,807.576 1305.36,803.644 1294.16,799.713 1283.04,795.781 \n",
" 1272.01,791.849 1261.07,787.918 1250.22,783.986 1239.47,780.054 1228.81,776.123 1218.25,772.191 1207.8,768.26 1197.45,764.328 1187.21,760.396 1177.09,756.465 \n",
" 1167.08,752.533 1157.2,748.601 1147.44,744.67 1137.81,740.738 1128.31,736.807 1118.94,732.875 1109.72,728.943 1100.64,725.012 1091.72,721.08 1082.94,717.148 \n",
" 1074.33,713.217 1065.88,709.285 1057.6,705.353 1049.49,701.422 1041.56,697.49 1033.81,693.559 1026.25,689.627 1018.88,685.695 1011.72,681.764 1004.75,677.832 \n",
" 998.001,673.9 991.462,669.969 985.144,666.037 979.051,662.106 973.189,658.174 967.563,654.242 962.179,650.311 957.04,646.379 952.154,642.447 947.523,638.516 \n",
" 943.154,634.584 939.05,630.653 935.217,626.721 931.658,622.789 928.378,618.858 925.38,614.926 922.667,610.994 920.244,607.063 918.112,603.131 916.275,599.199 \n",
" 914.734,595.268 913.492,591.336 912.55,587.405 911.91,583.473 911.572,579.541 911.536,575.61 911.803,571.678 912.372,567.746 913.243,563.815 914.414,559.883 \n",
" 915.885,555.952 917.652,552.02 919.715,548.088 922.07,544.157 924.714,540.225 927.645,536.293 930.859,532.362 934.353,528.43 938.122,524.498 942.162,520.567 \n",
" 946.469,516.635 951.038,512.704 955.865,508.772 960.944,504.84 966.271,500.909 971.841,496.977 977.648,493.045 983.687,489.114 989.952,485.182 996.439,481.251 \n",
" 1003.14,477.319 1010.06,473.387 1017.18,469.456 1024.5,465.524 1032.01,461.592 1039.71,457.661 1047.6,453.729 1055.67,449.797 1063.91,445.866 1072.32,441.934 \n",
" 1080.9,438.003 1089.63,434.071 1098.53,430.139 1107.57,426.208 1116.76,422.276 1126.09,418.344 1135.55,414.413 1145.15,410.481 1154.88,406.55 1164.74,402.618 \n",
" 1174.72,398.686 1184.81,394.755 1195.02,390.823 1205.35,386.891 1215.77,382.96 1226.31,379.028 1236.94,375.097 1247.68,371.165 1258.5,367.233 1269.42,363.302 \n",
" 1280.43,359.37 1291.53,355.438 1302.71,351.507 1313.97,347.575 1325.32,343.643 1336.73,339.712 1348.23,335.78 1359.79,331.849 1371.43,327.917 1383.13,323.985 \n",
" 1394.9,320.054 1406.73,316.122 1418.63,312.19 1430.59,308.259 1442.6,304.327 1454.67,300.396 1466.8,296.464 1478.98,292.532 1491.22,288.601 1503.5,284.669 \n",
" 1515.84,280.737 1528.22,276.806 1540.65,272.874 1553.13,268.942 1565.65,265.011 1578.21,261.079 1590.81,257.148 1603.46,253.216 1616.14,249.284 1628.86,245.353 \n",
" 1641.63,241.421 1654.42,237.489 1667.26,233.558 1680.12,229.626 1693.02,225.695 1705.96,221.763 1718.93,217.831 1731.92,213.9 1744.95,209.968 1758.01,206.036 \n",
" 1771.1,202.105 1784.21,198.173 1797.36,194.241 1810.53,190.31 1823.72,186.378 1836.94,182.447 1850.19,178.515 1863.46,174.583 1876.76,170.652 1890.08,166.72 \n",
" 1903.42,162.788 1916.78,158.857 1930.16,154.925 1943.57,150.994 1957,147.062 1970.44,143.13 1983.91,139.199 1997.4,135.267 2010.9,131.335 2024.43,127.404 \n",
" 2037.97,123.472 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip252)\" style=\"stroke:#008000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:8; stroke-opacity:1; fill:none\" stroke-dasharray=\"32, 20\" points=\"\n",
" 1314.31,713.217 1296.04,709.285 1277.99,705.353 1260.16,701.422 1242.58,697.49 1225.26,693.559 1208.2,689.627 1191.43,685.695 1174.96,681.764 1158.8,677.832 \n",
" 1142.96,673.9 1127.48,669.969 1112.35,666.037 1097.61,662.106 1083.26,658.174 1069.34,654.242 1055.86,650.311 1042.84,646.379 1030.3,642.447 1018.27,638.516 \n",
" 1006.76,634.584 995.806,630.653 985.426,626.721 975.642,622.789 966.477,618.858 957.955,614.926 950.096,610.994 942.921,607.063 936.451,603.131 930.704,599.199 \n",
" 925.698,595.268 921.447,591.336 917.971,587.405 915.264,583.473 913.351,579.541 912.234,575.61 911.916,571.678 912.372,567.746 913.243,563.815 914.414,559.883 \n",
" 915.885,555.952 917.652,552.02 919.715,548.088 922.07,544.157 924.714,540.225 927.645,536.293 930.859,532.362 934.353,528.43 938.122,524.498 942.162,520.567 \n",
" 946.469,516.635 951.038,512.704 955.865,508.772 960.944,504.84 966.271,500.909 971.841,496.977 977.648,493.045 983.687,489.114 989.952,485.182 996.439,481.251 \n",
" 1003.14,477.319 1010.06,473.387 1017.18,469.456 1024.5,465.524 1032.01,461.592 1039.71,457.661 1047.6,453.729 1055.67,449.797 1063.91,445.866 1072.52,441.934 \n",
" 1082.84,438.003 1095.06,434.071 1109.12,430.139 1124.93,426.208 1142.41,422.276 1161.45,418.344 1181.97,414.413 1203.88,410.481 1227.1,406.55 1251.53,402.618 \n",
" 1277.09,398.686 1303.7,394.755 1331.3,390.823 1359.8,386.891 1389.15,382.96 1419.28,379.028 1450.14,375.097 1481.68,371.165 1513.84,367.233 1546.58,363.302 \n",
" 1579.86,359.37 1613.65,355.438 \n",
" \"/>\n",
"<circle clip-path=\"url(#clip252)\" cx=\"1636.43\" cy=\"352.817\" r=\"14\" fill=\"#ff0000\" fill-rule=\"evenodd\" fill-opacity=\"1\" stroke=\"#000000\" stroke-opacity=\"1\" stroke-width=\"2.56\"/>\n",
"<circle clip-path=\"url(#clip252)\" cx=\"1090.94\" cy=\"483.872\" r=\"14\" fill=\"#ff0000\" fill-rule=\"evenodd\" fill-opacity=\"1\" stroke=\"#000000\" stroke-opacity=\"1\" stroke-width=\"2.56\"/>\n",
"<circle clip-path=\"url(#clip252)\" cx=\"1314.31\" cy=\"713.217\" r=\"14\" fill=\"#ff0000\" fill-rule=\"evenodd\" fill-opacity=\"1\" stroke=\"#000000\" stroke-opacity=\"1\" stroke-width=\"2.56\"/>\n",
"<path clip-path=\"url(#clip250)\" d=\"\n",
"M253.272 398.156 L770.367 398.156 L770.367 156.236 L253.272 156.236 Z\n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip250)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 253.272,398.156 770.367,398.156 770.367,156.236 253.272,156.236 253.272,398.156 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip250)\" style=\"stroke:#ff0000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 271.887,216.716 383.575,216.716 \n",
" \"/>\n",
"<path clip-path=\"url(#clip250)\" d=\"M423.903 218.348 L423.903 233.996 L419.643 233.996 L419.643 218.487 Q419.643 214.806 418.208 212.977 Q416.773 211.149 413.903 211.149 Q410.454 211.149 408.463 213.348 Q406.472 215.547 406.472 219.343 L406.472 233.996 L402.19 233.996 L402.19 208.07 L406.472 208.07 L406.472 212.098 Q408 209.76 410.06 208.602 Q412.143 207.445 414.852 207.445 Q419.319 207.445 421.611 210.223 Q423.903 212.977 423.903 218.348 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M442.444 211.056 Q439.018 211.056 437.028 213.741 Q435.037 216.403 435.037 221.056 Q435.037 225.709 437.004 228.394 Q438.995 231.056 442.444 231.056 Q445.847 231.056 447.838 228.371 Q449.828 225.686 449.828 221.056 Q449.828 216.45 447.838 213.764 Q445.847 211.056 442.444 211.056 M442.444 207.445 Q448 207.445 451.171 211.056 Q454.342 214.667 454.342 221.056 Q454.342 227.422 451.171 231.056 Q448 234.667 442.444 234.667 Q436.866 234.667 433.694 231.056 Q430.546 227.422 430.546 221.056 Q430.546 214.667 433.694 211.056 Q436.866 207.445 442.444 207.445 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M495.129 209.065 L495.129 213.047 Q493.324 212.051 491.495 211.565 Q489.689 211.056 487.838 211.056 Q483.694 211.056 481.402 213.695 Q479.111 216.311 479.111 221.056 Q479.111 225.801 481.402 228.44 Q483.694 231.056 487.838 231.056 Q489.689 231.056 491.495 230.57 Q493.324 230.061 495.129 229.065 L495.129 233 Q493.347 233.834 491.425 234.25 Q489.527 234.667 487.375 234.667 Q481.518 234.667 478.069 230.986 Q474.62 227.306 474.62 221.056 Q474.62 214.713 478.092 211.079 Q481.588 207.445 487.652 207.445 Q489.62 207.445 491.495 207.862 Q493.37 208.255 495.129 209.065 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M512.583 211.056 Q509.157 211.056 507.166 213.741 Q505.175 216.403 505.175 221.056 Q505.175 225.709 507.143 228.394 Q509.134 231.056 512.583 231.056 Q515.986 231.056 517.976 228.371 Q519.967 225.686 519.967 221.056 Q519.967 216.45 517.976 213.764 Q515.986 211.056 512.583 211.056 M512.583 207.445 Q518.138 207.445 521.31 211.056 Q524.481 214.667 524.481 221.056 Q524.481 227.422 521.31 231.056 Q518.138 234.667 512.583 234.667 Q507.004 234.667 503.833 231.056 Q500.685 227.422 500.685 221.056 Q500.685 214.667 503.833 211.056 Q507.004 207.445 512.583 207.445 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M553.092 218.348 L553.092 233.996 L548.833 233.996 L548.833 218.487 Q548.833 214.806 547.397 212.977 Q545.962 211.149 543.092 211.149 Q539.643 211.149 537.652 213.348 Q535.661 215.547 535.661 219.343 L535.661 233.996 L531.379 233.996 L531.379 208.07 L535.661 208.07 L535.661 212.098 Q537.189 209.76 539.249 208.602 Q541.333 207.445 544.041 207.445 Q548.508 207.445 550.8 210.223 Q553.092 212.977 553.092 218.348 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M578.115 208.834 L578.115 212.862 Q576.309 211.936 574.365 211.473 Q572.42 211.01 570.337 211.01 Q567.166 211.01 565.569 211.982 Q563.995 212.954 563.995 214.899 Q563.995 216.38 565.129 217.237 Q566.263 218.07 569.689 218.834 L571.147 219.158 Q575.684 220.13 577.582 221.912 Q579.504 223.672 579.504 226.843 Q579.504 230.454 576.633 232.561 Q573.786 234.667 568.786 234.667 Q566.703 234.667 564.434 234.25 Q562.189 233.857 559.689 233.047 L559.689 228.649 Q562.05 229.875 564.342 230.5 Q566.633 231.102 568.879 231.102 Q571.888 231.102 573.508 230.084 Q575.129 229.042 575.129 227.167 Q575.129 225.431 573.948 224.505 Q572.791 223.579 568.832 222.723 L567.351 222.375 Q563.393 221.542 561.633 219.829 Q559.874 218.093 559.874 215.084 Q559.874 211.426 562.467 209.436 Q565.059 207.445 569.828 207.445 Q572.189 207.445 574.272 207.792 Q576.356 208.139 578.115 208.834 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M590.499 200.709 L590.499 208.07 L599.272 208.07 L599.272 211.38 L590.499
" 271.887,277.196 383.575,277.196 \n",
" \"/>\n",
"<path clip-path=\"url(#clip250)\" d=\"M423.903 278.828 L423.903 294.476 L419.643 294.476 L419.643 278.967 Q419.643 275.286 418.208 273.457 Q416.773 271.629 413.903 271.629 Q410.454 271.629 408.463 273.828 Q406.472 276.027 406.472 279.823 L406.472 294.476 L402.19 294.476 L402.19 268.55 L406.472 268.55 L406.472 272.578 Q408 270.24 410.06 269.082 Q412.143 267.925 414.852 267.925 Q419.319 267.925 421.611 270.703 Q423.903 273.457 423.903 278.828 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M442.444 271.536 Q439.018 271.536 437.028 274.221 Q435.037 276.883 435.037 281.536 Q435.037 286.189 437.004 288.874 Q438.995 291.536 442.444 291.536 Q445.847 291.536 447.838 288.851 Q449.828 286.166 449.828 281.536 Q449.828 276.93 447.838 274.244 Q445.847 271.536 442.444 271.536 M442.444 267.925 Q448 267.925 451.171 271.536 Q454.342 275.147 454.342 281.536 Q454.342 287.902 451.171 291.536 Q448 295.147 442.444 295.147 Q436.866 295.147 433.694 291.536 Q430.546 287.902 430.546 281.536 Q430.546 275.147 433.694 271.536 Q436.866 267.925 442.444 267.925 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M493 269.314 L493 273.342 Q491.194 272.416 489.25 271.953 Q487.305 271.49 485.222 271.49 Q482.051 271.49 480.453 272.462 Q478.879 273.434 478.879 275.379 Q478.879 276.86 480.013 277.717 Q481.148 278.55 484.574 279.314 L486.032 279.638 Q490.569 280.61 492.467 282.392 Q494.388 284.152 494.388 287.323 Q494.388 290.934 491.518 293.041 Q488.671 295.147 483.671 295.147 Q481.588 295.147 479.319 294.73 Q477.074 294.337 474.574 293.527 L474.574 289.129 Q476.935 290.355 479.226 290.98 Q481.518 291.582 483.763 291.582 Q486.773 291.582 488.393 290.564 Q490.013 289.522 490.013 287.647 Q490.013 285.911 488.833 284.985 Q487.675 284.059 483.717 283.203 L482.236 282.855 Q478.277 282.022 476.518 280.309 Q474.759 278.573 474.759 275.564 Q474.759 271.906 477.351 269.916 Q479.944 267.925 484.713 267.925 Q487.074 267.925 489.157 268.272 Q491.24 268.619 493 269.314 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M522.722 278.828 L522.722 294.476 L518.462 294.476 L518.462 278.967 Q518.462 275.286 517.027 273.457 Q515.592 271.629 512.722 271.629 Q509.273 271.629 507.282 273.828 Q505.291 276.027 505.291 279.823 L505.291 294.476 L501.009 294.476 L501.009 258.457 L505.291 258.457 L505.291 272.578 Q506.819 270.24 508.879 269.082 Q510.962 267.925 513.671 267.925 Q518.138 267.925 520.43 270.703 Q522.722 273.457 522.722 278.828 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M541.263 271.536 Q537.837 271.536 535.847 274.221 Q533.856 276.883 533.856 281.536 Q533.856 286.189 535.823 288.874 Q537.814 291.536 541.263 291.536 Q544.666 291.536 546.657 288.851 Q548.647 286.166 548.647 281.536 Q548.647 276.93 546.657 274.244 Q544.666 271.536 541.263 271.536 M541.263 267.925 Q546.819 267.925 549.99 271.536 Q553.161 275.147 553.161 281.536 Q553.161 287.902 549.99 291.536 Q546.819 295.147 541.263 295.147 Q535.684 295.147 532.513 291.536 Q529.365 287.902 529.365 281.536 Q529.365 275.147 532.513 271.536 Q535.684 267.925 541.263 267.925 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M575.244 272.531 Q574.527 272.115 573.67 271.93 Q572.837 271.721 571.819 271.721 Q568.207 271.721 566.263 274.082 Q564.342 276.42 564.342 280.818 L564.342 294.476 L560.059 294.476 L560.059 268.55 L564.342 268.55 L564.342 272.578 Q565.684 270.217 567.837 269.082 Q569.99 267.925 573.069 267.925 Q573.508 267.925 574.041 267.994 Q574.573 268.041 575.221 268.156 L575.244 272.531 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M583.925 261.189 L583.925 268.55 L592.698 268.55 L592.698 271.86 L583.925 271.86 L583.925 285.934 Q583.925 289.105 584.781 290.008 Q585.661 290.911 588.323 290.911 L592.698 290.911 L592.698 294.476 L588.323 294.476 Q583.393 294.476 581.518 292.647 Q579.643 290.795 579.64
"<path clip-path=\"url(#clip250)\" d=\"M415.593 341.923 Q410.431 341.923 408.44 343.104 Q406.449 344.284 406.449 347.132 Q406.449 349.4 407.931 350.743 Q409.435 352.062 412.005 352.062 Q415.546 352.062 417.676 349.562 Q419.829 347.039 419.829 342.872 L419.829 341.923 L415.593 341.923 M424.088 340.164 L424.088 354.956 L419.829 354.956 L419.829 351.021 Q418.37 353.382 416.194 354.516 Q414.018 355.627 410.87 355.627 Q406.889 355.627 404.528 353.405 Q402.19 351.159 402.19 347.409 Q402.19 343.034 405.106 340.812 Q408.046 338.59 413.856 338.59 L419.829 338.59 L419.829 338.173 Q419.829 335.234 417.884 333.636 Q415.963 332.016 412.468 332.016 Q410.245 332.016 408.139 332.548 Q406.032 333.081 404.088 334.146 L404.088 330.21 Q406.426 329.308 408.625 328.868 Q410.824 328.405 412.907 328.405 Q418.532 328.405 421.31 331.322 Q424.088 334.238 424.088 340.164 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M449.389 329.794 L449.389 333.822 Q447.583 332.896 445.639 332.433 Q443.694 331.97 441.611 331.97 Q438.44 331.97 436.842 332.942 Q435.268 333.914 435.268 335.859 Q435.268 337.34 436.403 338.197 Q437.537 339.03 440.963 339.794 L442.421 340.118 Q446.958 341.09 448.856 342.872 Q450.778 344.632 450.778 347.803 Q450.778 351.414 447.907 353.521 Q445.06 355.627 440.06 355.627 Q437.977 355.627 435.708 355.21 Q433.463 354.817 430.963 354.007 L430.963 349.609 Q433.324 350.835 435.616 351.46 Q437.907 352.062 440.153 352.062 Q443.162 352.062 444.782 351.044 Q446.403 350.002 446.403 348.127 Q446.403 346.391 445.222 345.465 Q444.065 344.539 440.106 343.683 L438.625 343.335 Q434.667 342.502 432.907 340.789 Q431.148 339.053 431.148 336.044 Q431.148 332.386 433.741 330.396 Q436.333 328.405 441.102 328.405 Q443.463 328.405 445.546 328.752 Q447.629 329.099 449.389 329.794 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M474.088 329.794 L474.088 333.822 Q472.282 332.896 470.338 332.433 Q468.393 331.97 466.31 331.97 Q463.139 331.97 461.541 332.942 Q459.967 333.914 459.967 335.859 Q459.967 337.34 461.102 338.197 Q462.236 339.03 465.662 339.794 L467.12 340.118 Q471.657 341.09 473.555 342.872 Q475.476 344.632 475.476 347.803 Q475.476 351.414 472.606 353.521 Q469.759 355.627 464.759 355.627 Q462.676 355.627 460.407 355.21 Q458.162 354.817 455.662 354.007 L455.662 349.609 Q458.023 350.835 460.315 351.46 Q462.606 352.062 464.852 352.062 Q467.861 352.062 469.481 351.044 Q471.102 350.002 471.102 348.127 Q471.102 346.391 469.921 345.465 Q468.764 344.539 464.805 343.683 L463.324 343.335 Q459.365 342.502 457.606 340.789 Q455.847 339.053 455.847 336.044 Q455.847 332.386 458.44 330.396 Q461.032 328.405 465.801 328.405 Q468.162 328.405 470.245 328.752 Q472.328 329.099 474.088 329.794 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M504.435 340.928 L504.435 343.011 L484.851 343.011 Q485.129 347.409 487.49 349.724 Q489.875 352.016 494.111 352.016 Q496.564 352.016 498.856 351.414 Q501.171 350.812 503.439 349.609 L503.439 353.636 Q501.148 354.608 498.74 355.118 Q496.333 355.627 493.856 355.627 Q487.652 355.627 484.018 352.016 Q480.407 348.405 480.407 342.247 Q480.407 335.882 483.833 332.155 Q487.282 328.405 493.115 328.405 Q498.347 328.405 501.379 331.785 Q504.435 335.141 504.435 340.928 M500.175 339.678 Q500.129 336.183 498.208 334.099 Q496.31 332.016 493.162 332.016 Q489.597 332.016 487.444 334.03 Q485.314 336.044 484.99 339.701 L500.175 339.678 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip250)\" d=\"M515.638 321.669 L515.638 329.03 L524.411 329.03 L524.411 332.34 L515.638 332.34 L515.638 346.414 Q515.638 349.585 516.495 350.488 Q517.374 351.391 520.036 351.391 L524.411 351.391 L524.411 354.956 L520.036 354.956 Q515.106 354.956 513.231 353.127 Q511.356 351.275 511.356 346.414 L511.356 332.34 L508.231 332.34 L508.231 329.03 L511.356 329.03 L511.356 321.669 L515.638 321.669 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#c
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"p1 = plot( [StdRp Std_no_ss]*100,[μstar μstar]*100,\n",
" linecolor = [:red :green],\n",
" linestyle = [:solid :dash],\n",
" linewidth = 2, \n",
" label = [\"no constraints\" \"no short sales\"],\n",
" xlim = (0,15),\n",
" ylim = (0,15),\n",
" legend = :topleft,\n",
" title = \"MVF (with/without constraints)\",\n",
" xlabel = \"Std(Rp), %\",\n",
" ylabel = \"ERp, %\" )\n",
"scatter!(sqrt.(diag(Σ))*100,μ*100,color=:red,label=\"assets\")\n",
"display(p1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"@webio": {
"lastCommId": null,
"lastKernelId": null
},
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Julia 1.6.1",
"language": "julia",
"name": "julia-1.6"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 1
}