Back of the Envelope

Observations on the Theory and Empirics of Mathematical Finance

Archive for the ‘Math: Useful’ Category

[Stats] Normalizing to a benchmark by matching moments

leave a comment »

One often needs to compare data across samples, say, when one or more samples constitute a benchmark. For example, consider comparing interview scores across panels when one of the panels is considered to be the benchmark.

The objective is to transform the data of a sample \{Y\} so as to match its mean (\mu_Y) and standard deviation (\sigma_Y) to that of the benchmark sample. That is, we begin with:

\begin{aligned} \mathbb{E}[Y] &= \mu_Y\\ \mathbb{E}[\big(Y - \mu\big)^2] &= \sigma_Y^2 \end{aligned}

and we need to transform data \{Y\} as \{Z = cY + d\} such that \mu_Z = \mu_B and \sigma_Z^2 = \sigma_B^2, where \mu_B and \sigma_B respectively represent the mean and standard deviation of the benchmark sample.

The moment matching approach then requires finding parameters c and d such that:

\begin{aligned} \mathbb{E}[cY + d] &= \mu_B \\ \mathbb{E}[\big((cY + d) - \mu_B \big)^2] &= \sigma_B^2 \end{aligned}

Simplifying the second equation implies we require that:

\begin{aligned} c^2 \mathbb{E}[Y^2] + d^2 + 2cd\mathbb{E}[Y] + \mu_B^2 - 2\mathbb{E}[cY + d]\mu_B &= \sigma_B^2 \\ \mbox{or } c^2 \mathbb{E}[Y^2] + d^2 + 2cd\mu_Y + \mu_B^2 - 2\mu_B^2 &= \sigma_B^2 \\ \mbox{or } c^2 (\mu_Y^2 + \sigma_Y^2) + d^2 + 2cd\mu_Y &= \mu_B^2 + \sigma_B^2\\ \mbox{or } c^2 \sigma_Y^2 + \underbrace{c^2 \mu_Y^2 + d^2 + 2cd\mu_Y}_{\mu_B^2} &= \mu_B^2 + \sigma_B^2 \\ \mbox{i.e. } c &= \dfrac{\sigma_B}{\sigma_Y}\end{aligned}

And accordingly,

d = \mu_B - c\mathbb{E}[Y] =\mu_B - c\mu_Y= \mu_B - \dfrac{\sigma_B}{\sigma_Y}\mu_Y

That is, transforming Y as:

Z = \dfrac{\sigma_B}{\sigma_Y}(Y - \mu_Y) + \mu_B

ensures that Z has the same mean and standard deviation as the benchmark data. Needless to say that this will work best for situations where the underlying data can be safely assumed to be coming from the Normal distribution or any of its kin (why?).

Looking at the transformation, upon a moment’s reflection it almost appears obvious, doesn’t it? To the point that this whole post seems moot. So, why bother? Well, while this is a simple enough example, the method of moments is important enough in economics and finance for its generalized version to be granted a Nobel status a couple of years ago.


Written by Vineet

April 7, 2015 at 12:22 am

[Stats] Results involving correlation

leave a comment »

I have noticed that many of our students are not quite aware of mathematical proofs behind some very basic identities involving correlation (standard books on probability – including that one – of course, have the necessary proofs, but old-fashioned textbooks aren’t exactly all that popular, are they?).

I have in mind the three:

  1. Correlation coefficient always lies between minus and plus 1
  2. Perfect correlation between two variables implies a linear relationship between them
  3. The relationship between R^2 in a simple linear regression and the correlation coefficient

1. Proof that \mathbf{|\rho| \le 1}

(This pretty much follows Feller, Vol. 1, Chapter 9)

Normalize the random variables X and Y to have mean 0 and standard deviation 1, as:

\begin{aligned} x &= \frac{X - \mu_X}{\sigma_X} \hspace{0.5pc} \mbox{and}\hspace{0.5pc} y=\frac{X - \mu_Y}{\sigma_Y} \end{aligned}

Covariance, \mbox{Cov}(x, y), between the standardized random variables x and y is:

\begin{aligned} \mbox{Cov}(x, y) &= \mbox{Cov}(\frac{X - \mu_X}{\sigma_X}, \frac{Y - \mu_Y}{\sigma_Y}) \\&=\mathbb{E}\big[\frac{(X - \mu_X)(Y - \mu_Y)}{\sigma_X \sigma_Y}\big] - \mathbb{E}\big[\frac{X - \mu_X}{\sigma_X}\big] \mathbb{E}\big[\frac{Y - \mu_Y}{\sigma_Y}\big] \\&=\frac{\mbox{Cov}(X, Y)}{\sigma_X \sigma_Y} \\&= \rho \end{aligned}

i.e. the covariance between the standardized random variables represents the correlation between the original random variables(the second term in the second equation above is zero because \mathbb{E}[X] = \mu_X and \mathbb{E}[Y] = \mu_Y).

The trick now is to calculate the variance of the sum of the standardized random variables:

\begin{aligned} \mbox{Var}(x \pm y) &=\mbox{Var}(x) +\mbox{Var}(y) \pm 2\mbox{Cov}(x, y) \\&= 1 + 1 \pm 2\rho \\&= 2(1 \pm \rho) \end{aligned}

Since variance is always non-negative, we must have that -1 \le \rho \le 1 or |\rho| \le 1.

2. A special case: \rho = \pm 1 

When \rho = \pm 1, the last equation reduces to \mbox{Var}(x \pm y) = 0, meaning x \pm y = constant. Converting back to the original variables, this implies:

\begin{aligned} \frac{X - \mu_X}{\sigma_X} \pm \frac{Y - \mu_Y}{\sigma_Y} &=\mbox{constant} \\ \Rightarrow Y &=c\pm \frac{\sigma_Y}{\sigma_X} X \end{aligned}

i.e. when the two random variables are perfectly positively or negatively correlated, they can be written as linear functions of each other. Alternatively, correlation captures a linear relationship between two random variables.

3. \mathbf{\mbox{R}^2 = \rho^2}

Regression coefficient b in a standard linear regression y = a + bx + \epsilon is given by:

\begin{aligned} b &=\dfrac{\sum (x - \bar{x})(y - \bar{y})}{\sum (x - \bar{x})^2} \end{aligned}

with the \mbox{R}^2 given as:

\begin{aligned} \mbox{R}^2 &=\dfrac{\sum (y - \bar{y})^2 - \sum (y - \mathbb{E}[y])^2}{\sum (y - \bar{y})^2}\end{aligned}

The correlation coefficient between x and y is given by:

\begin{aligned} \rho &=\dfrac{\sum (x - \bar{x})(y - \bar{y})}{\sqrt{\sum (x - \bar{x})^2 \sum (y - \bar{y})^2}}\end{aligned}

Noting that \mathbb{E}[y] = a + bx, it is a matter of simple algebra to verify that:

\begin{aligned} \sum (y - \mathbb{E}[y])^2 &=\sum (y - \bar{y})^2 + b^2 \sum (x - \bar{x})^2 - 2b \sum (x - \bar{x})(y - \bar{y})\end{aligned}

Putting the two together, and using the formula for the regression coefficient, b, we have that:

\begin{aligned}\sum (y - \bar{y})^2 - \sum (y - \mathbb{E}[y])^2 &=2b \sum (x - \bar{x})(y - \bar{y}) - b^2 \sum (x - \bar{x})^2\\&= 2 \dfrac{\sum (x - \bar{x})(y - \bar{y})}{\sum (x - \bar{x})^2} \times \sum (x - \bar{x})(y - \bar{y}) \\ &\qquad - \dfrac{\big(\sum (x - \bar{x})(y - \bar{y})\big)^2}{\big(\sum (x - \bar{x})^2\big)^2}\times \sum (x - \bar{x})^2 \\&= \dfrac{\big(\sum (x - \bar{x})(y - \bar{y})\big)^2}{\sum (x - \bar{x})^2}\end{aligned}

(where in the second step above the term \sum (x - \bar{x})^2 cancels off in numerator and denominator, simplifying the expression)

Finally, dividing both sides by \sum (y - \bar{y})^2 gives the definition of \mbox{R}^2 on the LHS and \rho^2 on the RHS, i.e.:

\begin{aligned}\dfrac{\sum (y - \bar{y})^2 - \sum (y - \mathbb{E}[y])^2}{\sum (y - \bar{y})^2} &=\dfrac{\big(\sum (x - \bar{x})(y - \bar{y})\big)^2}{\sum (x - \bar{x})^2\sum (y - \bar{y})^2} \\ \\ \Rightarrow \mbox{R}^2 &= \rho^2 \end{aligned}

(This result also has a more concise and general proof, but uses linear algebra. See, for example, here.)

Written by Vineet

February 15, 2015 at 7:47 pm

Posted in Math: Useful

Tagged with , ,

Simulating Correlated Stochastic Differential Equations (or How to Simulate Heston Stochastic Volatility Model)

leave a comment »

I notice that students new to computational finance often make mistakes in simulating correlated Brownian motion paths. Here is a ready reckoner.

Let’s take the example of generating paths for asset prices using the Heston stochastic volatility model:

\begin{aligned} dS &= rSdt + \sqrt{\nu} S dW_1 \\ d \nu &= \kappa (\theta - \nu) dt + \sigma \sqrt{\nu} dW_2 \end{aligned}

where \nu is the instantaneous variance of asset returns, and the increment in Brownian motions dW_1 and dW_2 are correlated with correlation coefficient \rho, i.e. \langle dW_1, dW_2 \rangle = \rho dt.

The simplest way to generate paths S and \nu is to use the Euler discretization (there are better methods available of course, for Heston in particular) as:

\begin{aligned} ln S(t + \Delta t) &= ln S(t) + r \Delta t - \frac{1}{2} \nu (t) \Delta t + \sqrt{\nu (t)} \epsilon_1 \sqrt{\Delta t} \\ \nu (t + \Delta t) &=\nu (t) + \kappa (\theta - \nu (t) ) \Delta t + \sigma \sqrt{\nu (t)} \epsilon_2 \sqrt{\Delta t} \end{aligned}

where \epsilon_1 and \epsilon_2 are standard Gaussian random variables with correlation \rho

To generate correlated standard Gaussian random variables, i.e. \epsilon_1 and \epsilon_2, the most popular method is to use what is called the Cholesky decomposition. Given two uncorrelated standard Gaussian random variables Z_1 and Z_2 (easily done both in Excel and in R), Cholesky decomposition can be used to generate \epsilon_1 and \epsilon_2 as:

\begin{aligned} \epsilon_1 &= Z_1 \\ \epsilon_2 &= \rho Z_1 + \sqrt{1 - \rho^2} Z_2 \end{aligned}

If, God forbid, your job requires simulating three correlated stochastic differential equations, say when you are using a Double Heston or a Double Lognormal model, then you would need to simulate three jointly correlated Gaussian random variables.

In that case if the correlation structure is \langle dW_1, dW_2 \rangle = \rho_{12} dt\langle dW_2, dW_3 \rangle = \rho_{23} dt and \langle dW_1, dW_3 \rangle = \rho_{13} dt, then given three uncorrelated Gaussian random variables Z_1, Z_2 and Z_3, one could use Cholesky decomposition to generate generate \epsilon_1, \epsilon_2 and \epsilon_3 as:

\begin{aligned} \epsilon_1 &= Z_1 \\ \epsilon_2 &= \rho_{12} Z_1 + \sqrt{1 - \rho^2_{12}} Z_2 \\ \epsilon_3 &=\rho_{13} Z_1 + \rho^*_{23} Z_2 + \rho^*_{33} Z_3\end{aligned}


\displaystyle \rho^*_{23} = \frac{\rho_{23} - \rho_{12} \rho_{13}}{\sqrt{1 - \rho^2_{12}}} and \displaystyle \rho^*_{33} = \sqrt{\frac{1 - \rho^2_{12} - \rho^2_{23} - \rho^2_{13} + 2 \rho_{12} \rho_{23} \rho_{13}}{1 - \rho^2_{12}}}.

Written by Vineet

January 9, 2013 at 7:35 pm