Building Flexible Derivatives Pricing Models with Monte Carlo and PDE Solvers

DolphinDB
2026-11-05

Pricing a vanilla European option is easy. Pricing everything else is where quants lose their weekends.

Asian options need observation dates and historical fixings. Barrier products need to know whether the price ever touched a level. Add stochastic volatility or multiple assets, and you're suddenly carrying extra state variables through every step of your model.

For these use cases, DolphinDB provides two general-purpose pricing toolkits that let developers focus on financial models and product logic rather than implementing numerical solvers from scratch:

  • Monte Carlo: Simulate stochastic paths, define custom payoff logic, and obtain statistical estimates with standard errors and confidence intervals.
  • PDE solvers: Solve 1D and 2D linear parabolic PDEs to generate full price curves or surfaces, with interpolated values and Greeks.

This article walks through both toolkits with practical examples, compares their performance against Python, QuantLib, and PriceLib, and discusses how to choose and validate a pricing method in real-world applications.

In this post

  1. Monte Carlo: build path-dependent pricing models flexibly
  2. pdeSolver: one solve, the whole price surface
  3. Performance benchmarks
  4. How to choose and validate a pricing method in practice
  5. What this unlocks, and where we're heading

1. Monte Carlo: Build Path-Dependent Pricing Models Flexibly

For Asian and barrier options, the payoff depends not just on the terminal price but on how the underlying got there. To price them, you simulate the asset's random paths, compute the payoff under the product terms, and estimate the price statistically.

Writing that pipeline from scratch every time means re-implementing random number generation, correlation handling, batch computation and statistical aggregation again and again. But look closely, and products differ in just two ways:

  1. How the underlying state evolves
  2. When, and how much, the product pays

Path simulation and statistical estimation can be reused. DolphinDB's Monte Carlo toolkit is designed around exactly this idea: you define state evolution and payoff logic as custom functions, and the toolkit orchestrates everything else.

Core capabilities

Three functions do the heavy lifting:

  • mcSimulate: simulates stochastic processes and generates paths.
  • monteCarlo: combines your evolution function, payoff function and simulation settings into a complete Monte Carlo pricing run.
  • mcEstimate: produces statistical estimates from simulation output.

Two workflows cover most needs:

  • Research and debugging: generate paths with mcSimulate, inspect them, apply custom processing, then estimate with mcEstimate. It's ideal for checking intermediate results, though storing full paths can consume significant memory.
  • Production pricing: call monteCarlo directly. It advances the simulation in batches and aggregates results internally, which suits high-volume numerical estimation with a fixed payoff.

The core product-specific logic is captured in two functions: evolve and payoff. European, Asian, barrier, lookback and multi-asset options can all be defined on top of the same simulation framework. For stochastic volatility models, simply include volatility as an extra state variable in the simulation.

Example: an Asian option under GBM

Assume the underlying follows geometric Brownian motion (GBM). First, define how the price evolves:

def gbmEvolve(t, state, dt, noise, p) {
    drift = (p["r"] - p["q"] - 0.5 * p["sigma"] * p["sigma"]) * dt
    return state * exp(drift + p["sigma"] * sqrt(dt) * noise)
}

Next, define the payoff. This example prices both the arithmetic-average and geometric-average Asian call in a single pass:

def asianPayoff(paths, timeGrid, p) {
    n = rows(paths[0])
    m = size(paths) - 1
    prices = matrix(DOUBLE, n, m)
    for (i in 1..m) {
        prices[, i - 1] = paths[i][, 0]
    }
    arithmeticAverage = rowAvg(prices)
    geometricAverage = exp(rowAvg(log(prices)))
    T = timeGrid[size(timeGrid) - 1] - timeGrid[0]
    df = exp(-p["r"] * T)
    return df * matrix(max(arithmeticAverage - p["K"], 0.0),
                       max(geometricAverage - p["K"], 0.0))
}

Then run the pricing with the initial price, time grid, number of paths and model parameters:

res = monteCarlo(gbmEvolve, asianPayoff, 100.0,
    0..12 / 12.0, 100000, 1, p, opt)

gbmEvolve and asianPayoff carry your model logic. The remaining arguments set the initial state, simulation horizon, scale and configuration. The toolkit handles simulation and estimation, and returns the price estimate along with its standard error.

The takeaway: when product terms change, you only rewrite evolve and payoff. The simulation and estimation machinery stays untouched.

2. pdeSolver: One Solve, the Whole Price Surface

For European options, analytical solutions are available under standard assumptions. American options are more challenging because their value depends not only on the underlying price and time, but also on the optimal exercise decision at each point before maturity.

This makes PDE methods particularly useful: instead of computing a single price, they solve the pricing equation across a discretized space-time grid, producing a price curve or surface. The same framework can accommodate early-exercise constraints, different boundary conditions, time-dependent parameters, and more complex payoff structures.

Core capabilities

DolphinDB's pdeSolver family solves 1D and 2D linear parabolic PDEs, with support for:

  • Flexible PDE coefficients: configure diffusion, convection, reaction and source terms as constants or as functions of price and time (e.g., local volatility).
  • Grids and boundaries: uniform grids and non-uniform sinh/tanh/log grids (refine around the strike or barrier), plus Dirichlet, Neumann and Robin boundary conditions.
  • Time-Stepping Schemes: explicit, implicit Euler, Crank–Nicolson and Theta schemes, with Rannacher smoothing to suppress oscillations on discontinuous payoffs.
  • Early-Exercise Constraints: American options are expressed through an obstacle configuration, with both PSOR and Penalty solution paths.
  • 2D problems: ADI methods (Douglas, CS, MCS, HV) for models with cross-derivative terms, such as Heston, Basket and Exchange options.
  • Pricing Results & Diagnostics: prices, interpolated values at specified points, Delta, Gamma and other Greeks, plus convergence and iteration diagnostics.

You describe the financial model by configuring the equation, terminal condition, boundary conditions and numerical parameters. You never implement the PDE algorithm itself.

Example: an American put

Spot 100, strike 100, risk-free rate 5%, volatility 20%, one year to expiry. Start with the equation coefficients, payoff and boundaries:

coeff = pdeCoeff1D(
    diff={S,tau -> 0.5 * volatility * volatility * S * S}, // diffusion
    conv={S,tau -> rate * S},                              // convection
    react=-rate                                            // reaction
)
payoff = {S -> max(strike-S, 0.0)}                         // payoff at maturity
boundary = [strike, 0.0]                                   // boundary values at both ends

The early-exercise constraint goes in the solver configuration through obstacle. Here we use PSOR:

method = dict(STRING, ANY)
method["obstacle"] = payoff
method["obstacleSolver"] = "PSOR"
method["psorOmega"] = 1.2
method["psorTolerance"] = 1e-10
method["psorMaxIterations"] = 20000

Finally, build the spatial and time grids and pass everything to pdeSolver:

spotGrid = pdeGrid1D(0.0, 300.0, 401, "sinh", strike, 3.0)
tGrid = (0..400) / 400.0
setting = dict(STRING, ANY)
setting["interpAt"] = 100.0
result = pdeSolver(
    coeff, payoff, pdeDomain1D(spotGrid), tGrid,
    boundary, method, setting
)
result["interpValue"]

The coefficients, terminal condition and boundaries define the pricing model; early exercise is a separate, pluggable constraint.

Product differences mostly come down to a few configuration choices:

  • European: drop the early-exercise constraint.
  • Barrier: encode the terms in the solution domain and boundary values.
  • Local volatility: change how the diff coefficient is computed. The equation structure stays the same.

Grid construction and the solving workflow never need to be rewritten.

3. Performance Benchmarks

Speed matters well beyond a single valuation. It drives batch pricing, parameter sensitivity sweeps and complex product research. We benchmarked both toolkits against Python, QuantLib and PriceLib.

A note on methodology: libraries differ in model expression, algorithms and execution-level optimization, so these results compare end-to-end efficiency in specific scenarios and configurations, not absolute rankings. Where algorithms or precision settings differ, we say so explicitly.

Monte Carlo benchmark

All implementations ran 100,000 paths and 126 time steps, using a single worker and antithetic variates. Each test had one warm-up run followed by seven timed runs, and we report the median end-to-end time (DolphinDB timings include SDK round-trip overhead). All times are in milliseconds.

ScenarioDolphinDB standardDolphinDB logNumPy standardNumPy logQuantLib standardQuantLib logPriceLib standardPriceLib log
European Call98.038.0144.986.12447.2571.2209.5152.6
Geometric Asian241.080.4223.494.310845.09438.8249.2142.4
Arithmetic Asian139.1208.0154.4183.110704.011320.1199.1202.8
Heston Call344.8283.2316.3256.42859.3†N/A420.8362.3
Discrete Up-and-Out124.471.5155.4123.99762.110380.7198.0147.6
Two-asset Basket315.9180.6310.4192.15655.31429.5N/AN/A

"Standard" and "log" are two ways of writing the state representation within the same engine. † QuantLib's Heston uses its native FullTruncation variance discretization, which differs from the other implementations, so it is excluded from comparison. N/A means the interface is not supported.

Comparison of Median Execution Times

What the numbers say

  • vs. QuantLib: across the five comparable scenarios, DolphinDB's standard formulation runs in roughly 1/18 to 1/77 of QuantLib's end-to-end time, and the log formulation in roughly 1/8 to 1/145. Geometric Asian and discrete Up-and-Out with the log formulation are about 117x and 145x faster, respectively.
  • vs. NumPy: DolphinDB is faster on European Call, Geometric Asian (log) and discrete Up-and-Out.
  • Where it doesn't win: on Heston Call, both DolphinDB formulations are slightly slower than NumPy, and on Arithmetic Asian the standard formulation is clearly faster than log. Execution efficiency depends on the state representation, the expressions and the implementation, so no single formulation is best everywhere.

For real workloads, evaluate numerical accuracy, algorithmic consistency and your target workload together.

pdeSolver benchmark

Tested on DolphinDB Server V3.00.6.4 (Linux), single CPU core, Release build. Each scenario uses its own spatial grid, time horizon and numerical scheme. Times are post-warm-up medians, in milliseconds.

ScenarioGrid (space × time)Pure C++QuantLibPythonDolphinDBQuantLib / DolphinDBPython / DolphinDB
BS European Call401 × 4001.4733.53412.5904.5840.77x2.75x
Heston stochastic vol121 × 61 × 12048.81280.162509.30998.9080.81x5.15x
BS American Put (PSOR)401 × 2009.9902.8481092.07625.533different algorithms42.78x
Cash-or-nothing digital call401 × 2000.8043.1507.4742.3701.33x3.15x
Asset-or-nothing digital call801 × 4003.11510.82118.9069.7941.11x1.93x
Down-and-out barrier call601 × 4002.3238.17216.8007.2671.12x2.31x
Up-and-out barrier call601 × 4002.3678.18116.4347.3141.12x2.25x
Space-time local vol301 × 1501.4917.8358.4014.1811.87x2.01x
Quanto fixed-FX call401 × 2000.8073.0407.5362.3861.27x3.16x

What the numbers say

  • vs. Python: DolphinDB is faster in all nine scenarios, up to 42.78x, with clear gains on Heston, digital and barrier options.
  • vs. QuantLib: results depend on the scenario. DolphinDB is faster on digital, barrier, Local Vol and Quanto cases, while QuantLib is faster on BS European Call and Heston. The BS American Put compares different numerical algorithms, so we don't treat it as a head-to-head performance result.

4. Choosing and Validating a Pricing Method in Practice

Monte Carlo and PDE each have their sweet spot, and performance shifts with model and implementation. In real projects, choose a method on three criteria, in order: model fit, numerical reliability, computational cost.

Step 1: Let the product's characteristics pick the tool

First check whether a dedicated pricing function already covers your need. If not, decide between general Monte Carlo and PDE based on model state, payoff structure and the outputs you need.

Pricing needConsiderWhy
Path-dependent payoffs, complex payoffs or multiple stochastic factorsMonte CarloDescribe product terms through simulated state evolution and custom payoff logic
Theoretical prices across a range of underlying prices, with a PDE-compatible modelPDESolve a price curve or surface on a space-time grid
Early exercise, expressible through a supported PDE constraintPDEHandle exercise constraints through obstacle and related settings
A mature, standard product interface already existsDedicated pricing functionReuse the existing model and workflow directly

These are guidelines, not hard rules. The final call depends on model assumptions, solver support, accuracy requirements and compute resources.

Step 2: Validate with numerical diagnostics

A price isn't ready for production until it's been validated, and different methods fail in different ways.

  • Monte Carlo: check standard errors, confidence intervals and estimates across different simulation sizes to confirm statistical error is acceptable.
  • PDE: refine the grid, adjust solver tolerances and check convergence of both prices and Greeks.

Where possible, cross-check against analytical solutions or an independent reference implementation. For complex products without closed forms, build a validation plan from statistical error, grid convergence and independent implementations.

Step 3: Evaluate performance once accuracy is met

Optimize on top of a correct, reliable model, not before. For Monte Carlo, tune path count, time steps and batch configuration. For PDE, test grid size, solver algorithm and execution path.

As Section 3 shows, performance varies by model and implementation. Before deployment, benchmark representative products and parameter sets, and keep model definitions, accuracy targets and test scale comparable.

In short: pick the method, validate the numbers, then measure speed. DolphinDB's general Monte Carlo and PDE toolkits give you a reusable computation framework for that process, so you can spend your time on financial models and product terms.

5. What This Unlocks, and Where We're Heading

Beyond raw numerical power, these toolkits give you a reusable foundation for developing, optimizing and integrating derivatives pricing models.

Flexible model building. Standard products use dedicated pricing functions directly. For exotics, path-dependent products and custom payoffs, you define state evolution and payoff logic, or configure PDE coefficients, boundaries, grids and solvers. No need to build a full computation framework for every new product.

Model development meets high-performance computing. Batch computation, vectorization and JIT support help optimize execution. Monte Carlo can be tuned through path count, time steps, batching and memory limits; PDE through grid size, precomputation and solver choice. Actual performance depends on model, algorithm, hardware and parameters, so validate it with comparable tests.

Pricing and business data in one place. Because pricing runs alongside DolphinDB's data processing and analytics, market data, model parameters and results don't have to shuttle between separate systems. You can build standardized workflows that manage product parameters, model configuration, numerical methods and result validation together, laying the groundwork for batch valuation, scenario analysis and downstream risk work, with less duplicated development and maintenance.

Built to keep growing. Directions we're exploring include 3D PDEs, finite volume (FVM) and finite element (FEM) methods, Sobol sequences and quasi-Monte Carlo (QMC), control variates, Brownian bridge corrections for continuous barriers, optimal stopping algorithms for American and Bermudan options, model calibration, and automatic differentiation for Greeks. These are potential directions only; actual support will follow product progress.

Whichever numerical method you choose, the point is the same: reuse proven computation workflows and focus your effort on the financial model, the product terms and the business logic, not on re-implementing solvers.