LIVE·WAITING…
connecting to the live quote stream…
--:--:--UTC
#15
Monte Carlo VaR
mediumQuantacceptance —~25 min
Implement mc_var(S, mu, sigma, days, n, seed, alpha) — a Monte Carlo value-at-risk. Call random.seed(seed), then for each of n paths draw one random.gauss(0, 1) per day and step S·exp((mu - sigma²/2)·dt + sigma·sqrt(dt)·z) with dt = 1/252, for days steps. VaR is the loss S - S_T at the alpha quantile: sort the losses descending and take index int(alpha·n).
It is the risk desk's morning number, and the workbench's Monte Carlo VaR bot. Return VaR as a fraction of S rounded to 4 decimal places.
example 1
input
S=100.0, mu=0.05, sigma=0.2, days=1, n=2000, seed=7, alpha=0.05
output
0.0218
example 2
input
S=100.0, mu=0.05, sigma=0.2, days=10, n=2000, seed=7, alpha=0.05
output
0.0622
constraints
- S > 0
- 1 ≤ days ≤ 60
- 100 ≤ n ≤ 20_000
- 0 < alpha < 0.5
teacher · 2 hints · the first is free
↗ read the theory
the chapter this problem is cut from
▶ open in the workbench
run the same math on a real tape
●solution.py· utf-8 · spaces:4
ln 1, col 1tab indent · esc leave editor
python 3.13 · pyodide
+ 6 hidden on submit
input · keyword arguments to mc_var()
S=100.0, mu=0.05, sigma=0.2, days=1, n=2000, seed=7, alpha=0.05
expected
0.0218
the judge calls mc_var() with exactly these inputs · outputs are compared to 6 decimal places
● standing bypython 3.13 in your browser · pyodide 0.28.3 · judged on the server to 6 dp⌘↵ run · ⌘⇧↵ submit
paper only · educational · not advice