Package com.quantfinlib.hedging
@NullMarked
package com.quantfinlib.hedging
Hedging algorithms across asset classes. The main classes:
DeltaHedger (dynamic delta hedging with
bands and costs) and HedgingSimulator
(Monte Carlo hedging-error distributions),
GreekHedger (delta-gamma-vega
neutralization), OptionsBook (book-level
Greeks, scenario grids, P&L explain),
MinimumVarianceHedge (optimal ratios,
futures sizing), FxHedger (exposure
netting, forward carry), PairsHedger
(spread construction, half-life),
CointegrationTest (Engle-Granger, the
statistical gate before a pairs trade) and
WhalleyWilmott (the optimal no-trade
band around delta; the width the band hedgers take as configuration
should come from here, with the hedge-to-nearest-edge policy).-
ClassDescriptionEngle-Granger two-step cointegration test: regress one price series on the other, then run an augmented Dickey-Fuller test (no constant) on the residual spread.Dynamic delta hedging simulator: sell an option, then replicate it by trading the underlying along a price path, rebalancing whenever the delta drifts outside a band.Hedging settings.FX exposure hedging with forwards: nets currency exposures across a book, computes the variance-minimizing hedge ratio for a foreign-asset position, and prices the carry cost of the forward hedge from forward points.One currency exposure, signed, in base-currency terms.Greek-neutralization: solves the hedge quantities that flatten a portfolio's option Greeks using available hedge instruments — the standard delta-gamma and delta-gamma-vega hedging recipes, plus a general linear solver for arbitrary greek/instrument combinations.Per-unit Greeks of a hedge instrument (the underlying is delta=1, gamma=0, vega=0).Distribution of delta-hedging P&L across Monte Carlo paths: how well the hedge replicates the option, where the tail risk sits, and what the hedging itself costs.Monte Carlo delta-hedging engine: runs
DeltaHedgeracross thousands of GBM paths in parallel to produce the full hedging-error distribution — replication error, tail risk (hedging VaR/CVaR), and cost/rebalance statistics.Minimum-variance and beta hedging with futures or a correlated proxy: Optimal hedge ratioh* = cov(asset, hedge) / var(hedge)— the classic OLS/minimum-variance ratio. Hedge effectiveness — the fraction of variance removed at the optimal ratio (= correlation², the standard 80%+ effectiveness test). Futures contract sizing — contracts to move a portfolio from its current beta to a target beta.An options book on one underlying: aggregate Greeks across positions, spot×vol scenario grids, and delta-gamma-vega-theta P&L explain — the risk view a desk runs, not a single option.Aggregated book value and Greeks.One option position;quantityin option units (contract multiplier applied by caller).Taylor attribution of a P&L move: delta, gamma, vega, vanna (∂²V/∂S∂σ · dS·dσ), volga (½·∂²V/∂σ² · dσ²) and theta, with the remainder inunexplained.Statistical (pairs) hedging: regresses one price series on another to get the hedge ratio, builds the spread, and characterizes its mean reversion — z-score for entry/exit signals and half-life (from an AR(1) fit of spread changes on spread levels) for expected holding time.Whalley-Wilmott optimal hedge bands — the answer to the question every band hedger otherwise guesses: how wide should the no-trade band around delta be?The rebalancing decision: trade (to the nearest edge) or hold.