Unit 2, lesson 9

Random variables and distribution transformations

How a CDF and a density describe the law of a random variable, how a change of variables with its Jacobian gives a new density, and how completing the square yields the lognormal moments.

  • Video 9
  • Distributions, expectation and dependence

Suppose a model says that the log price ratio of a stock over one year is normal with mean 00 and standard deviation 0.20.2, and the stock starts at 100100 currency units. A risk report asks for the probability that the price ends at or below 9090, the density of the price itself and its expected value. None of these comes from putting the price itself into the normal formulas, because the exponential stretches some intervals of log returns and squeezes others. This lesson describes a law through its CDF and its density, derives the density of a function of a random variable from the inverse Jacobian, and obtains the lognormal density and its moments by completing the square.

Key terms

Random variable

Definition Fix a probability space (Ω,F,P)(\Omega, \mathcal{F}, \mathbb{P}). A random variable is a function X ⁣:Ω→RX \colon \Omega \to \mathbb{R} that is measurable with respect to F\mathcal{F}, which means that

{ω∈Ω:X(ω)≤x}∈F\{\omega \in \Omega : X(\omega) \le x\} \in \mathcal{F}

for every real xx. Equivalently, the event {X∈B}\{X \in B\} belongs to F\mathcal{F} for every Borel set BB of the real line. The distribution, or law, of XX is the probability measure μX(B)=P(X∈B)\mu_X(B) = \mathbb{P}(X \in B) on the Borel sets, and measurability is exactly what makes these probabilities defined. If gg is a Borel function, for example a continuous or a monotone one, then g(X)g(X) is again a random variable. Different random variables, even on different probability spaces, can have the same law.

In plain words A random variable attaches a number, such as a price or a payoff, to each outcome, in such a way that every question of the form “is the value at most xx” has a probability. The law keeps only how the probability is spread over the values and forgets which outcome produced which value. Measurability depends on the collection of events, so a price can be a random variable for full information and fail to be one for less information.

Example In a constructed two-state model, Ω={up,down}\Omega = \{\text{up}, \text{down}\} with P(up)=0.6\mathbb{P}(\text{up}) = 0.6, and F\mathcal{F} contains all four subsets of Ω\Omega. The price with S(up)=110S(\text{up}) = 110 and S(down)=90S(\text{down}) = 90 is a random variable, and so is the call payoff (S−100)+(S - 100)^{+}, which is 1010 in the up state and 00 in the down state. The law of SS puts mass 0.40.4 at 9090 and 0.60.6 at 110110. For the trivial collection {∅,Ω}\{\varnothing, \Omega\}, which carries no information, the same SS is not measurable, because {S≤90}\{S \le 90\} is the event {down}\{\text{down}\}, which that collection does not contain. Only constant functions are measurable for the trivial collection.

Cumulative distribution function

Definition The cumulative distribution function (CDF) of a random variable XX is the function

FX(x)=P(X≤x)F_X(x) = \mathbb{P}(X \le x)

of a real threshold xx. It is nondecreasing and right-continuous, with FX(x)→0F_X(x) \to 0 as x→−∞x \to -\infty and FX(x)→1F_X(x) \to 1 as x→∞x \to \infty. Conversely, every function with these four properties is the CDF of some random variable, a result stated here without proof. The CDF determines the law, and for a<ba < b,

P(a<X≤b)=FX(b)−FX(a).\begin{aligned} &\mathbb{P}(a < X \le b) \\[0.4em] &= F_X(b) - F_X(a). \end{aligned}

Writing FX(x−)F_X(x-) for the limit from the left, the jump FX(x)−FX(x−)F_X(x) - F_X(x-) equals P(X=x)\mathbb{P}(X = x). A value with P(X=x)>0\mathbb{P}(X = x) > 0 is an atom of the law. The CDF describes discrete, continuous and mixed laws alike.

In plain words The CDF says how much probability has accumulated up to a threshold. Raising the threshold can only add outcomes, so the CDF never decreases. A flat stretch carries no probability, and a jump means probability sitting on a single value, with the height of the jump equal to that probability.

Example In the two-state model, FS(x)=0F_S(x) = 0 for x<90x < 90, FS(x)=0.4F_S(x) = 0.4 for 90≤x<11090 \le x < 110 and FS(x)=1F_S(x) = 1 for x≥110x \ge 110. It jumps by 0.40.4 at 9090 and by 0.60.6 at 110110, the probabilities of the two atoms. Right-continuity shows in FS(90)=0.4F_S(90) = 0.4, because the event {S≤90}\{S \le 90\} includes the atom at 9090, while P(S<90)=FS(90−)=0\mathbb{P}(S < 90) = F_S(90-) = 0.

Probability density function

Definition A random variable XX, or its law, is absolutely continuous with probability density function fXf_X if fX≥0f_X \ge 0 and

FX(x)=∫−∞xfX(u) duF_X(x) = \int_{-\infty}^{x} f_X(u)\,du

for every real xx. Then fXf_X integrates to 11, P(X∈B)=∫BfX(u) du\mathbb{P}(X \in B) = \int_B f_X(u)\,du for every Borel set BB, and FX′(x)=fX(x)F_X'(x) = f_X(x) at every point where fXf_X is continuous. A density is determined only up to changes on a set of length zero. It is not a probability. It has the units of one over the units of XX, it can exceed 11, and P(X=x)=0\mathbb{P}(X = x) = 0 for every xx, also where fX(x)>0f_X(x) > 0. A law with an atom has no density. A continuous CDF is not enough for a density either, since singular continuous laws exist, but they lie outside this lesson.

In plain words A density is probability per unit of the variable. When fXf_X is continuous at xx, a short interval from xx to x+hx + h has probability close to fX(x) hf_X(x)\,h. Only areas under the density are probabilities, and a single point has no width and no probability.

Example A price modeled as uniform on [99.9,100.1][99.9, 100.1] has density 55 per currency unit on that interval, more than 11, and every interval of length 0.020.02 inside it has probability 5⋅0.02=0.15 \cdot 0.02 = 0.1. For a mixed law, let SS be the lognormal price of the opening question and let C=(S−100)+C = (S - 100)^{+} be a call payoff. Then P(C=0)=P(S≤100)=0.5\mathbb{P}(C = 0) = \mathbb{P}(S \le 100) = 0.5, an atom at 00, while for c≥0c \ge 0 the CDF is

FC(c)=Φ ⁣(ln⁡(1+c/100)0.2),\begin{aligned} &F_C(c) \\[0.4em] &= \Phi\!\left(\frac{\ln(1 + c/100)}{0.2}\right), \end{aligned}

smooth on c>0c > 0. Its derivative on c>0c > 0 integrates to only 0.50.5, so a density formula alone would lose the half of the probability that sits at a zero payoff.

Change of variables and the Jacobian

Definition Let XX have density fXf_X with P(X∈I)=1\mathbb{P}(X \in I) = 1 for an open interval II. Let gg be continuously differentiable on II with g′(x)≠0g'(x) \ne 0 for every x∈Ix \in I. Then gg is strictly monotone, maps II onto an open interval JJ, and has a continuously differentiable inverse h=g−1 ⁣:J→Ih = g^{-1} \colon J \to I. The random variable Y=g(X)Y = g(X) has the density

fY(y)=fX(h(y)) ∣h′(y)∣f_Y(y) = f_X\bigl(h(y)\bigr)\,\lvert h'(y) \rvert

for y∈Jy \in J, and fY(y)=0f_Y(y) = 0 for y∉Jy \notin J. The factor ∣h′(y)∣=1/∣g′(h(y))∣\lvert h'(y) \rvert = 1/\lvert g'(h(y)) \rvert is the absolute value of the Jacobian of the inverse map, which in one dimension is its derivative. To derive it for increasing gg, note that {Y≤y}={X≤h(y)}\{Y \le y\} = \{X \le h(y)\}, so FY(y)=FX(h(y))F_Y(y) = F_X(h(y)) on JJ, and the substitution u=h(v)u = h(v) in the integral of fXf_X up to h(y)h(y) produces the density. For decreasing gg the inequality reverses, FY(y)=1−FX(h(y))F_Y(y) = 1 - F_X(h(y)), and h′<0h' < 0, which the absolute value corrects. More generally, suppose II splits, apart from finitely many points, into open intervals I1,…,ImI_1, \dots, I_m on each of which gg is continuously differentiable with g′≠0g' \ne 0, and let hih_i be the inverse of gg on IiI_i. Then every branch that reaches yy contributes,

fY(y)=∑i : y∈g(Ii)fX(hi(y))×∣hi′(y)∣.\begin{aligned} f_Y(y) &= \sum_{i \,:\, y \in g(I_i)} f_X\bigl(h_i(y)\bigr) \\[0.4em] &\qquad \times \lvert h_i'(y) \rvert . \end{aligned}

The left-out points have probability zero, and the value of fYf_Y at their images does not matter.

In plain words The map moves probability without creating or destroying any. Outputs between yy and y+dyy + dy come from inputs in an interval of width close to ∣h′(y)∣ dy\lvert h'(y) \rvert\,dy, which carries probability close to fX(h(y)) ∣h′(y)∣ dyf_X(h(y))\,\lvert h'(y) \rvert\,dy, and dividing by dydy gives the new density. The absolute value keeps widths positive when the map reverses order, and a map that folds several inputs onto one output collects probability from all of them.

Example Let XX be standard normal with density φ\varphi, and let Y=X2Y = X^2, the square of a standardized return. Since g′(0)=0g'(0) = 0, split the line into (−∞,0)(-\infty, 0) and (0,∞)(0, \infty). The inverses there are −y-\sqrt{y} and y\sqrt{y}, both branches reach every y>0y > 0, and both have ∣hi′(y)∣=1/(2y)\lvert h_i'(y) \rvert = 1/(2\sqrt{y}). So for y>0y > 0,

fY(y)=φ(y)+φ(−y)2y=e−y/22πy,\begin{aligned} &f_Y(y) \\[0.4em] &= \frac{\varphi(\sqrt{y}) + \varphi(-\sqrt{y})}{2\sqrt{y}} \\[0.4em] &= \frac{e^{-y/2}}{\sqrt{2\pi y}}, \end{aligned}

the chi-squared density with one degree of freedom, unbounded near 00 and still integrable. As a check, P(Y≤1)=P(−1≤X≤1)\mathbb{P}(Y \le 1) = \mathbb{P}(-1 \le X \le 1), which is about 0.68270.6827. Keeping only the positive branch would give about 0.34130.3413, half of the probability.

Lognormal distribution

Definition Let Z∼N(μ,σ2)Z \sim N(\mu, \sigma^2) with μ\mu real and σ>0\sigma > 0, and let S0>0S_0 > 0. The price S=S0eZS = S_0 e^{Z} has a lognormal distribution, which means that ln⁡(S/S0)∼N(μ,σ2)\ln(S/S_0) \sim N(\mu, \sigma^2). The exponential is strictly increasing from R\mathbb{R} onto (0,∞)(0, \infty), with inverse z=ln⁡(s/S0)z = \ln(s/S_0) and dz/ds=1/sdz/ds = 1/s. With the standardized log price

z(s)=ln⁡(s/S0)−μσ,z(s) = \frac{\ln(s/S_0) - \mu}{\sigma},

the CDF and the density of SS are, for s>0s > 0,

FS(s)=Φ(z(s)),fS(s)=φ(z(s))s σ,\begin{gathered} F_S(s) = \Phi\bigl(z(s)\bigr), \\[0.4em] f_S(s) = \frac{\varphi\bigl(z(s)\bigr)}{s\,\sigma}, \end{gathered}

and both are zero for s≤0s \le 0. Since FSF_S is strictly increasing on (0,∞)(0, \infty) and FS(S0eμ)=Φ(0)=12F_S(S_0 e^{\mu}) = \Phi(0) = \frac12, the median is S0eμS_0 e^{\mu}. The mean S0eμ+σ2/2S_0 e^{\mu + \sigma^2/2}, derived in the next card, lies above the median. If σ=0\sigma = 0, the price is the constant S0eμS_0 e^{\mu}, an atom with no density, so the formulas need σ>0\sigma > 0. Lognormality is a model assumption about prices, not a property of market data.

In plain words A lognormal price is the starting price times the exponential of a normal log return. It is always positive and skewed to the right. The factor 1/s1/s is the Jacobian of the logarithm, and it is why the price density is not the normal bell curve redrawn on a price axis. Because the exponential keeps the order of values, every quantile of the price is S0S_0 times the exponential of the same quantile of the log return. The median follows this rule, while the long right tail pulls the mean above it.

Example With the constructed values S0=100S_0 = 100, μ=0\mu = 0 and σ=0.2\sigma = 0.2, the median price is 100100 and P(S≤100)=0.5\mathbb{P}(S \le 100) = 0.5. The probability of ending at or below 9090 is Φ(ln⁡0.9/0.2)=Φ(−0.5268)\Phi(\ln 0.9 / 0.2) = \Phi(-0.5268), about 0.29920.2992. The 0.050.05 and 0.950.95 quantiles are 100e−0.2⋅1.6449≈71.97100e^{-0.2 \cdot 1.6449} \approx 71.97 and 100e0.2⋅1.6449≈138.95100e^{0.2 \cdot 1.6449} \approx 138.95, which lie 28.0328.03 below and 38.9538.95 above the median. The density at the median is 1/(100⋅0.22π)1/(100 \cdot 0.2\sqrt{2\pi}), about 0.01990.0199 per currency unit.

Completing the square

Definition Completing the square rewrites a quadratic plus a linear term as one shifted square plus a constant. Let Z∼N(μ,σ2)Z \sim N(\mu, \sigma^2) with σ>0\sigma > 0 and let aa be any real number. The exponent of the integrand in E[eaZ]\mathbb{E}[e^{aZ}] satisfies

az−(z−μ)22σ2=−(z−μ−aσ2)22σ2+aμ+a2σ22,\begin{aligned} &az - \frac{(z - \mu)^2}{2\sigma^2} \\[0.4em] &= -\frac{(z - \mu - a\sigma^2)^2}{2\sigma^2} \\[0.4em] &\quad + a\mu + \frac{a^2\sigma^2}{2}, \end{aligned}

so the integrand is eaμ+a2σ2/2e^{a\mu + a^2\sigma^2/2} times the density of N(μ+aσ2,σ2)N(\mu + a\sigma^2, \sigma^2), which integrates to 11. Hence

E[eaZ]=eaμ+a2σ2/2\mathbb{E}\bigl[e^{aZ}\bigr] = e^{a\mu + a^2\sigma^2/2}

for every real aa, and the identity also holds when σ=0\sigma = 0. For the lognormal price S=S0eZS = S_0 e^{Z} it gives E[Sa]=S0aeaμ+a2σ2/2\mathbb{E}[S^a] = S_0^a e^{a\mu + a^2\sigma^2/2} for every real aa. The choices a=1a = 1 and a=2a = 2 give

E[S]=S0 eμ+σ2/2,E[S2]=S02 e2μ+2σ2,\begin{aligned} \mathbb{E}[S] &= S_0\,e^{\mu + \sigma^2/2}, \\[0.4em] \mathbb{E}[S^2] &= S_0^2\,e^{2\mu + 2\sigma^2}, \end{aligned}

and therefore

Var⁡(S)=E[S2]−(E[S])2=S02 e2μ+σ2(eσ2−1).\begin{aligned} &\operatorname{Var}(S) \\[0.4em] &= \mathbb{E}[S^2] - \bigl(\mathbb{E}[S]\bigr)^2 \\[0.4em] &= S_0^2\,e^{2\mu + \sigma^2}\bigl(e^{\sigma^2} - 1\bigr). \end{aligned}

When σ>0\sigma > 0, all moments of SS are finite, yet E[etS]=∞\mathbb{E}[e^{tS}] = \infty for every t>0t > 0, because etS0eze^{tS_0 e^{z}} grows faster than the normal density decays. The moment generating function belongs to the normal logarithm ZZ, not to the price.

In plain words Multiplying the normal density by eaze^{az} slides the bell curve to the right by aσ2a\sigma^2 and leaves a constant factor outside. Once the shifted bell curve is recognized, its integral is 11 and the constant is the answer, with no series expansion or table needed.

Example For the constructed values S0=100S_0 = 100, μ=0\mu = 0 and σ=0.2\sigma = 0.2,

E[S]=100 e0.02≈102.0201,Var⁡(S)=104e0.04(e0.04−1)≈424.7629,\begin{aligned} &\mathbb{E}[S] = 100\,e^{0.02} \\[0.4em] &\approx 102.0201, \\[0.4em] &\operatorname{Var}(S) \\[0.4em] &= 10^4 e^{0.04}\bigl(e^{0.04} - 1\bigr) \\[0.4em] &\approx 424.7629, \end{aligned}

a standard deviation of about 20.6120.61 currency units. Doubling σ\sigma to 0.40.4 with μ=0\mu = 0 held fixed keeps the median at 100100 and raises the mean to 100e0.08≈108.3287100e^{0.08} \approx 108.3287. That rise comes from holding the mean log return fixed. It is not a claim that higher volatility raises expected returns. To keep the mean at 102.0201102.0201 instead, the parameter μ\mu must fall to 0.02−0.08=−0.060.02 - 0.08 = -0.06, and then the median falls to 100e−0.06≈94.18100e^{-0.06} \approx 94.18. A statement about the effect of volatility has to say which parameter stays fixed.

Check yourself

  1. In the constructed lognormal model with S0=100S_0 = 100, μ=0\mu = 0 and σ=0.2\sigma = 0.2, find the probability that the price ends above 120120 and the price level that is exceeded with probability 0.050.05.
Show the answer

The event {S>120}\{S > 120\} is the event {Z>ln⁡1.2}\{Z > \ln 1.2\}, so

P(S>120)=1−Φ ⁣(ln⁡1.20.2)=1−Φ(0.9116)≈0.1810.\begin{aligned} &\mathbb{P}(S > 120) \\[0.4em] &= 1 - \Phi\!\left(\frac{\ln 1.2}{0.2}\right) \\[0.4em] &= 1 - \Phi(0.9116) \\[0.4em] &\approx 0.1810 . \end{aligned}

The level exceeded with probability 0.050.05 is the 0.950.95 quantile. The exponential keeps the order of values, so it is 100100 times the exponential of the 0.950.95 quantile of ZZ, which is 0.2⋅1.64490.2 \cdot 1.6449. The level is 100e0.3290≈138.95100e^{0.3290} \approx 138.95 currency units.

  1. A classmate writes the price density as φ(z(s))/σ\varphi(z(s))/\sigma, the normal density of the log return evaluated at ln⁡(s/S0)\ln(s/S_0), without the factor 1/s1/s. Explain what is wrong, and compute the integral of this function over s>0s > 0 for the constructed values.
Show the answer

The classmate dropped the Jacobian of the inverse map z=ln⁡(s/S0)z = \ln(s/S_0), whose derivative is 1/s1/s. Substituting s=S0ezs = S_0 e^{z}, so that ds=S0ez dzds = S_0 e^{z}\,dz, gives

∫0∞φ(z(s))σ ds=S0 E[eZ]=S0 eμ+σ2/2,\begin{aligned} &\int_0^\infty \frac{\varphi\bigl(z(s)\bigr)}{\sigma}\,ds \\[0.4em] &= S_0\,\mathbb{E}\bigl[e^{Z}\bigr] = S_0\,e^{\mu + \sigma^2/2}, \end{aligned}

which is about 102.0201102.0201 for the constructed values, not 11, so the function is not a probability density. The units also give it away. A density of a price must be measured per currency unit, while the classmate’s function has no units. With the factor 1/s1/s the same substitution cancels S0ezS_0 e^{z} against ss and the integral is exactly 11.

  1. Let SS be the price of one unit of a foreign currency in domestic currency units, lognormal with S0=100S_0 = 100, μ=0\mu = 0 and σ=0.2\sigma = 0.2. Find the law of the reciprocal quote Y=1/SY = 1/S, its mean, and compare E[1/S]\mathbb{E}[1/S] with 1/E[S]1/\mathbb{E}[S].
Show the answer

The map g(s)=1/sg(s) = 1/s is decreasing and continuously differentiable on (0,∞)(0, \infty) with g′≠0g' \ne 0, and its inverse is h(y)=1/yh(y) = 1/y with ∣h′(y)∣=1/y2\lvert h'(y) \rvert = 1/y^2. For y>0y > 0 the CDF is FY(y)=P(S≥1/y)=1−FS(1/y)F_Y(y) = \mathbb{P}(S \ge 1/y) = 1 - F_S(1/y), and the density is

fY(y)=fS(1/y)y2=1y σ φ ⁣(ln⁡(yS0)+μσ),\begin{aligned} &f_Y(y) = \frac{f_S(1/y)}{y^2} \\[0.4em] &= \frac{1}{y\,\sigma}\,\varphi\!\left(\frac{\ln(y S_0) + \mu}{\sigma}\right), \end{aligned}

using that φ\varphi is even. This is the lognormal density with starting value 1/S01/S_0 and log parameters −μ-\mu and σ\sigma, as it must be, since Y=(1/S0)e−ZY = (1/S_0)e^{-Z} and −Z∼N(−μ,σ2)-Z \sim N(-\mu, \sigma^2). Completing the square with a=−1a = -1 gives

E[1/S]=e−μ+σ2/2S0≈0.010202,\begin{aligned} \mathbb{E}[1/S] &= \frac{e^{-\mu + \sigma^2/2}}{S_0} \\[0.4em] &\approx 0.010202, \end{aligned}

while 1/E[S]=1/102.0201≈0.0098021/\mathbb{E}[S] = 1/102.0201 \approx 0.009802. The two differ because 1/s1/s is strictly convex on (0,∞)(0, \infty), so Jensen’s inequality makes E[1/S]>1/E[S]\mathbb{E}[1/S] > 1/\mathbb{E}[S] whenever σ>0\sigma > 0. The medians do match, because P(Y≤0.01)=P(S≥100)=0.5\mathbb{P}(Y \le 0.01) = \mathbb{P}(S \ge 100) = 0.5, so the median of YY is 1/100=0.011/100 = 0.01.

How this lesson connects