Surface-Lib
A high-performance Rust library for volatility surface modeling and calibration. Currently supports the SVI (Stochastic Volatility Inspired) model with advanced optimization capabilities for quantitative finance applications.
Features
- SVI Model: Complete implementation of the SVI volatility model with parameter validation and no-arbitrage constraints
- Advanced Calibration: CMA-ES and L-BFGS-B optimization with robust parameter estimation
- Model Parameters: Configurable weighting schemes (ATM boost, vega weighting) for fine-tuning calibration
- Option Pricing: Black-Scholes pricing with calibrated volatility surfaces
- Production Ready: Optimized for real-time trading and backtesting systems
- Type Safety: Comprehensive error handling and parameter validation
Usage
Basic Example
use ;
// Create market data with required fields
let market_data = vec!;
// Step 1: Calibrate SVI parameters
let config = fast;
let calib_params = default;
let = calibrate_svi?;
// Step 2: Create SVI parameters from calibration results
let svi_params = SVIParams ;
// Step 3: Price options with calibrated model
let fixed_params = FixedParameters ;
let pricing_results = price_with_svi;
println!;
println!;
for result in pricing_results
Custom Model Parameters
Control the calibration weighting scheme with model-specific parameters:
use ;
// Default behavior (ATM boost = 25.0, vega weighting enabled)
let calib_params = default;
// Custom parameters for different weighting schemes
let mut calib_params = default;
calib_params.model_params = Some;
let = calibrate_svi?;
Model Parameters:
atm_boost_factor: Controls ATM weighting withexp(-factor * |log_moneyness|). Higher values emphasize ATM options more strongly (default: 25.0)use_vega_weighting: Whether to weight observations by their vega values. Set tofalsefor equal strike weighting (default: true)
Configuration Presets
The library provides several optimization configuration presets:
use default_configs;
// For production trading systems
let config = production;
// For development and testing (balanced speed/accuracy)
let config = fast;
// For research and backtesting (highest precision)
let config = research;
// For quick validation and debugging
let config = minimal;
Data Structure
The library expects a MarketDataRow with these essential fields:
SVI Model
The SVI model parameterizes total variance as:
w(k) = a + b * (ρ(k-m) + sqrt((k-m)² + σ²))
Where:
kis log-moneyness:ln(K/S)ais the base variance level (vertical shift parameter)bis the slope factor (overall variance level)ρis the asymmetry parameter (skew, must be in (-1, 1))mis the horizontal shift parameter (ATM location in log-moneyness)σis the curvature parameter (smile curvature, must be > 0)
The model automatically enforces no-arbitrage constraints during calibration.
API Reference
Calibration
calibrate_svi(data, config, calib_params)
Calibrates SVI model parameters to market option data for a single expiration.
Arguments:
data: Vec<MarketDataRow>- Market option data (single expiration only)config: OptimizationConfig- Optimization settings (usedefault_configspresets)calib_params: CalibrationParams- Calibration and model parametersinitial_guess: Option<Vec<f64>>- Optional initial parameter guess for warm-started calibration
Returns:
(f64, Vec<f64>, SVIParamBounds)- (objective_value, parameters, effective_parameter_bounds)
price_with_svi(params, market_data, fixed_params)
Prices European options using calibrated SVI parameters.
Arguments:
params: SVIParams- Calibrated SVI parametersmarket_data: Vec<MarketDataRow>- Options to pricefixed_params: FixedParameters- Risk-free rate and dividend yield
Returns:
Vec<PricingResult>- Pricing results with model prices and implied volatilities
Model Parameters
SviModelParams
Controls SVI-specific calibration behavior:
Usage Examples:
- Equal weighting:
SviModelParams { atm_boost_factor: 0.0, use_vega_weighting: false } - Strong ATM focus:
SviModelParams { atm_boost_factor: 50.0, use_vega_weighting: true } - Wing emphasis:
SviModelParams { atm_boost_factor: 10.0, use_vega_weighting: true }
Advanced Features
- Configurable Weighting: ATM boost and vega weighting can be independently controlled
- Auto-Bounds: Parameter bounds automatically adjust based on time to expiration
- Two-Stage Optimization: Global search with CMA-ES followed by local refinement with L-BFGS-B
- Production Ready: Optimized for real-time trading and backtesting systems
Requirements
- Data must contain options for a single expiration (SVI is a single-slice model)
- Minimum 5-10 data points recommended for stable calibration
- Market implied volatilities should be provided as decimals (0.25 for 25%)
License
Licensed under either of:
- MIT license (
LICENSE-MIT) - Apache License, Version 2.0 (
LICENSE-APACHE)
at your option.