Quant Memo
Core

Transformations of Random Variables

Why squaring, exponentiating, or otherwise reshaping a random variable does not just reshape its density the same way — the stretching correction, the Jacobian, that makes probability mass balance out.

Prerequisites: Kolmogorov's Axioms of Probability

If stock prices are lognormal, that means log(price)\log(\text{price}) is normal — but the density of the price is not just the normal density with xx swapped for log(x)\log(x). Applying a function to a random variable warps its distribution in a way that isn't a simple substitution; regions get stretched or compressed, and the probability density has to compensate. Getting this compensation right is what "transformation of random variables" means, and skipping it is a very common source of wrong answers.

The analogy: stretching a rubber sheet with paint on it

Imagine a rubber sheet marked with a fixed amount of paint per unit area — that's a probability density. Now stretch part of the sheet: pull one region out to twice its original width. The total paint on that region hasn't changed, but it is now spread over twice the area, so the paint's density (amount per unit area) there has halved. A transformation of a random variable does exactly this to probability: it relocates outcomes, and wherever the transformation stretches the number line, the density there must shrink to conserve total probability, and wherever it compresses the line, the density must grow.

Writing it down

Let XX have density fX(x)f_X(x) and let Y=g(X)Y = g(X) for a monotonic, differentiable function gg (strictly increasing or strictly decreasing, so it has a well-defined inverse g1g^{-1}). The density of YY is

fY(y)=fX(g1(y))ddyg1(y).f_Y(y) = f_X\big(g^{-1}(y)\big) \, \left| \frac{d}{dy} g^{-1}(y) \right| .

In words: find which xx-value maps to your target yy (that's g1(y)g^{-1}(y)), look up the original density there, then multiply by the stretching factor ddyg1(y)\left|\dfrac{d}{dy}g^{-1}(y)\right| — how much a small interval near yy corresponds to in the original xx-space. That stretching factor is exactly the rubber-sheet correction: it is large where the transformation compresses xx-space into yy-space (density piles up) and small where it stretches xx-space out (density thins).

uniform density in x y = g(x), compressive near x=0 non-uniform density in y — piles up where g compresses
A flat density in x, pushed through a compressive transformation g, piles up where g squeezes many x-values into a small y-range and thins out where g stretches them apart.

Worked example 1: squaring a uniform variable

Let XX be uniform on (0,1)(0,1), so fX(x)=1f_X(x) = 1 for 0<x<10<x<1. Let Y=X2Y = X^2. First find the inverse: if y=x2y = x^2 then x=g1(y)=yx = g^{-1}(y) = \sqrt{y}. The stretching factor: ddyy=12y\dfrac{d}{dy}\sqrt{y} = \dfrac{1}{2\sqrt{y}}. Plug into the formula: fY(y)=fX(y)×12y=1×12y=12yf_Y(y) = f_X(\sqrt{y}) \times \dfrac{1}{2\sqrt{y}} = 1 \times \dfrac{1}{2\sqrt{y}} = \dfrac{1}{2\sqrt{y}} for 0<y<10<y<1. Sanity check by direct computation: P(Y0.25)=P(X0.5)=0.5P(Y \leq 0.25) = P(X \leq 0.5) = 0.5 since XX is uniform. Integrate the derived density to confirm: 00.2512ydy=[y]00.25=0.5\int_0^{0.25} \tfrac{1}{2\sqrt{y}}\,dy = \big[\sqrt{y}\big]_0^{0.25} = 0.5. Matches. Notice fY(y)f_Y(y) \to \infty as y0y \to 0 — squaring compresses values near zero enormously (both 0.10.1 and 0.1-0.1, though here X>0X>0 only, map close to 0.010.01), so density piles up there, exactly the rubber-sheet effect.

Worked example 2: log-return to price, the lognormal case

Let ZZ be standard normal (mean 0, variance 1) representing a log-return, and let S=100eZS = 100\, e^{Z} be next period's price starting from $100. Find the density of SS. Invert: z=ln(s/100)z = \ln(s/100), so g1(s)=ln(s/100)g^{-1}(s) = \ln(s/100). Stretching factor: ddsln(s/100)=1s\dfrac{d}{ds}\ln(s/100) = \dfrac{1}{s}. So fS(s)=ϕ(ln(s/100))×1sf_S(s) = \phi\big(\ln(s/100)\big) \times \dfrac{1}{s}, where ϕ\phi is the standard normal density — this is exactly the lognormal density formula. Concretely at s=100s = 100: ln(100/100)=0\ln(100/100)=0, ϕ(0)=12π0.3989\phi(0) = \tfrac{1}{\sqrt{2\pi}} \approx 0.3989, stretching factor 1/100=0.011/100 = 0.01, so fS(100)0.003989f_S(100) \approx 0.003989. At s=200s=200: ln(2)=0.693\ln(2) = 0.693, ϕ(0.693)0.3123\phi(0.693)\approx 0.3123, stretching factor 1/200=0.0051/200=0.005, giving fS(200)0.001561f_S(200)\approx 0.001561 — visibly lower, even though $200 is only "one log-unit" away, because the 1/s1/s stretching factor shrinks as prices rise.

What this means in practice

Every time a quant moves between log-returns and prices, between volatility and variance, or between a raw signal and a ranked percentile, they are applying a transformation and must include the stretching factor or the resulting density is simply wrong — not approximately wrong, wrong by a factor that depends on where you are on the curve. The lognormal model for prices, the chi-squared distribution of squared normal variables, and delta-method standard errors for nonlinear estimators all come directly from this formula.

Applying a function gg to a random variable does not just relabel the density's axis — it reshapes it. The new density equals the old density (looked up at the corresponding xx) times a stretching factor, ddyg1(y)\left|\dfrac{d}{dy}g^{-1}(y)\right|, that corrects for how much gg compresses or expands the number line at each point.

The classic error is assuming fY(y)=fX(g1(y))f_Y(y) = f_X(g^{-1}(y)) with no stretching factor at all — as if transforming a variable were just a relabeling. It is not: worked example 1 shows a perfectly flat density in XX becomes an unbounded spike near zero in Y=X2Y=X^2 purely from the stretching factor, with nothing about the "shape" of fXf_X changing. Skipping the derivative term is the single most common mistake in change-of-variables problems, and it produces a function that doesn't even integrate to 1.

Related concepts

Practice in interviews

Further reading

  • Casella & Berger, Statistical Inference (ch. 2)
  • Ross, A First Course in Probability (ch. 5-6)
ShareTwitterLinkedIn