跳到正文

第 21 课 · Risk and Portfolios

Measuring Return and Risk

Calculate simple and compound returns, volatility, annualization, drawdown and Sharpe ratio from price data, and learn the limits of each measure.

Before you manage risk, you must measure it. This lesson turns a series of prices into the numbers analysts often use, with only the Python standard library. All prices here are invented. For theory, see risk, return and variance.

Simple returns

A simple return for one period is:

r = (ending price + income - starting price) / starting price

Income includes dividends. If your price data ignores dividends, your returns are too low for assets that pay them. Many data sources offer adjusted prices; check how they handle dividends and share splits.

Compounding returns over time

Do not add returns. Multiply growth factors:

total return = (1 + r1)(1 + r2)...(1 + rn) - 1

The geometric mean is the constant rate that gives the same total. The arithmetic mean is the simple average. The geometric mean is never larger.

Python Why averaging returns misleads

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 average is zero, yet you lost a quarter of your money.

Volatility

Volatility is usually the standard deviation of returns. It measures how widely results spread around their average. To compare periods, analysts annualize it by multiplying by the square root of the number of periods per year (12 for monthly data). That rule assumes returns are roughly uncorrelated over time with stable variability, which real markets may not follow.

Python Monthly prices to annual figures

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.

stdev is the sample standard deviation (it divides by n - 1), the usual choice when you estimate from data. Twelve observations are very few; estimates like these are noisy.

Drawdown

Volatility counts upward moves too. Drawdown measures the fall from a previous peak. Maximum drawdown is the worst such fall, which is close to how losses feel.

Python Maximum drawdown and recovery

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.

Losses and gains are not symmetric: after a 50% fall you need a 100% gain to recover.

Risk-adjusted return

The Sharpe ratio compares the return above a risk-free rate with volatility:

Sharpe = (return - risk-free rate) / volatility

All three must use the same time basis. There are several calculation variants, so state yours. The Sortino ratio uses only downside variation. Neither captures everything: a strategy can show a high Sharpe ratio for years and then lose heavily in one rare event.

What volatility misses

Risks a standard deviation can miss

Rare big losses Extremes can beat simple models
Liquidity You may not be able to sell
Changing links Assets can fall together
Permanent loss A business can fail
1 / 2

Data hygiene

  • Check that dates are in order, without gaps or duplicates.
  • Look for jumps caused by share splits or data errors.
  • Beware survivorship bias: studying only companies that still exist flatters the past.
  • Do not choose the time window to get the answer you like. Show results for several windows.

Choosing a return frequency

Daily data gives many observations but contains more noise, and some assets trade rarely, which can make their risk look lower than it is. Monthly data is smoother but gives fewer points. Choose the frequency that fits the decision, and never compare volatilities computed from different methods without saying so.

A Sharpe example

Suppose a made-up investment earned 9% over a year, the risk-free rate was 3% and annualized volatility was 12%. The Sharpe ratio is (9% - 3%) / 12% = 0.5. Another investment that earned 12% with 24% volatility has a ratio of 0.375. It earned more, but with more variation per unit of extra return. With short histories, differences like this can easily be chance.

Log returns

You may also meet log returns, calculated as the natural logarithm of the price ratio. They add across time, which simplifies some mathematics. They differ from simple returns, especially for large moves, and they do not add across assets in a portfolio the way weighted simple returns do. Keep the two types separate and label them.

Business uses

These ideas apply beyond investing. You can measure how much monthly sales vary, how far cash has fallen from a recent peak or how unstable a supplier price has been. The same warning applies: a calm past does not promise a calm future.

Common mistakes: adding period returns instead of compounding, annualizing with the wrong factor, mixing monthly returns with an annual risk-free rate, and assuming past volatility describes the future.

Past performance does not guarantee future results. These tools describe data; they do not tell you what to buy.

Reporting the numbers

Always state the period, the number of observations, the return frequency, whether income is included and how you annualized. Two reports that omit these details can disagree even when both calculations are correct.

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 price goes from 80 to 88 and pays a dividend of 2 during the period. What is the simple return?

Answer: (88 - 80 + 2) / 80 = 12.5%.

Task 2. A value falls from a peak of 200 to 150. What is the drawdown, and what gain recovers it?

Answer: The drawdown is -25%. Recovery from 150 to 200 needs a gain of about 33.3%.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. Returns are +20% then -20%. The total return is

    1.2 x 0.8 = 0.96, a 4% loss.
  2. 2. Under the usual assumptions, you annualize monthly volatility by multiplying by

    Variance scales with time, so the standard deviation scales with its square root.
  3. 3. What does maximum drawdown measure?

    It is the worst fall from a previous high.
  4. 4. What is survivorship bias?

    Failed firms drop out of the data and their losses vanish.

Summary

  • Include income, and compound returns instead of adding them.
  • Volatility measures spread; annualizing rests on assumptions.
  • Drawdown shows the depth of losses and the recovery needed.
  • Risk-adjusted ratios help comparison but miss rare and liquidity risks.

Next: Portfolio Risk and Diversification

你的学习进度保存在此浏览器中,无需账号。