Aller au contenu

Leçon 22 · Risk and Portfolios

Portfolio Risk and Diversification

Compute portfolio return and risk from weights, volatility and correlation, find a minimum variance mix, and model rebalancing with plain Python.

A portfolio is a set of holdings. Its risk is not simply the average of its parts, because assets do not move in perfect step. This lesson turns that idea into code. The theory is in diversification, and the investing view is in two-asset portfolios.

Nothing here is a recommendation. The numbers are invented to show the method.

Weights and return

A weight is the share of total value in each holding; weights add to 1. The expected portfolio return is the weighted average:

Rp = w1 R1 + w2 R2 + ...

Two-asset risk

For two assets with volatilities s1 and s2 and correlation rho:

variance = w1² s1² + w2² s2² + 2 w1 w2 rho s1 s2

Correlation runs from -1 to 1. With positive weights in both, whenever rho is below 1 the portfolio volatility is lower than the weighted average of the two volatilities.

Python How correlation changes portfolio risk

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The max(var, 0) protects the square root from a tiny negative rounding result.

Many assets: the covariance matrix

With more assets, list every pair's covariance: correlation × both volatilities. Portfolio variance is the sum over all pairs of weight × weight × covariance.

Python Portfolio volatility for three assets

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Risk contributions

A holding's share of risk can differ greatly from its share of money. For asset i, the contribution to variance is its weight times its covariance with the whole portfolio. The contributions add up to the total variance.

Python Money weights versus risk shares

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Here 60% of the money, in stocks, creates the large majority of the risk.

Minimum variance

For two assets, the lowest-variance weight for asset 1 is:

w1 = (s2² - cov) / (s1² + s2² - 2 cov)

The formula can give a weight below 0 or above 1, which would mean short selling or borrowing. A grid search over 0 to 1 avoids that. Portfolios optimized from estimated data can be unstable: small changes in expected returns or correlations may give very different weights. Treat optimizer output as a starting point. See efficient frontier and Sharpe.

Python Grid search for a minimum-variance mix

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Rebalancing

As prices move, weights drift. Rebalancing restores targets, on a schedule or when a limit is passed. It controls risk, but trades may carry fees and taxes.

Python Weight drift and rebalancing trades

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Limits

  • Correlations can rise during crises, just when you want diversification.
  • Diversification cannot remove market-wide risk.
  • Estimates from short histories are noisy.
  • Many similar holdings are not real diversification.

Business finance uses the same logic: a company with one big customer, one supplier or one currency is concentrated.

Where correlations come from

Correlation is estimated from past returns, usually with a chosen window and frequency. A longer window includes more history but may mix very different market conditions. A shorter one reacts faster but is noisier. In Python 3.10 and later, statistics.correlation calculates it for two lists of equal length. Calculate it on returns, not on price levels: two prices that both trend upward can look related even when their returns are not.

Concentration measures

A simple way to see how spread out weights are is the effective number of holdings: 1 divided by the sum of squared weights. Four equal holdings give 4. Weights of 0.7, 0.1, 0.1 and 0.1 give about 1.9, so the portfolio behaves, by weight, much like two holdings. This measure ignores correlation, so ten similar assets can still carry one risk.

Questions before you act on a model

  • What is the money for, and when is it needed?
  • How large a fall could you accept without being forced to sell?
  • Which costs, taxes and limits apply?
  • What happens if correlations rise and returns fall at the same time?

These questions are personal or organizational and a formula cannot answer them. A qualified advisor can help with real investment decisions.

Common mistake: averaging volatilities to get portfolio risk. You need correlations, and you should test what happens if they rise.

A short review routine

Before trusting a portfolio calculation, check five things. The weights add to 1. All volatilities and returns use the same time basis, such as per year. The correlation matrix is symmetric, with ones on the diagonal and values between -1 and 1. A single-asset portfolio returns exactly that asset's volatility. Finally, set every correlation to 1 as a stress case: for positive weights, volatility then equals the weighted average. Note that a hand-edited correlation matrix can be internally impossible and produce a negative variance. If that happens, fix the inputs rather than hiding the problem.

Practice tasks

Try each task on paper or in the editor above before you read the answer. When your result differs, compare definitions first, then timing, then arithmetic.

Task 1. A portfolio has weights of 0.25, 0.25, 0.25 and 0.25. What is its effective number of holdings? What about 0.85, 0.05, 0.05 and 0.05?

Answer: The first gives 1 / 0.25 = 4. The second gives 1 / (0.7225 + 3 x 0.0025) = about 1.37. By weight, the second portfolio is close to a single holding.

Task 2. Two assets each have 20% volatility, equal weights and zero correlation. What is portfolio volatility?

Answer: The variance is 0.25 x 0.04 + 0.25 x 0.04 = 0.02, so volatility is about 14.14%.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. With positive weights, when does portfolio volatility equal the weighted average of two volatilities?

    Perfect positive correlation gives no diversification benefit.
  2. 2. Why can a 60% money weight create more than 60% of the risk?

    Contribution depends on volatility and covariance.
  3. 3. What is a weakness of portfolios optimized from estimated inputs?

    Optimizers are sensitive to estimation error.
  4. 4. Why test higher correlations?

    Diversification can weaken when markets are stressed.

Summary

  • Portfolio return is a weighted average; risk needs covariances.
  • Risk contributions differ from money weights.
  • Optimized weights are fragile and need judgment.
  • Rebalance with costs in mind and stress your correlations.

Next: Simulation and Value at Risk

Votre progression est enregistrée dans ce navigateur. Aucun compte nécessaire.