Monte Carlo Option Pricing¶
quanta.layer3.monte_carlo ¶
quanta.layer3.monte_carlo — Quantum Monte Carlo via Amplitude Estimation.
Uses quantum amplitude estimation to compute expectations faster than classical Monte Carlo. Key applications: option pricing, risk analysis, and probabilistic inference.
Classical Monte Carlo converges as O(1/√N) with N samples. Quantum amplitude estimation achieves O(1/N) — quadratic speedup.
Pipeline
- Encode probability distribution into quantum state amplitudes
- Apply payoff function as phase rotations
- Use amplitude estimation (Grover-style iterations) to extract expectation
- Classical post-processing for final estimate
Example
from quanta.layer3.monte_carlo import quantum_monte_carlo
Price a European call option¶
result = quantum_monte_carlo( ... distribution="lognormal", ... payoff="european_call", ... params={"S0": 100, "K": 105, "sigma": 0.2, "T": 1.0, "r": 0.05}, ... ) print(result.estimated_value)
GreeksResult
dataclass
¶
Option Greeks (sensitivities).
Attributes:
| Name | Type | Description |
|---|---|---|
delta |
float
|
Price sensitivity to spot (∂V/∂S). |
gamma |
float
|
Delta sensitivity to spot (∂²V/∂S²). |
vega |
float
|
Price sensitivity to volatility (∂V/∂σ). |
theta |
float
|
Price sensitivity to time (∂V/∂T). |
rho |
float
|
Price sensitivity to interest rate (∂V/∂r). |
Source code in quanta/layer3/monte_carlo.py
MonteCarloResult
dataclass
¶
Result of Quantum Monte Carlo estimation.
Attributes:
| Name | Type | Description |
|---|---|---|
estimated_value |
float
|
Estimated expectation value. |
classical_value |
float
|
Classical Monte Carlo estimate for comparison. |
confidence_interval |
tuple[float, float]
|
(lower, upper) bounds. |
num_qubits |
int
|
Qubits used for encoding. |
grover_iterations |
int
|
Amplitude estimation iterations. |
speedup_factor |
float
|
Theoretical quantum speedup achieved. |
Source code in quanta/layer3/monte_carlo.py
amplitude_estimate ¶
amplitude_estimate(
probs: ndarray,
payoffs: ndarray,
n_qubits: int,
n_estimation: int = 4,
seed: int | None = None,
) -> tuple[float, int]
Quantum amplitude estimation (Brassard-Hoyer-Mosca-Tapp).
Estimates a = E[f(X)] = Σ p(x)·f̃(x) using quantum circuits.
Circuit structure
- Prepare |ψ⟩ = Σ √p(x)|x⟩ on data register
- Controlled-R_y on ancilla: encodes f̃(x) as P(ancilla=|1⟩|x⟩) Result: Σ √p(x)[√f̃(x)|1⟩ + √(1-f̃(x))|0⟩]|x⟩
- P(ancilla=|1⟩) = Σ p(x)·f̃(x) = a (the target expectation)
- Iterative Grover amplification refines the estimate
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
probs
|
ndarray
|
Probability distribution (2^n_qubits,). |
required |
payoffs
|
ndarray
|
Payoff values per state (2^n_qubits,). |
required |
n_qubits
|
int
|
Number of qubits encoding the distribution. |
required |
n_estimation
|
int
|
Number of Grover power rounds (precision). |
4
|
seed
|
int | None
|
Random seed. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[float, int]
|
(estimated_expectation, total_grover_iterations). |
Source code in quanta/layer3/monte_carlo.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
compute_greeks ¶
compute_greeks(
spot: float = 100.0,
strike: float = 105.0,
volatility: float = 0.2,
rate: float = 0.05,
time_to_expiry: float = 1.0,
payoff: str = "european_call",
n_samples: int = 100000,
seed: int = 42,
) -> GreeksResult
Compute option Greeks using finite-difference Monte Carlo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spot
|
float
|
Current asset price (S0). |
100.0
|
strike
|
float
|
Strike price (K). |
105.0
|
volatility
|
float
|
Annualized volatility (σ). |
0.2
|
rate
|
float
|
Risk-free interest rate (r). |
0.05
|
time_to_expiry
|
float
|
Time to expiry in years (T). |
1.0
|
payoff
|
str
|
"european_call" or "european_put". |
'european_call'
|
n_samples
|
int
|
Number of classical MC samples. |
100000
|
seed
|
int
|
Random seed. |
42
|
Returns:
| Type | Description |
|---|---|
GreeksResult
|
GreeksResult with delta, gamma, vega, theta, rho. |
Example
from quanta.layer3.monte_carlo import compute_greeks g = compute_greeks(spot=100, strike=105, volatility=0.2) print(g.summary())
Source code in quanta/layer3/monte_carlo.py
quantum_monte_carlo ¶
quantum_monte_carlo(
distribution: str = "lognormal",
payoff: str = "european_call",
params: dict | None = None,
n_qubits: int = 6,
n_estimation: int = 4,
n_classical: int = 100000,
seed: int | None = None,
) -> MonteCarloResult
Quantum Monte Carlo estimation using amplitude estimation.
Estimates E[f(X)] where X follows a probability distribution and f is a payoff function. Uses quantum amplitude estimation for quadratic speedup over classical Monte Carlo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distribution
|
str
|
Probability distribution type. Options: "lognormal", "normal", "uniform". |
'lognormal'
|
payoff
|
str
|
Payoff function type. Options: "european_call", "european_put", "expectation", "var". |
'european_call'
|
params
|
dict | None
|
Distribution and payoff parameters. For lognormal/options: S0, K, sigma, T, r. For normal: mean, std. |
None
|
n_qubits
|
int
|
Qubits for distribution encoding (precision). |
6
|
n_estimation
|
int
|
Estimation register qubits (accuracy). |
4
|
n_classical
|
int
|
Classical Monte Carlo samples for comparison. |
100000
|
seed
|
int | None
|
Random seed. |
None
|
Returns:
| Type | Description |
|---|---|
MonteCarloResult
|
MonteCarloResult with quantum and classical estimates. |
Example
result = quantum_monte_carlo( ... distribution="lognormal", ... payoff="european_call", ... params={"S0": 100, "K": 105, "sigma": 0.2, "T": 1.0, "r": 0.05}, ... ) print(result.estimated_value)
Source code in quanta/layer3/monte_carlo.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |