The Claude Quant PlaybookDownload ebookDownload ebook

Two-asset portfolio variance

intermediateRisk and portfolio8 of 13

The risk of a mix of two assets is not the average of their risks. It depends on how they move together: the less correlated they are, the more their ups and downs cancel.

Build a trading system with Claude.Download ebook

01The formula

the volatility of the portfolio
the shares of money in each asset (here w₂ = 1 − w₁)
the volatility of each asset
the correlation between the two assets' returns, from −1 to 1

02See it move

03Where it is used

04Why traders use it

It is the maths behind diversification. Two risky assets can make a portfolio safer than either one alone, but only if their correlation is low enough.

05Worked example

With 60% in an asset with volatility 20% and the rest in one with volatility 30%, at correlation 0.30, the portfolio's volatility is 19.35%. If they were perfectly correlated it would be 24.00%, so diversification removes 4.65%.

06How it is built

  1. The portfolio return is .
  2. The variance of a sum is .
  3. Write the covariance as to get the formula.
  4. It is the law of cosines: arrows of length and at an angle with add up to an arrow of length .

07The common mistake

Adding volatilities instead of variances. Volatilities only add when ; for any lower correlation the portfolio is less risky than the weighted average volatility.

08In Python and LaTeX

import numpy as np
w = np.array([0.6, 0.4])
s1, s2, rho = 0.2, 0.3, 0.3
C = np.array([[s1**2, rho*s1*s2], [rho*s1*s2, s2**2]])
print(round(np.sqrt(w @ C @ w), 4))
\sigma_p^2 = w_1^2\sigma_1^2 + w_2^2\sigma_2^2 + 2\,w_1 w_2\,\rho\,\sigma_1\sigma_2

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.