American Option Pricing Via Least Squares Monte Carlo
Project description
American Option Pricing Via Least Squares Monte Carlo
Project Goal
This project implements a high-performance pricing engine for American and Bermudan options using the Least Squares Monte Carlo (LSM) approach.
The primary focus is on enhancing the standard Longstaff-Schwartz (2001) method with advanced variance reduction techniques, specifically Control Variates and Leave-One-Out (LOO) regression to reduce pricing error and in-sample bias. The engine can also be applied to other payoff structures, such as multi-asset max American calls, swing options, quantos, etc.
Features
- Core LSM Algorithm: Backward induction with regression-based continuation value estimation.
- Advanced Stochastic Processes: Simulates multi-dimensional correlated assets (GBM), Quanto asset dynamics, and path-dependent stochastic interest rates (Vasicek/Hull-White dynamics for domestic and foreign rates).
- Flexible Payoffs: Vanilla puts/calls, max calls, swing options, and Quanto options (supporting both fixed FX and stochastic rates).
- Variance and Bias Reduction: Antithetic variates, control variates (European options sampled at maturity or exercise times), and Leave-One-Out (LOO) cross-validation to eliminate look-ahead bias.
- Regression Bases: Laguerre polynomials and power polynomials for basis functions.
- Multi-Asset Support: Handles correlated assets via Cholesky decomposition.
- Benchmarks: Comparison against Binomial Trees, Finite Difference Methods (QuantLib), and Black-Scholes.
- Performance: Optimized for speed and accuracy with configurable paths and steps.
Project Structure
├── .github/
│ └── workflows/
│ ├── ci.yml # GitHub Actions automated testing
│ └── publish.yml # PyPI publishing pipeline
├── LSM/
│ ├── __init__.py
│ ├── algorithms.py # Core LeastSquaresMonteCarlo engine (American & Swing)
│ ├── stochastic_processes.py # GBM, QuantoGBM, and Stochastic Rates processes
│ ├── payoffs.py # Vanilla, MaxCall, Swing, and Quanto payoffs/features
│ ├── regression_bases.py # Laguerre and Power polynomial bases
│ ├── control_variate.py # Black-Scholes European prices and CV logic
│ └── binomial_tree.py # CRR Binomial Tree for benchmarking
├── notebooks/
│ ├── demo.ipynb # Quick start and Colab demonstration
│ └── tests.ipynb # Benchmark tests and advanced payoffs
├── tests/
│ ├── test_lsm.py # Pytest suite for core LSM functionality
│ ├── test_quanto.py # Pytest suite for Quanto pricing and stochastic rates
│ └── test_swing.py # Pytest suite for Swing option constraints and pricing
├── pyproject.toml # Build metadata and dependencies
└── README.md
Installation
You can install the package via pip:
pip install lsm-option-pricing
Quick Start
Import the modules and create an LSM engine:
import numpy as np
from LSM.stochastic_processes import GeometricBrownianMotion
from LSM.payoffs import VanillaPayoff
from LSM.regression_bases import LaguerrePolynomials
from LSM.algorithms import LeastSquaresMonteCarlo
# Set up process, payoff, and basis
gbm = GeometricBrownianMotion(S0=36.0, r=0.06, q=0.0, sigma=0.2)
payoff = VanillaPayoff(strike=40.0, option_type="put")
basis = LaguerrePolynomials(degree=3)
# Create LSM engine and price option
lsm = LeastSquaresMonteCarlo(process=gbm, payoff_function=payoff, basis_function=basis)
price, stderr = lsm.pricer(T=1.0, n_steps=50, n_paths=10000)
print(f"American Put Price: {price:.4f} ± {stderr:.4f}")
API Reference
LeastSquaresMonteCarlo.pricer()
Prices the option using the standard Least Squares Monte Carlo algorithm. Evaluates the option by comparing immediate intrinsic value against the conditional expected continuation value.
| Parameter | Type | Default | Description |
|---|---|---|---|
T |
float |
Required | Time to maturity in years. |
n_steps |
int |
Required | Number of discrete time steps for the simulation. |
n_paths |
int |
Required | Number of Monte Carlo paths to generate (generates n_paths/2 pairs if use_antithetic=True). |
rng |
np.random.Generator |
None |
NumPy random number generator instance for reproducible paths. |
use_antithetic |
bool |
False |
If True, uses antithetic variates for variance reduction. |
control_variate |
str |
None |
European option control variate method. Options: 'european_at_maturity', 'european_at_exercise', or None. |
cv_oos |
bool |
True |
If True, uses out-of-sample path estimation for the European CV to eliminate look-ahead bias and over-fitting during stopping time determination. |
create_features |
Callable |
None |
Function to create custom basis features for regression (e.g., cross-terms for multi-asset or Quanto options). |
cache |
bool |
False |
If True, caches the cash flow matrix allowing retrieval via get_cashflow(). |
exercise_times |
array-like |
None |
Specific exercise times for Bermudan options (e.g., [0.25, 0.5, 1.0]). If None, assumes an American option (exercisable at every step). |
simulation_times |
array-like |
None |
Custom time grid passed directly to the simulator. If provided, overrides T and n_steps. |
use_loo |
bool |
False |
If True, applies Leave-One-Out (LOO) cross-validation to reduce in-sample regression bias. |
LeastSquaresMonteCarlo.swing_pricer()
Prices a natural gas or electricity swing option with specific volume constraints. Assumes every step in the simulation grid is a valid daily exercise opportunity.
| Parameter | Type | Default | Description |
|---|---|---|---|
T |
float |
Required | Total time to maturity in years. |
n_steps |
int |
Required | Number of discrete time steps. |
n_paths |
int |
Required | Number of Monte Carlo paths to simulate. |
rng |
np.random.Generator |
None |
NumPy random number generator instance for reproducible paths. |
use_antithetic |
bool |
False |
If True, uses antithetic variates for variance reduction. |
contract_prices |
np.ndarray |
None |
1D array of shape (n_steps + 1,) representing the fixed strike price or forward curve value at each time step. |
simulation_times |
np.ndarray |
None |
Custom time grid. Overrides T and n_steps. Must exactly match the length of contract_prices. |
DCQ |
float |
1.0 |
Daily Contract Quantity (the maximum volume allowed per single exercise). |
Ed |
int |
1 |
Total number of exercise rights available (Annual Contract Quantity / DCQ). |
ToP_rights |
int |
0 |
Minimum number of times the option MUST be exercised to avoid Take-or-Pay penalties. |
Note:
- "Bang-Bang" Exercise: Decisions are strictly all-or-nothing (0 or exactly
DCQ). Partial volume exercises are not supported.- Hard ToP Penalties: Failing to meet
ToP_rightsinvalidates the simulation path (assigns-infvalue) rather than applying a proportional cash penalty.- No Operational Friction: Assumes immediate exercise rights without advance notice periods, resting times, or dynamic capacity limits.
Returns: A tuple (price, std_err) containing the estimated option price and the standard error.
Demo
An interactive demo showing error convergence and basic pricing is available here:
Dependencies
- Python
- NumPy
- SciPy
- Pandas (for data handling)
- Matplotlib (for plotting)
- Jupyter (for notebooks)
- QuantLib (optional, for FDM benchmarks)
License
This project is licensed under the MIT License (see the LICENSE file for details).
References
- Longstaff, F. A., and E. S. Schwartz (2001). "Valuing American Options by Simulation: A Simple Least-Squares Approach.": Seminal LSM paper.
- Broadie, M., and P. Glasserman (2004). "A Stochastic Mesh Method for Pricing High-Dimensional American Options." Journal of Computational Finance.: Multi-asset American max call benchmarks.
- Jaillet, P., Ronn, E. I., and S. Tompaidis (2004). "Valuation of Commodity-Based Swing Options.": American equivalency and European strip bounds for swing options.
- Hanfeld, M., and S. Schlüter (2016). "Operating a swing option on today's gas markets: How least squares Monte Carlo works and why it is beneficial." Working Paper.: Detailed backward induction logic for the $q_{n,t}$ offtake levels and the 2D state grid used in our swing_pricer.
- Glasserman, P. (2004). Monte Carlo Methods in Financial Engineering.: Quantos and other payoff structures, critique about LSM, etc.
- Rasmussen, H. O. (2005). "Control Variates for American Options.": Control variates for American options sampled at exercise.
- Woo, R., et al. (2019). "Leave-one-out Least Squares Monte Carlo.": Leave-one-out LSM.
- GitHub: luphord/longstaff_schwartz. "An implementation of the Longstaff-Schwartz algorithm for American option pricing.": Another LSM implementation.
Acknowledgements
- Inspiration and repository structure:
luphord/longstaff_schwartz(see References).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lsm_option_pricing-0.1.0.tar.gz.
File metadata
- Download URL: lsm_option_pricing-0.1.0.tar.gz
- Upload date:
- Size: 23.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9cce2e8ddea844522eeb43ba0f791e3d053f8029a99642bd958fd4797dbcc21
|
|
| MD5 |
8800e190e9068eb99d227d5f84fb8b42
|
|
| BLAKE2b-256 |
1b2ef0489acb7687f1ede036dfcf045d9d76f1117058010e40dc6c194102128d
|
Provenance
The following attestation bundles were made for lsm_option_pricing-0.1.0.tar.gz:
Publisher:
publish.yml on sockiesss/LSM_Option_Pricing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lsm_option_pricing-0.1.0.tar.gz -
Subject digest:
b9cce2e8ddea844522eeb43ba0f791e3d053f8029a99642bd958fd4797dbcc21 - Sigstore transparency entry: 1521662234
- Sigstore integration time:
-
Permalink:
sockiesss/LSM_Option_Pricing@417d18f7bc2dfff87106e50db22323202d4f266e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/sockiesss
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@417d18f7bc2dfff87106e50db22323202d4f266e -
Trigger Event:
release
-
Statement type:
File details
Details for the file lsm_option_pricing-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lsm_option_pricing-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c94a957c7b73434833a016ee3cda6f9cc39241012d6c2ab40630f0b48d9117ee
|
|
| MD5 |
ba19291c24470d25b4686fa7536c880d
|
|
| BLAKE2b-256 |
20ab87e6375721d69c680f12bb25d275e2d784e66b4a3a0148ae46142ac2a1e5
|
Provenance
The following attestation bundles were made for lsm_option_pricing-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on sockiesss/LSM_Option_Pricing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lsm_option_pricing-0.1.0-py3-none-any.whl -
Subject digest:
c94a957c7b73434833a016ee3cda6f9cc39241012d6c2ab40630f0b48d9117ee - Sigstore transparency entry: 1521662300
- Sigstore integration time:
-
Permalink:
sockiesss/LSM_Option_Pricing@417d18f7bc2dfff87106e50db22323202d4f266e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/sockiesss
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@417d18f7bc2dfff87106e50db22323202d4f266e -
Trigger Event:
release
-
Statement type: