Serving the Quantitative Finance Community

Rabelais
Topic Author
Posts: 9
Joined: September 22nd, 2020, 6:33 pm

### Accuracy of Explicit Euler method (finite difference) decreases as Δx decreases, shouldn't it increase?

The price of a commodity can be described by the Schwartz mean reverting SDE
$dS = \alpha(\mu-\log S)Sdt + \sigma S dW$ where W is the standard Brownian motion and alpha is the strength of mean reversion.

From it is possible to derive the PDE for the price of the forward contract having the commodity as underlying asset
$(1) \qquad \frac{\partial F}{\partial t} + \alpha\Big(\mu-\frac{\mu-r}\alpha -\log S\Big)S\frac{\partial F}{\partial S}+\frac12\sigma^2S^2\frac{\partial^2F}{\partial S^2} = 0$ whose analytical solution is $F(S,\tau)=\exp\bigg(e^{-\alpha\tau}\log S +\Big(\mu-\frac{\sigma^2}{2\alpha}-\frac{\mu-r}{\alpha}\Big)(1-e^{-\alpha\tau})+\frac{\sigma^2}{4\alpha}(1-e^{-2\alpha\tau})\bigg)$ where $\tau=T-t$ is the time to expiry ($T$ is the time of delivery/expiry).

Using Euler explicit method, i.e. forward difference on $\dfrac{\partial F}{\partial t}$ and central difference on $\dfrac{\partial F}{\partial S}$ and $\dfrac{\partial^2F}{\partial S^2}$, we can discretize eq (1) as
$F^{n+1}_i = a F^n_{i-1} + b F^n_i + c F^n_{i+1}$ where $a = \dfrac{S\Delta t}{2\Delta S}\bigg(\alpha\mu-(\mu-r)-\alpha\log(S)-\dfrac{\sigma^2S}{\Delta S}\bigg)$, $b = \bigg(1-\sigma^2S^2\dfrac{\Delta t}{\Delta S^2}\bigg)$ and $c = \dfrac{S\Delta t}{2\Delta S}\bigg(-\alpha\mu+(\mu-r)+\alpha\log(S)-\dfrac{\sigma^2S}{\Delta S}\bigg)$.

To run Explicit Euler we have then to choose the number $N$ of time steps, which also set $\Delta t$ since $\Delta t = T/N$, and the size of $\Delta S$. Since the finite difference scheme divides the cartesian plane (time is the X-axis, and spot price is the Y-axis) in a grid, if we take more time steps and/or smaller $\Delta S$ the grid will be more dense and the accuracy of the approximation should increase (provided that $0<\frac{\Delta t}{(\Delta S)^2}<\frac12$).

However, the code I wrote using the equations above doesn't work in this way, in particular to have big accuracy I have to use a large $\Delta S$, and the accuracy decreses when using small values of $\Delta S$ to point that by using $\Delta S=0.1$ the relative error explodes to $10^{165}$ as you can see in the image below (dS stands for $\Delta S$).

If you want you can inspect the matlab code (see attachment), I'm sure there is an error somewhere but cannot find it. I think one problem is the fact that I'm using real data (vector spot_prices in the code) and so I cannot discretize along the y-axis, right?

Attachments
accuracy_test.rar

Cuchulainn
Posts: 64438
Joined: July 16th, 2004, 7:38 am
Location: Drosophila melanogaster
Contact:

### Re: Accuracy of Explicit Euler method (finite difference) decreases as Δx decreases, shouldn't it increase?

Hi,
"Compatibility means deliberately repeating other people's mistakes."
David Wheeler

http://www.datasimfinancial.com
http://www.datasim.nl

JohnLeM
Posts: 515
Joined: September 16th, 2008, 7:15 pm

### Re: Accuracy of Explicit Euler method (finite difference) decreases as Δx decreases, shouldn't it increase?

Your text is all grey, but adding a filter to my screen, I succeeded reading it !!
A possible answer is that your scheme is a finite difference explicit Euler scheme for which there exists a very famous known condition, called the CFL (Courant Friedrich Levy) condition.
In your particular scheme, I think that this condition could be something like (1 - sigma^2 S^2 Delta_t /Delta_s^2) >=0 . Taking Delta_S violating this condition leads to a consistent, but unstable, numerical scheme, which should explode accordingly to your observations.
To define an unconditionally stable numerical scheme, consider either a Crank Nicolson, or fully implicit version.
Last edited by JohnLeM on September 25th, 2020, 4:31 pm, edited 2 times in total.

Cuchulainn
Posts: 64438
Joined: July 16th, 2004, 7:38 am
Location: Drosophila melanogaster
Contact:

### Re: Accuracy of Explicit Euler method (finite difference) decreases as Δx decreases, shouldn't it increase?

There's no h in Nicolson.
"Compatibility means deliberately repeating other people's mistakes."
David Wheeler

http://www.datasimfinancial.com
http://www.datasim.nl

JohnLeM
Posts: 515
Joined: September 16th, 2008, 7:15 pm

### Re: Accuracy of Explicit Euler method (finite difference) decreases as Δx decreases, shouldn't it increase?

There's no h in Nicolson.
I am still doing the same mistakes ever and ever :/

Cuchulainn
Posts: 64438
Joined: July 16th, 2004, 7:38 am
Location: Drosophila melanogaster
Contact:

### Re: Accuracy of Explicit Euler method (finite difference) decreases as Δx decreases, shouldn't it increase?

The answer has been posted on quantnet.com.
Use Crank Nicolson or implicit Euler.

No one use explicit Euler anymore. Better again is ADE. It's explicit and unconditionally stable AND 2nd order accurate in both directions.

https://www.datasim.nl/application/files/5915/7045/5027/Matt_Robinson_Thesis_.pdf
"Compatibility means deliberately repeating other people's mistakes."
David Wheeler

http://www.datasimfinancial.com
http://www.datasim.nl

Cuchulainn
Posts: 64438
Joined: July 16th, 2004, 7:38 am
Location: Drosophila melanogaster
Contact:

### Re: Accuracy of Explicit Euler method (finite difference) decreases as Δx decreases, shouldn't it increase?

There's no h in Nicolson.
I am still doing the same mistakes ever and ever :/
The good news everyone makes the same mistake.

Next time I'll send my cousin to sort you guys out!

"Compatibility means deliberately repeating other people's mistakes."
David Wheeler

http://www.datasimfinancial.com
http://www.datasim.nl

Cuchulainn
Posts: 64438
Joined: July 16th, 2004, 7:38 am
Location: Drosophila melanogaster
Contact:

### Re: Accuracy of Explicit Euler method (finite difference) decreases as Δx decreases, shouldn't it increase?

$\frac{\Delta t}{(\Delta S)^2}<\frac12$

Yes and no; only for the pure heat equation.

Here's the full analysis
https://www.lexifi.com/quant/possible-s ... equations/
"Compatibility means deliberately repeating other people's mistakes."
David Wheeler

http://www.datasimfinancial.com
http://www.datasim.nl

JohnLeM
Posts: 515
Joined: September 16th, 2008, 7:15 pm

### Re: Accuracy of Explicit Euler method (finite difference) decreases as Δx decreases, shouldn't it increase?

$\frac{\Delta t}{(\Delta S)^2}<\frac12$

Yes and no; only for the pure heat equation.

Here's the full analysis
https://www.lexifi.com/quant/possible-s ... equations/
We had also a number of discussions spread everywhere at Wilmott forums concerning monotone schemes, that are probably the best schemes for Finance applications. We should work this topic, I still feel uncomfortable here. Maybe a dedicated thread if someone is interested ?