Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Avhz RustQuant MonteCarloPricer price monte carlo

From Leeroopedia


Knowledge Sources
Domains Monte_Carlo, Option_Pricing, Numerical_Methods
Last Updated 2026-02-07 20:00 GMT

Overview

Concrete tool for pricing options via Monte Carlo simulation provided by the RustQuant instruments crate.

Description

The MonteCarloPricer trait defines a single method price_monte_carlo that takes a stochastic process, simulation configuration, and risk-free rate, then returns a discounted average payoff. The impl_monte_carlo_pricer! macro implements this trait for multiple option types, automatically handling path-dependent vs path-independent payoffs.

Path-independent options (vanilla, power, binary) use only the terminal path value. Path-dependent options (Asian, barrier) receive the full path vector.

Usage

Call price_monte_carlo on any option struct that implements the MonteCarloPricer trait. Requires a pre-configured stochastic process and simulation config.

Code Reference

Source Location

  • Repository: RustQuant
  • File: crates/RustQuant_instruments/src/monte_carlo_pricer.rs
  • Lines: L16-82

Signature

pub trait MonteCarloPricer<S>: Payoff
where
    S: StochasticProcess,
{
    fn price_monte_carlo(
        &self,
        process: &S,
        config: &StochasticProcessConfig,
        rate: f64,
    ) -> f64;
}

// Automatically implemented for:
// EuropeanVanillaOption, AsianOption, BarrierOption,
// PowerOption, PoweredOption, CappedPowerOption,
// BinaryOption, SupershareOption, LogOption, etc.

Import

use RustQuant::instruments::MonteCarloPricer;

I/O Contract

Inputs

Name Type Required Description
self impl MonteCarloPricer Yes The option to price (must implement Payoff)
process &S where S: StochasticProcess Yes The stochastic process for path generation
config &StochasticProcessConfig Yes Simulation parameters (paths, steps, scheme, etc.)
rate f64 Yes Risk-free rate for discounting

Outputs

Name Type Description
return f64 Discounted expected payoff (Monte Carlo price estimate)

Usage Examples

Pricing a European Vanilla Option

use RustQuant::instruments::{
    EuropeanVanillaOption, MonteCarloPricer, TypeFlag,
};
use RustQuant::stochastics::{
    GeometricBrownianMotion, StochasticProcessConfig, StochasticScheme,
};
use time::macros::date;

let option = EuropeanVanillaOption::new(100.0, date!(2025 - 12 - 31), TypeFlag::Call);
let process = GeometricBrownianMotion::new(0.05, 0.20);
let config = StochasticProcessConfig::new(
    100.0, 0.0, 1.0, 1,
    StochasticScheme::EulerMaruyama,
    1_000_000, true, None,
);

let price = option.price_monte_carlo(&process, &config, 0.05);
println!("MC Price: {:.4}", price);

Pricing an Asian Option

use RustQuant::instruments::{
    AsianOption, MonteCarloPricer, AveragingMethod,
    OptionContractBuilder, TypeFlag, ExerciseFlag, StrikeFlag,
};
use RustQuant::stochastics::{
    GeometricBrownianMotion, StochasticProcessConfig, StochasticScheme,
};
use time::macros::date;

let contract = OptionContractBuilder::default()
    .type_flag(TypeFlag::Call)
    .exercise_flag(ExerciseFlag::European { expiry: date!(2025 - 12 - 31) })
    .strike_flag(Some(StrikeFlag::Fixed))
    .build()
    .unwrap();

let option = AsianOption::new(contract, AveragingMethod::ArithmeticDiscrete, Some(100.0));
let process = GeometricBrownianMotion::new(0.05, 0.20);
let config = StochasticProcessConfig::new(
    100.0, 0.0, 1.0, 252,
    StochasticScheme::EulerMaruyama,
    100_000, true, None,
);

let price = option.price_monte_carlo(&process, &config, 0.05);
println!("Asian MC Price: {:.4}", price);

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment