σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
Calculus skill›Module 2 · Gradients and integrals›Topic 2.3·~45 minIntermediate

Multivariable integrals by Monte Carlo

Skill positionModule 2 of 4 · Topic 3 of 3
2.3 Multivariable integrals by Monte Carlo
—Lab score— / 100Total XP—Streak—

Integrals by sampling

A multiple integral adds up a function over a region, ∬Rf dA\iint_R f\,dA∬R​fdA. Few of them can be solved by hand, yet finance is full of them: the expected payoff of a derivative, the probability of a loss, the price of a basket option are all integrals over many dimensions.

∫Rf dV≈V⋅1N∑i=1Nf(xi)\int_R f\,dV \approx V\cdot\frac{1}{N}\sum_{i=1}^{N} f(\mathbf{x}_i)∫R​fdV≈V⋅N1​i=1∑N​f(xi​)(1)

Monte Carlo estimates the integral by sampling. Draw NNN random points xi\mathbf{x}_ixi​ uniformly in a region of known volume VVV that contains the domain, average fff over them and multiply by VVV. The estimate is itself random, with a standard error σ/N\sigma/\sqrt{N}σ/N​: to cut the error in half you need four times as many points.

Its great advantage is dimension. A grid with 10 points per axis needs 10d10^d10d points in ddd dimensions, which is 101010^{10}1010 for d=10d=10d=10. Monte Carlo's error still shrinks like 1/N1/\sqrt{N}1/N​ whatever ddd is. For areas and volumes it reduces to hit-or-miss: the fraction of random points that land inside the shape, times the volume of the box.

  • Estimate: VVV times the average of fff over uniform random points.
  • Standard error: σ/N\sigma/\sqrt{N}σ/N​; four times the points halve it.
  • Hit-or-miss: area or volume is the fraction of points inside times the box volume.
A volume by hit-or-missThrow random points into the cube [−1,1]3[-1,1]^3[−1,1]3, which has volume 8. A point is inside the unit ball when x2+y2+z2≤1x^2+y^2+z^2\le 1x2+y2+z2≤1. The exact fraction inside is 4π/38=π6≈0.5236\frac{4\pi/3}{8}=\frac{\pi}{6}\approx 0.523684π/3​=6π​≈0.5236, so with 100,000 points about 52,360 fall inside, with standard error p(1−p)/N≈0.0016\sqrt{p(1-p)/N}\approx 0.0016p(1−p)/N​≈0.0016 on the fraction.
The answer changes with the seedTwo runs with different seeds give slightly different estimates, because the estimate is random. Always report the standard error next to the value, and fix the seed when you need a result you can reproduce, as the labs of this course do.

Lab · what's graded

  • An exact double integral15 pts
  • The standard error15 pts
  • How many more points15 pts
  • A volume by hit-or-miss15 pts
  • Why Monte Carlo in many dimensions10 pts
  • The Monte Carlo recipe10 pts
  • Why sampling works20 pts
0/ 7 answered
Tasks
1Numeric answer15 ptsNot answered

Compute ∫01∫01xy dx dy\int_0^1\int_0^1 xy\,dx\,dy∫01​∫01​xydxdy. This is what a Monte Carlo estimate should approach.

I=I =I=accepted: ± 0.001
2Numeric answer15 ptsNot answered

The values f(xi)f(\mathbf{x}_i)f(xi​) have standard deviation σ=0.5\sigma=0.5σ=0.5 and you use N=10,000N=10{,}000N=10,000 points. What is the standard error σ/N\sigma/\sqrt{N}σ/N​ of the average?

SE=SE =SE=accepted: ± 0.0001
3Numeric answer15 ptsNot answered

By what factor must you multiply NNN to cut the standard error to a quarter of its value?

factor=factor =factor=accepted: ± 0.001
4Numeric answer15 ptsNot answered

Random points fill the cube [−1,1]3[-1,1]^3[−1,1]3. What fraction should land inside the unit ball? Give π/6\pi/6π/6 to 4 decimals.

p=p =p=accepted: ± 0.001
5Choice10 ptsNot answered

Why is Monte Carlo preferred to a grid for an integral in 10 dimensions?

6Order the steps10 ptsNot answered

Put the steps of a Monte Carlo integral in order.

Drag to reorder, or focus an item, press Space to lift it, the arrow keys to move it and Space to drop it.

  1. 1Evaluate fff at every point
  2. 2Choose a box of known volume VVV that contains the region
  3. 3Average the values and multiply by VVV
  4. 4Draw NNN random points uniformly in the box
7Explain in words20 ptsNot answered

In two or three sentences, explain how a Monte Carlo estimate is computed, how fast its error shrinks, and why that matters in many dimensions.

Math modeKeyboard or LaTeX inputTask 1 of 7 · Ctrl ⏎ to check

Log in to run your code.

Every lecture is free to read. Create an account or log in to run code, run tests and submit this lab.

  • In-browser IDE with a bash terminal — nothing to install
  • Instant grading, XP and your place on the skill
Create an accountLog in
OR
Continue with GitHub