from spetro import RoughVolatilityEngine
e = RoughVolatilityEngine(backend="jax", device=None, precision="float32")Simulate rough-volatility asset and variance paths.
params:
model: RoughVolatilityModeln_paths: int, paths to simulaten_steps: int, time stepsT: float, maturityS0: float, initial pricekey: random key/seed
returns: tuple (S, V)
Price an option from MC path simulations.
params:
model: RoughVolatilityModelpayoff_fn: function(S) -> payoffn_paths: intn_steps: intT: floatS0: floatkey: random key/seedantithetic: bool
returns: dict {price, std_error, paths}
Estimate price and first/second-order Greeks.
params:
model: RoughVolatilityModelpayoff_fn: function(S) -> payoffn_paths: intn_steps: intT: floatS0: floatkey: random key/seed
returns: dict {price, delta, gamma}
from spetro import RoughBergomi
model = RoughBergomi(H=0.07, eta=1.9, rho=-0.9, xi=0.235**2, r=0.0)params:
H: float, hurst parameter (0 < H < 0.5)eta: float, vol of volrho: float, correlationxi: float, initial variancer: float, risk-free rate
from spetro import RoughHeston
model = RoughHeston(H=0.07, nu=0.3, theta=0.02, rho=-0.7, V0=0.02, r=0.0)params:
H: float, hurst parameter (0 < H < 0.5)nu: float, vol of voltheta: float, mean reversionrho: float, correlationV0: float, initial variancer: float, risk-free rate
from spetro import Pricer
p = Pricer(engine)price european option
params:
model: RoughVolatilityModeloption_type: str, "call" or "put"K: float, strikeT: float, maturityS0: float, initial pricen_paths: intn_steps: intantithetic: bool
returns: dict {price, std_error, paths}
price asian option
params:
model: RoughVolatilityModeloption_type: str, "call"K: float, strikeT: float, maturityS0: float, initial pricen_paths: intn_steps: int
returns: dict {price, std_error, paths}
price barrier option
params:
model: RoughVolatilityModelK: float, strikebarrier: float, barrier levelbarrier_type: str, "up_and_out" or "down_and_out"T: float, maturityS0: float, initial pricen_paths: intn_steps: int
returns: dict {price, std_error, paths}
price custom option
params:
model: RoughVolatilityModelpayoff_fn: function(S) -> payoffT: float, maturityS0: float, initial pricen_paths: intn_steps: intantithetic: bool
returns: dict {price, std_error, paths}
calc greeks
params:
model: RoughVolatilityModeloption_type: str, "call" or "put"K: float, strikeT: float, maturityS0: float, initial pricen_paths: intn_steps: int
returns: dict {price, delta, gamma}
from spetro import Calibrator
c = Calibrator(engine)calibrate_to_surface(model_class, market_prices, S0=100.0, initial_params=None, bounds=None, optimizer="adam", max_iter=1000, tolerance=1e-6)
calibrate model to market
params:
model_class: model class (RoughBergomi, RoughHeston)market_prices: dict {(K, T): price}S0: float, initial priceinitial_params: dict, initial parametersbounds: dict, parameter boundsoptimizer: str, "adam"max_iter: int, max iterationstolerance: float, convergence tolerance
returns: dict {model, parameters, objective_value, iterations, success}
validate calibration
params:
model: RoughVolatilityModelmarket_prices: dict {(K, T): price}S0: float, initial price
returns: dict {individual_results, mean_absolute_error, max_relative_error}
from spetro import NeuralSurrogate
ns = NeuralSurrogate(engine, backend="jax")generate training data
params:
model: RoughVolatilityModelparam_ranges: dict {param: (low, high)}option_configs: list of dicts {K, T, S0, option_type}n_samples: int, number of samplesn_paths: int, paths per sample
returns: tuple (X, y)
train neural network
params:
X: features arrayy: targets arrayvalidation_split: float, validation fractionepochs: int, training epochslearning_rate: float, learning ratebatch_size: int, batch size
returns: dict {train_loss, val_loss}
predict price
params:
features: list or array, input features
returns: float, predicted price
european call payoff
params:
K: float, strike
returns: function(S) -> payoff
european put payoff
params:
K: float, strike
returns: function(S) -> payoff
asian call payoff
params:
K: float, strike
returns: function(S) -> payoff
barrier call payoff
params:
K: float, strikebarrier: float, barrier levelbarrier_type: str, "up_and_out" or "down_and_out"
returns: function(S) -> payoff
basket call payoff
params:
weights: list, asset weightsK: float, strike
returns: function(S) -> payoff
backend = JAXBackend(device=None, precision="float32")backend = TorchBackend(device=None, precision="float32")