The Claude Quant PlaybookDownload ebookDownload ebook

Correlation

intermediateProbability10 of 12

Correlation is covariance with the units taken out. It runs from −1 (perfectly opposite) through 0 (no straight-line link) to 1 (moving perfectly together).

Build a trading system with Claude.Download ebook

01The formula

the correlation between X and Y
their covariance
their standard deviations

02See it move

03Where it is used

04Why traders use it

It is the number that tells you how much diversification you really have, and the simplest test of whether a signal and a return are related at all.

05Worked example

Two standardised returns with true correlation 0.60: in a sample of 400 points the measured correlation is 0.651. A correlation of 0.60 means the shared part explains 36% of each one's variance.

06How it is built

  1. Start with the covariance, which has awkward units (X's units times Y's).
  2. Divide by both standard deviations to remove the units.
  3. By the Cauchy–Schwarz inequality, , so the result lies between −1 and 1.
  4. Squared, is the share of one variable's variance that a straight line through the other explains.

07The common mistake

Taking zero correlation to mean no relationship. Correlation only sees straight-line links: a return and its square can be strongly dependent with zero correlation. And correlation measured in calm markets often jumps in a crisis.

08In Python and LaTeX

import numpy as np
rng = np.random.default_rng(7)
rho, n = 0.6, 400
z1, z2 = rng.standard_normal((2, n))
x, y = z1, rho * z1 + np.sqrt(1 - rho**2) * z2
r = np.cov(x, y)[0, 1] / (x.std(ddof=1) * y.std(ddof=1))
print(np.isclose(r, np.corrcoef(x, y)[0, 1]), 'shared variance:', round(rho**2, 2))  # True 0.36
\rho_{XY} = \frac{\text{Cov}(X, Y)}{\sigma_X\,\sigma_Y}, \qquad -1 \le \rho_{XY} \le 1

09Where it fits

Rather not code the maths yourself? Describe your trading idea and let AI build the bot.

Build a bot with AgenKit

The worked example and the model run the same code, so every number matches. Models simplify markets on purpose. This is education, not financial advice.