0
$\begingroup$

I'm looking at a GBM with parameters

$$ r=0.05 \\ \sigma=0.2 \\ K=130\\ T=0.25\\ S_0 = 100 $$

This is a process that is lognormally distributed with mean and variance given by

$ \mu = S_0e^{r T+0.5\sigma^2 T}\\ Var = S_0^2e^{2r T + \sigma^2T}(e^{\sigma^2 T}-1) $

I'm trying to generate values from this distribution. However, the values I get are quite:

r = 0.05
sigma = 0.2
K = 130
T = 0.25
S0 = 100

import numpy as np
mean = S0*np.exp(r*T)
var = np.sqrt((S0**2)*np.exp(2*r*T)*(np.exp((sigma**2)*T)-1))
np.random.lognormal(mean, np.sqrt(var))

Drawing values from $f(x)$ gives me something around $10^{45}$ (!) Can anybody spot my error in the above?

$\endgroup$
  • $\begingroup$ your mean variable is called mean and you pass mu into whatever function. Could that be related? $\endgroup$ – Slade Dec 13 '19 at 14:18
  • $\begingroup$ @Slade Sorry, I was being sloppy when writing the post. The issue is still there though $\endgroup$ – Tyler D Dec 13 '19 at 14:20
  • $\begingroup$ You should probably copy and paste all the code related so someone else can help. Maybe there's an issue with your variables, etc. Also, in general you should try to put parentheses whenever there are multiple operations being done so the code is easier to read and there's no chance of some kind of PEMDAS issue. $\endgroup$ – Slade Dec 13 '19 at 14:28
  • $\begingroup$ @Slade Updated the OP with the correct code, issue is still there $\endgroup$ – Tyler D Dec 13 '19 at 14:31
  • 1
    $\begingroup$ The main issue (I think) is that you are passing the mean of the lognormal distribution instead of the normal distribution. docs.scipy.org/doc/numpy-1.14.1/reference/generated/… $\endgroup$ – Slade Dec 13 '19 at 14:42
3
$\begingroup$

Assuming that your GBM is given by

$$S_{T}=S_{0}e^{(r -{\frac {\sigma ^{2}}{2}})T+\sigma W_{T}}$$

then its mean and variance are: $${Mean=S_{0}e^{r T},}$$ $$ {Variance=S_{0}^{2}e^{2r T}\left(e^{\sigma ^{2}T}-1\right)}{\displaystyle}$$

You cannot paste these values directly into np.random.lognormal because in this case the parameters $\mu$ and $\sigma^2$ do not represent the mean and variance of the random variable. You actually need to simulate $W_T\sim N(0,T)$ and plug these values into $S_T$.

For the Normal distribution it is only by coincidence that the estimator for $\mu$ and $\sigma$ are the mean and variance; the same does not hold for the Lognormal distribution https://docs.scipy.org/doc/numpy-1.14.1/reference/generated/numpy.random.lognormal.html:

"Draw samples from a log-normal distribution with specified mean, standard deviation, and array shape. Note that the mean and standard deviation are not the values for the distribution itself, but of the underlying normal distribution it is derived from."

To simulate from the Lognormal distribution of $S_T$, note that $\ln S_T$ is normally distributed: $$\ln S_{T}=\ln S_{0}+(r -{\frac {\sigma ^{2}}{2}})T+\sigma W_{T}\sim N(\ln S_{0}+(r -{\frac {\sigma ^{2}}{2}})T,\sigma T)$$

Hence you need to call:

 np.random.lognormal(ln S_0+(r-sigma^2/2)*T, sigma*T)
| improve this answer | |
$\endgroup$
  • $\begingroup$ Given the above values for $r, \sigma, \ldots$, then you're telling me it isn't possible to draw values from the lognormal distribution that $S$ follows? $\endgroup$ – Tyler D Dec 13 '19 at 14:49
  • $\begingroup$ @TylerD It is also possible, you need to set $\mu=\ln S_0+(r-{\frac {\sigma ^{2}}{2}})T$, $\sigma=\sigma T$ and call np.random.lognormal($\mu$, $\sigma$) $\endgroup$ – emcor Dec 13 '19 at 14:54
  • $\begingroup$ I want to simulate values of $S$ using the lognormal density $f(S)$ corresponding to the GBM with $r, \sigma, T, S_0, K$ as above. That must be possible? $\endgroup$ – Tyler D Dec 13 '19 at 14:56
  • $\begingroup$ @TylerD I updated the answer. $\endgroup$ – emcor Dec 13 '19 at 15:01
  • $\begingroup$ Thanks, it makes sense. But I believe the variance should be $\sigma^2 T$, not $\sigma T$. $\endgroup$ – Tyler D Dec 13 '19 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.