gk-fx-smile/README.md

74 lines
3.8 KiB
Markdown

2026-08-14 00:09:43 +00:00
# GK FX Smile
The FX volatility smile, reconstructed in MQL5 from the three quotes the market
actually publishes, priced with Garman-Kohlhagen.
Companion code for the MQL5 article: https://www.mql5.com/en/articles/23807
## What it does
FX options are not quoted the way equity options are. The market quotes in
delta space, not strikes, and the core set is three numbers: at-the-money
volatility, a risk reversal, and a butterfly. Turning those into a smile is
the work. Most desks also publish 10-delta wings, which the sample sheets
carry as optional columns.
2026-08-14 00:09:43 +00:00
Garman-Kohlhagen is Black-Scholes with two interest rates, one per currency,
which is what a currency pair needs. On top of that sits the part that catches
people out: delta is a convention. Spot or forward, premium-adjusted or not,
and the choice changes which strike a quoted delta refers to. The article works
through the conventions rather than picking one silently.
From those quotes the smile is reconstructed across strikes, and `GKSmile.mq5`
draws it. The feed can be a CSV or native MetaTrader 5 options. Be clear on
what comes back: the reconstruction is exact at the pillars and a
piecewise-linear interpolation everywhere else. Three or five quotes pin
points, not a curve, and a fuller model such as SABR or Vanna-Volga is what
would fill the gaps.
The engine is checked against an independent Python reference built from the
formulas rather than translated from the header. Across two sample sheets,
five tenors and all four delta conventions, 200 reconstructed pillars agree
bit for bit once both sides use the same normal CDF, which places the entire
residual on that approximation and nothing else. Measured directly against
`math.erfc` over a fine grid, the Abramowitz and Stegun CDF in the header is
worst by 7.45e-8, matching its published bound.
What it does not model is worth stating. Rates are one flat pair per tenor
rather than a bootstrapped curve. Time is calendar days over 365 throughout,
with the same value reused for the discount factors, and settlement lags, the
spot date and the expiry cut are absent. There is no arbitrage check, so five
pillars joined by straight lines can produce a call-price curve that is not
convex in the strike. The butterfly is read in its simplified form; a
market-strangle quote needs an extra calibration step first. The native
provider summarises a listed chain into delta-space quotes, which is lossy by
construction and therefore not an inverse of the reconstruction.
2026-08-14 00:09:43 +00:00
## Layout
```
Include/GK/GarmanKohlhagen.mqh two-rate pricing and greeks
Include/GK/GKData.mqh quote handling and smile reconstruction
Include/GK/GKProviderNative.mqh native MT5 options feed
Indicators/GK/GKSmile.mq5 the smile indicator
Files/GK/EURUSD.csv sample quotes
Files/GK/USDJPY.csv sample quotes
```
Start with `GKSmile.mq5` on any chart, left on its CSV source: the sample
sheets let it run without a live options feed. The one input that matters is
the delta convention, which is a property of the pair and of whoever supplies
your quotes, not a preference. EURUSD wants the unadjusted spot delta, USDJPY
the premium-adjusted one; getting it wrong raises no error and simply places
every pillar on a slightly different strike. To use your own marks, replace
the CSV rows, keeping volatilities in percent and rates as continuously
compounded decimals, since a money-market deposit quote needs converting
first.
2026-08-14 00:09:43 +00:00
## Disclaimer
Educational code. The sample volatility sheets carry illustrative quotes, not
live market data. This is a reconstruction tool, not a pricing library: the
checks above bound its arithmetic, and say nothing about whether the
conventions and rates you feed it are the ones your counterparty uses. Test on
your own data and broker conditions before drawing conclusions.