Skip to content

Commit

Permalink
Conlusion of all the Levy processes notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
cantaro86 committed Nov 3, 2019
1 parent 0cd2739 commit 270680a
Show file tree
Hide file tree
Showing 25 changed files with 5,754 additions and 1,585 deletions.
441 changes: 0 additions & 441 deletions 1.2 SDE simulations and more.ipynb

This file was deleted.

1,319 changes: 1,319 additions & 0 deletions 1.2 SDE simulations and statistics.ipynb

Large diffs are not rendered by default.

55 changes: 29 additions & 26 deletions 1.3 Fourier transform methods.ipynb

Large diffs are not rendered by default.

928 changes: 928 additions & 0 deletions 1.4 SDE - Heston model.ipynb

Large diffs are not rendered by default.

1,138 changes: 1,138 additions & 0 deletions 1.5 SDE - Lévy processes.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 2.2 Exotic options.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@
"\n",
"When working with path dependent options, such as Barrier options, it is necessary to generate the entire paths. This is SUPER slow!! \n",
"\n",
"With C and Cython it is possible to improve the performance. (in the future I will work on that)\n",
"With C and Cython it is possible to improve the performance.\n",
"\n",
"There are several methods to improve the algorithm:\n",
"- using antithetic variables [wiki](https://en.wikipedia.org/wiki/Antithetic_variates) to reduce the total variance.\n",
Expand Down
33 changes: 21 additions & 12 deletions 2.3 American Options.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"This formula resembles the formula of a European option, except that in this case the option can be exercised at any time. But... at which time? The problem is to find the best exercise time $\\tau$ that maximizes the expectation.\n",
"\n",
"Notice that the time $\\tau$ is a random variable! It can be different for different paths of the stock process. \n",
"The solution of the problem is thus a strategy (the optimal control) that at each time assesses if it is optimal to exercise the option or not, depending on the current value of the underlying stock.\n",
"The solution of the problem provides a strategy, that at each time assesses if it is optimal to exercise the option or not, depending on the current value of the underlying stock.\n",
"\n",
"This notebook is dedicated to the pricing problem, i.e. just to find $V(t,s)$.\n",
"This notebook is dedicated only to the pricing problem, i.e. just to find $V(t,s)$, and not to find $\\tau$.\n",
"\n",
"It can be proved that the function $V(t,s)$ is the (weak) solution of the following PDE:\n",
"\n",
Expand All @@ -35,9 +35,9 @@
"\n",
"$$ V(T,s) = \\Phi(s) $$\n",
"\n",
"The numerical algorithm for solving this PDE is almost identical to the approach used for the Black-Scholes equation. \n",
"The numerical algorithm for solving this PDE is almost identical to the algorithm proposed in the notebook **2.1** for the Black-Scholes PDE. \n",
"\n",
"Let us have a look at the implementation in the classes `BS_pricer`, `Merton_pricer`, `VG_pricer`:\n",
"Let us have a look at the differences between the implementation of the European and the American algorithm, in the class `BS_pricer`:\n",
"\n",
"```python\n",
"if self.exercise==\"European\": \n",
Expand Down Expand Up @@ -83,7 +83,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -106,26 +106,26 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAMYAAAASCAYAAAAANKFkAAAABHNCSVQICAgIfAhkiAAABz1JREFUaIHt2nvwVVUVB/AP9LMExcoomMoUlYKgsShNK/VqykSGYWV/OPnooU45SU9NreHX20c5mT0csoflTNNkoRNpSQyFUo69GIewROVXMEkIykMgCKE/1j5zz+/8zrn3nvv7+fvrfmfO7Hv3Xmvvtdfea++11jn00EMPtXEu9qfnA13wn4G7sR678Ch+ihNKaN+FG3EPtqUxb23R9wuSTIvwcOp/K+7F+zG2Be9L8T38G7sxgK/h+SW0A5o6KD4bSugvaEGfPU+X8F2DpViX5vIE/ooFaa5lqKuz0dQxnIif4TGh58fEfnhrCe0YvA/3YTt2ivlfimeNkFwdz7+vxaQOS508hYNb0FXhGlyGzbgdm3A03o534ryCUJ/GMWm89ZjWpv+z8W2h7GX4FybhHbgZcxLN/gLfUfg9XoQ78Hcch/l4C96YZM5jqzCcIp4qqVuJz1bIfCJOxV0lbR/FX7AEG3EQjkc/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NYHk04zrAXvi/+b8AW/E3k0HUc7yai8erUZp24vSqrNbc043gsaxlggAEGGGCAAQaA/wIaTbIUKTW09QAAAABJRU5ErkJggg==\n",
"text/latex": [
"$\\displaystyle 4.81205731126921$"
"$\\displaystyle 4.834259780628$"
],
"text/plain": [
"4.81205731126921"
"4.834259780628"
]
},
"execution_count": 5,
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"BS.LSM() # Longstaff Schwartz Method"
"BS.LSM(N=10000, paths=10000, order=2) # Longstaff Schwartz Method"
]
},
{
Expand Down Expand Up @@ -253,7 +253,7 @@
"<a id='sec2'></a>\n",
"## Longstaff - Schwartz Method\n",
"\n",
"This is a Monte Carlo algorithm proposed by Longstaff and Schwartz in the paper:\n",
"This is a Monte Carlo algorithm proposed by Longstaff and Schwartz in the paper [1]:\n",
"[LS Method](https://people.math.ethz.ch/~hjfurrer/teaching/LongstaffSchwartzAmericanOptionsLeastSquareMonteCarlo.pdf)\n",
"\n",
"The algorithm is not difficult to implement, but it can be difficult to understand. I think this is the reason the authors started the paper with an exaple. \n",
Expand Down Expand Up @@ -472,6 +472,15 @@
"source": [
"display_matrix(V.round(4))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## References\n",
"\n",
"[1] F. Longstaff, E. Schwartz (2001) \"Valuing American Options by Simulation: A Simple Least-Squares Approach\", The Review of Financial Studies, vol 14-1, pag 113-147. "
]
}
],
"metadata": {
Expand Down
32 changes: 17 additions & 15 deletions 3.1 Merton jump-diffusion, PIDE method.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
" \n",
"The notebook **2.1** is a prerequisites for understanding this notebook. If you don't know the Merton model, have a look at the notebook **A.3**.\n",
"\n",
"In this notebook we only consider the problem of solving the PIDE. \n",
"In this notebook we only consider the problem of solving the Merton PIDE. \n",
"Let us recall that, this is the pricing PIDE associated to the process: \n",
"\n",
"\\begin{equation}\\label{MertonM}\n",
Expand Down Expand Up @@ -70,7 +70,7 @@
"The Lévy measure is a scaled Normal distribution, such that $\\lambda = \\int_{\\mathbb{R}} \\nu(dz)$.\n",
"\n",
"For more information on the derivation of this equation, have a look at the PDF **A3**. It includes a short description of PIDEs and the Merton model. \n",
"This equation is a clear \"extension\" of the Black-Scholes equation. It coincides with the BS equation for $\\nu = 0$.\n",
"This equation is a clear \"extension\" of the Black-Scholes equation. It coincides with the BS equation for $\\lambda = 0$.\n",
"\n",
"Let us first introduce the discretization method, and then write everything in python!"
]
Expand All @@ -87,7 +87,7 @@
"\n",
"We will adopt the Implicit-Explicit **(IMEX)** scheme proposed by Cont-Voltchkova [1]. The differential part is discretized by an implicit scheme (the same approach used for the BS equation). The integral part in instead discretized by an explicit scheme. The reason of the explicit choice, is that it avoids the inversion of the dense \"jump\" matrix (below we will construct the jump matrix).\n",
"\n",
"The integral part is computed using the **fourier methods** (it is a convolution integral) in order to increasing the efficiency."
"The integral part is computed using **fourier methods** (it is a convolution integral) in order to increasing the efficiency."
]
},
{
Expand Down Expand Up @@ -498,8 +498,8 @@
"Since the integral we are considering is a convolution integral, we should take advantage of the [convolution theorem](https://en.wikipedia.org/wiki/Convolution_theorem).\n",
"\n",
"We can use two python functions:\n",
"- [fftconvolve](https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.fftconvolve.html#scipy.signal.fftconvolve) Convolve two arrays using FFT.\n",
"- [convolve](https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.convolve.html) Convolve two arrays. The user can specify the method. If the length of the array is smaller than 500 it is better to use the definition of convolution, otherwise it is better to use the FFT (and it calls fftconvolve).\n",
"- [fftconvolve](https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.fftconvolve.html#scipy.signal.fftconvolve) Convolves two arrays using FFT.\n",
"- [convolve](https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.convolve.html) Convolves two arrays. The user can specify the method. If the length of the array is smaller than 500 it is better to use the definition of convolution, otherwise it is better to use the FFT (and it calls fftconvolve).\n",
"\n",
"Let us check that the output is the same:"
]
Expand Down Expand Up @@ -587,7 +587,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -599,7 +599,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -616,7 +616,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"PIDE price:"
"**PIDE price:**"
]
},
{
Expand All @@ -643,7 +643,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The closed formula gives the value:"
"**Closed formula:**"
]
},
{
Expand All @@ -670,7 +670,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Fourier inversion price:"
"**Fourier inversion:**"
]
},
{
Expand All @@ -697,27 +697,27 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Monte Carlo method gives the value: (the output includes the price, the standard error and the execution time)"
"**Monte Carlo** method gives the value: (the output includes the price, the standard error and the execution time)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(22.13987625472911, 0.08186874789093583, 29.929722785949707)"
"(22.01260319665876, 0.05643812936401397, 64.60239958763123)"
]
},
"execution_count": 7,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Merton.MC(500000, Err=True, Time=True)"
"Merton.MC(1000000, Err=True, Time=True)"
]
},
{
Expand Down Expand Up @@ -1051,6 +1051,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# References\n",
"\n",
"[1] Cont-Voltchkova (2005), \"Integro-differential equations for option prices in exponential Lévy models\", Finance and Stochastics, 9, 299--325.\n",
"\n",
"[2] Merton, R. (1976). \"Option pricing when underlying stock returns are discontinuous\", Journal of Financial Economics, 3, 125--144."
Expand Down
Loading

0 comments on commit 270680a

Please sign in to comment.