Your first simulationLesson 03 of 76 · 6 min

Repeat the whole experiment

Build a repeated simulation without mixing inputs from different trials.

A Monte Carlo estimate averages a quantity calculated from random inputs. First define it for one complete trial, then repeat that rule. An indicator is 1 when a condition holds and 0 otherwise; averaging a loss indicator estimates the chance of a loss.

Here each event has attendance, ticket revenue and a fixed venue cost. Profit is revenue minus cost. NumPy applies the arithmetic entry by entry, keeping each count attached to its revenue. A sample mean adds all profits and divides by the number of events. Its target, expectation, is the average weighted by the model's outcome probabilities.

The code also reports percentiles: P10 and P90 are cutoffs with roughly 10% and 90% of outcomes at or below them. P50 is the median, the middle of the ordered outcomes. Finite-sample cutoffs may interpolate between values; the next lesson makes that visible. A positive expected profit can coexist with a substantial loss chance, so inspect both.

In the illustration, Π\Pi denotes profit, E means model expectation and P means probability. P(Π<0)P(\Pi<0) reads ‘the chance that profit is negative’.

One world, one profit
  1. Sample together

    customers, spending, costs

  2. Calculate in that world
    Π=revenue−cost\Pi=\text{revenue}-\text{cost}
  3. Summarise complete worlds
    E[Π],P(Π<0)E[\Pi],\quad P(\Pi<0)
Reference illustration. Keep every input for a trial together. Expected profit and the chance of a loss are different summaries of the same authored outcome model.

Can an event have positive average profit and still lose money in some trials?

Write a prediction (optional)

Seeded teaching simulation

Select Run Python below with the code unchanged.

Tools
About Python ↗

The code is editable. Press Ctrl+Enter or ⌘+Enter to run Python from the editor.

Published example output

This result comes from the original Python. Your runs appear above. Build environment ↗

Estimated mean profit (£): 74.8
Estimated P(loss): 0.1668
Profit percentiles 10/50/90 (£): [-50.  75. 200.]

Read the first result

Read Estimated mean profit (£) alongside Estimated P(loss). The first averages the profit across all events. The second gives the fraction of events with negative profit.

Try an edit

Replace ticket_price, fixed_cost = 25, 900 with ticket_price, fixed_cost = 25, 1000. Select Run Python again. Compare Estimated mean profit (£), Profit percentiles 10/50/90 (£) and Estimated P(loss). What happens to profits when every simulated event pays £100 more?

Back to the Python editor

Scope. Ticket price and venue cost are fixed teaching assumptions. The model omits refunds, variable expenses and selection effects.

Try a fresh case

Two plans have the same mean profit. What else would inform a choice?

Choose an answer
Need a hint?
Hint 1

Imagine one plan frequently makes a small gain and occasionally a large loss.

Hint 2

Inspect the distribution relevant to the decision.

Your notes