# Drawing values from a lognormal distribution of a GBM

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?

• your mean variable is called mean and you pass mu into whatever function. Could that be related? Commented Dec 13, 2019 at 14:18
• @Slade Sorry, I was being sloppy when writing the post. The issue is still there though Commented Dec 13, 2019 at 14:20
• 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. Commented Dec 13, 2019 at 14:28
• @Slade Updated the OP with the correct code, issue is still there Commented Dec 13, 2019 at 14:31
• 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/… Commented Dec 13, 2019 at 14:42

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)

• 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? Commented Dec 13, 2019 at 14:49
• @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$) Commented Dec 13, 2019 at 14:54
• 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? Commented Dec 13, 2019 at 14:56
• @TylerD I updated the answer. Commented Dec 13, 2019 at 15:01
• Thanks, it makes sense. But I believe the variance should be $\sigma^2 T$, not $\sigma T$. Commented Dec 13, 2019 at 15:02