Skip to content

Lesson 23 ยท Risk and Portfolios

Simulation and Value at Risk

Run seeded Monte Carlo simulations of project value, calculate historical and simulated value at risk and expected shortfall, and learn their limits.

Scenarios test a few chosen futures. Monte Carlo simulation tests thousands, by drawing uncertain inputs at random from distributions you choose and running the model each time. The output is a distribution of results. Its quality depends on your assumptions. For method details, see Monte Carlo Simulation.

Simulate the roaster project

Make the yearly extra earnings and the resale value uncertain. A triangular distribution needs only a low, a high and a most likely value, which suits expert judgment. It is a simple choice, not a law of nature.

Python Monte Carlo NPV

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.

Note the argument order of random.triangular(low, high, mode): the most likely value comes last.

The shared demand value matters. If each year were drawn independently, good and bad years would partly cancel and the risk would look smaller. Dependence between inputs is one of the most important and most neglected parts of a simulation.

The mean can differ from the single base case because the distributions are not symmetric around the most likely values.

Value at risk

Value at risk (VaR) answers: over a set period, at a chosen confidence level, what loss is not exceeded? A 95% one-day VaR of 10,000 means that, under the model, losses are above 10,000 on about 5% of days. It does not say how big losses can be beyond that point.

Expected shortfall (also called conditional VaR) is the average loss in that worst tail.

Python Historical VaR and expected shortfall

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.

There are several percentile conventions, so small differences between tools are normal. State which one you use. With 1,000 observations, the 99% figure rests on only about ten days.

Parametric VaR

A quick method assumes returns follow a normal distribution:

VaR โ‰ˆ value ร— (z ร— volatility - mean)

Python's NormalDist supplies z. Real returns often have fat tails: extreme events happen more often than a normal curve predicts.

Python Compare normal VaR with a fat-tailed sample

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.

Compare the rows. A normal shortcut that looks acceptable at one confidence level can badly understate the far tail.

How many runs?

More runs reduce sampling noise but never fix bad assumptions. Rerun with other seeds; if key results move noticeably, run more. Tail estimates need many more runs than averages.

Good practice

  • Record the seed, number of runs, distributions and dependencies.
  • Base ranges on data or documented judgment.
  • Compare simulation output with a few hand-checked scenarios.
  • Run stress tests with events your data does not contain, such as losing the largest customer.
  • Explain results in plain words, saying "under these assumptions" next to any probability.

Rules and regulation

Banks and other regulated firms follow detailed risk rules that go far beyond these examples, and those rules change. Use this lesson to understand the ideas, not to meet a legal requirement.

Choosing distributions

Distribution Typical use
Uniform Any value in a range seems equally plausible
Triangular You can estimate low, likely and high
Normal Symmetric variation around a center
Lognormal Positive values with a long upper tail

A normal distribution can produce negative values, which makes no sense for quantities such as sales volume. Whatever you choose, plot or summarize the draws and ask whether they look believable.

Checking a simulation

Before trusting results, test the code:

  1. Fix every input at its base value. The simulation must reproduce the deterministic result.
  2. Check that sampled inputs stay inside their allowed ranges.
  3. Change the seed and confirm that key results are stable enough for the decision.
  4. Look at a few extreme runs and trace which inputs caused them.

Backtesting VaR

For a VaR model, count how often actual losses exceeded the forecast. A 95% one-day VaR should be exceeded on roughly 5% of days over a long period, if the model is sound. Far more breaches suggest that risk is understated. Breaches that cluster together suggest the model reacts too slowly to changing conditions.

Common mistakes: treating VaR as the maximum loss; drawing related inputs independently; presenting simulated probabilities as facts; and quoting many decimal places from uncertain assumptions.

Reporting to non-specialists

Show a small table of percentiles, the chance of the outcome that matters and the three assumptions that drive it. Then say what the model leaves out. A reader should understand that a different set of reasonable assumptions could give a noticeably different probability.

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. The five worst daily losses in a sample of 100 days are 9, 8, 6, 5 and 4 (thousands). What are the 95% VaR and expected shortfall under the convention used above?

Answer: The tail has 5 observations. VaR is the fifth-worst loss, 4,000. Expected shortfall is the average of the five, 32 / 5 = 6.4 thousand.

Task 2. Why would you not trust a 99.9% figure from those 100 days?

Answer: The sample is too small: a 1-in-1,000 event may never appear in it. Any such figure depends almost entirely on extra assumptions.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Under the model, a 95% one-day VaR of 10,000 means

    VaR is a threshold, not a maximum.
  2. 2. What does expected shortfall add?

    It describes how bad the bad cases are on average.
  3. 3. Why set a random seed?

    A seed repeats the same random draws.
  4. 4. Drawing five years of demand independently when demand is persistent will likely

    Independent years average out; persistent demand does not.

Summary

  • Simulation turns uncertain inputs into a distribution of results.
  • Model dependence, record seeds and check sampling noise.
  • VaR is a threshold; expected shortfall describes the tail.
  • Assumptions matter more than the number of runs.

Next: Project: Investment Appraisal

Your progress is saved in this browser. No account needed.