Package com.quantfinlib.hedging
package com.quantfinlib.hedging
Hedging algorithms across asset 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.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 Pinvalid input: '&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).First/second-order attribution of a Pinvalid input: '&L' move.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.