Introduction to Quant Finance · Lesson 25
Getting in, and what to learn next
Three classic puzzles of the kind quant interviews use, each worked out by hand and checked by simulation, then a map of what to study next.
Know the basics? Read the lesson notesWhat this lesson is, and what it isn't
A quant (short for quantitative analyst) uses maths, statistics and code to answer questions about markets and money. The lesson What quants do maps the jobs. This last lesson works three puzzles of the kind their interviews use, then shows what to study next.
Interview guides often cover a few kinds of question. The mix differs by firm and by job. Turn the five over: this course has already used each one.
- Probability and averages
How likely something is, and what it gives on average over many tries.
- Statistics
How far luck moves an average measured on a few tries.
- Quick arithmetic and puzzles
Working a problem out in your head or on paper, out loud. The three problems in this lesson are of this kind.
- Coding
Every number in this course comes from a short Python script, shown at the end of its lesson.
- Markets and prices
What a price is, how orders fill, what trading costs, and options for jobs that price them.
Problem 1: two heads in a row
A coin is fair when heads and tails each come up half the time, whatever came before. Flip one until you get two heads, one straight after the other. Then start again, and again, many times.
On average, how many flips does a round take? (The average: add up every round's flips and divide by the number of rounds.)
Two heads: flip, reason, check
Flip until two heads in a row, three rounds. Your flips are the first three rounds of a seeded simulation: random draws by a computer from a fixed starting number, the seed, so every reader gets the same ones.
Round 1 of 3 · flips 0
Your rounds took 7, 10 and 3 flips: 6.67 on average. Three rounds are far too few to settle an average (the Sample size lesson). So reason it out.
Only two situations matter. Call E the average number of flips still needed at the start; a tail puts you back there, since it wipes out any head before it. Call EH the average still needed just after a head.
At the start you make one flip. Half the time it is a head and you need EH more; half the time a tail and you need E more: E = 1 + ½EH + ½E. Just after a head you make one flip. A head finishes the round; a tail sends you back: EH = 1 + ½ × 0 + ½E.
Put the second into the first: E = 1 + ½ × (1 + ½E) + ½E = 1.5 + ¾E. So ¼E = 1.5, and E = 6. Now check it.
Flips needed in each of 10,000 rounds (simulated)
Bars: how many rounds took 2, 3, 4… flips; the last bar holds 25 or more. Line: the rounds' average.
The 10,000 rounds averaged 6.00 flips, as worked out: the answer to the guess is C, 6. About a quarter of rounds ended at 2 flips (2,499), since two heads straight away has chance ½ × ½. Others ran long, one to 42 flips, and those pull the average above the most common count.
Average waiting time, one try at a time
The method you just used is first-step analysis. Name the situations that decide what can happen next, the states. For each, the average waiting time is one try, plus each outcome's chance times the average waiting time from where it lands you. Then solve the equations. The answer is the expected waiting time: the average number of tries over very many rounds.
- s, j
- states: the situations that decide what can happen next
- Es
- the expected waiting time from state s: the average number of tries still needed
- ps→j
- the chance that one try takes you from state s to state j
- Σj
- add up over every state j
- p
- the chance of the event on each try
Two heads: E = 1 + ½EH + ½E and EH = 1 + ½E, so E = 6; the simulation's 10,000 rounds averaged 6.00. One event: a die rolled until the first six has p = 1/6, so E = 1 ÷ (1/6) = 6 rolls.
- each try's chances are fixed in advance;
- the past matters only through the state you are in (a fair coin's earlier flips don't change the next one);
- the goal is sure to be reached in the end.
Chances drift from try to try, or depend on more of the past than the states hold. Then the equations give a wrong answer unless more states are added. Real trades can drift like this: the Quant Research course, coming, is planned to cover this.
New pattern. Flip a fair coin until a head is followed straight away by a tail. On average, how many flips?
Problem 2: a shared birthday
A group of 30 people. Take every birthday to be one of 365 days, each day equally likely, with no twins in the group. What is the chance that at least two of the 30 share a birthday?
This classic is the birthday problem. A simulation can check it directly, the way the lesson Monte Carlo answers a question: simulate it many times and count.
Birthdays: count the pairs, then check
About 8% is 30 ÷ 365, roughly the chance that someone shares your birthday. The question asks about any two people, and 30 people make 30 × 29 ÷ 2 = 435 pairs. Each pair is a chance of a match.
For the exact answer, add people one at a time and work out the chance of no match. The second person misses the first one's day with chance 364/365, the third misses both with chance 363/365, and so on. Multiply these. One minus the product is the chance of at least one match. Slide up to 30 people.
Chance that at least two share a birthday (exact)
365 equally likely days. Dashed line: a chance of one half.
At 30 people the chance of no shared day is 29.4%, so the chance of at least one is 100 − 29.4 = 70.6%: the answer to the guess is C. The chance first passes one half at 23 people (50.7%). Now check it.
In group 1, persons 9 and 10 share day 317 of the year. Across the groups, 71.0% against the exact 70.6%. From the Sample size lesson: a share counted over 10,000 tries usually lands within about 100 ÷ √10,000 = 1 point of the true chance, so a gap of 0.4 points is what luck alone leaves.
Problem 3: €3, a fair coin and two exits
You start with €3 and bet €1 on each flip of a fair coin: heads wins €1, tails loses €1. You stop when you reach €10, or when you are down to €0 and broke. What is the chance you reach €10?
This classic is gambler's ruin, the cousin of the Ruin lesson.
€3 to €10: play, reason, check
Play one game: flip until you reach €10 or €0. It is game 1 of the simulation.
Your money after each flip (game 1, simulated)
Dashed lines: the two exits, €10 and €0.
Game 1 went broke after 19 flips. One game can't show a chance, so reason it out, with the Ruin lesson's point. Each bet averages €0 (half the time +€1, half −€1), so your money on average stays at the €3 you started with; it ends at €0 or €10, so 10 × q = 3 and the chance of €10 is q = 3 ÷ 10 = 30%.
The answer to the guess is B. This needs the game to be sure to end, with your money kept between €0 and €10 on the way, which it is here.
29.2% against the exact 30%: within the Sample size lesson's 1 point for 10,000 tries. The same argument gives start ÷ target for any fair game like this one: the nearer the start is to €0, the likelier the ruin.
What to learn next
This course is the first of several. Pick a kind of quant job to see one path through the courses that follow. The paths are suggestions: each course stands on its own. A course marked "coming" is planned and not yet written, with no date set.
Maths for Quants helps on every path. Another course, Testing Popular Ideas (open), tests well-known trading ideas the same way, for readers who trade their own account; that is not a quant job.
What the course gives you, and what it doesn't
This course teaches ideas and habits: guess first, work it out, check it by counting many simulated tries, and state each answer with the condition it needs. It is not a qualification, and it won't get anyone a job by itself; firms hire on their own criteria, which differ and change.
Which habit from this lesson will you keep?
Two sixes in a row
On average, how many rolls does that take?
Hint: two states, as for two heads: at the start (where any roll that isn't a six puts you), and just after a six. Write one equation for each, then put the second into the first.
"With 10 people it can't happen"
What is the chance that at least two of the 10 share a birthday?
Bigger bets
What is the chance you reach €20, in percent?
Lesson done
Three classics, each worked by hand and checked by simulation. With a fair coin, two heads in a row take 6 flips on average. With 365 equally likely days, 30 people share a birthday with chance 70.6%. With fair €1 bets, €3 reaches €10 before €0 with chance 30%. Each answer needs its condition: for the last one, each bet averages €0, so the money on average stays at €3, and it ends at €0 or €10, so the chance of €10 is 3 ÷ 10. This course teaches habits like these; it is not a qualification and won't get anyone a job by itself.
Next: pick one path from the map of courses. Re-running the check on each new answer is the dull part, and it is the habit that matters.
Key ideas
- Quant
- someone who uses maths, statistics and code on questions about markets and money
- First-step analysis
- one equation per state: one try, plus each outcome's chance times the average wait from where it lands
- Expected waiting time
- the average number of tries until something happens, over very many rounds
- Birthday problem
- the chance that at least two people in a group share a birthday
- Gambler's ruin
- the chance of reaching a target before going broke, betting a fixed amount on each flip
Formulas
first-step analysis: Es = 1 + Σj ps→j × Ej, E = 0 at the goal · one event with chance p each try: E = 1 ÷ p
shared birthday among n: 1 − (365 × 364 × … × (365 − n + 1)) ÷ 365n · fair game: chance of the target = start ÷ target
Conditions: chances fixed in advance, the past mattering only through the state, and a goal sure to be reached; for birthdays, 365 equally likely days, no twins; for the fair game, bets that average zero, stopping only at €0 or the target, landing exactly on either.