Quant Memo
Coding/●●●●●

Estimate pi by Monte Carlo

Asked at Jane Street

Estimate π\pi by simulation: sample points uniformly in the unit square [0,1]2[0,1]^2 and count how many land inside the quarter circle x2+y21x^2 + y^2 \le 1. The quarter circle has area π/4\pi/4, so

π4#insiden\pi \approx 4 \cdot \frac{\#\text{inside}}{n}

estimate_pi(1_000_000)  ->  3.1418... (varies by seed)

Write the estimator, then answer: how many samples do you need for roughly 3 correct decimal places?

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions