Skip to content

refactor(cftc): build the FX market once for the vol surface and trade valuation - #7857

Open
artcashin wants to merge 1 commit into
openbq-org:bugfix/cftc-fx-own-print-exclusionfrom
artcashin:refactor/cftc-fx-shared-market
Open

artcashin wants to merge 1 commit into
openbq-org:bugfix/cftc-fx-own-print-exclusionfrom
artcashin:refactor/cftc-fx-shared-market

Conversation

@artcashin

Copy link
Copy Markdown
Contributor

Description

The last two follow-ups from the #7750 review. Stacked on #7833, which covers the first two; this PR's own diff is the single commit on top of it.

One shared market builder

fx_implied_vol and fx_market each built their own market. Both now call fx_vol.build_market, which owns:

Surface before Valuation before Both now
Notional floor 0 $1,000 $1,000
Forward-aware discounting on off on
min_trades query (default 3) query (default 1) the caller's query value
Spot NDF pairs: forward curve. Others: forwards with an effective date within 2 days forward curve, else prints out to 9 days forward curve, else prints out to 9 days, else forwards effective within 2 days (crossed through USD)
Curve family OIS only deepest family first deepest family first (OIS when the currency has one)

min_trades stays a query parameter on both endpoints, so the defaults still differ (3 and 1). Say if you want one default.

The days > 2 cut-off in _deliverable_spot now uses FORWARD_MIN_DAYS. fx_spot takes the floor as an argument; its other callers pass none and are unchanged.

A valued option reads its vol like the surface

option_vol reads the option's own cell of the empirical surface: the same expiry bucket, strike-grid step and 0.5x to 2x trim, through a new surface_points that vol_surface also uses. If the cell is empty it takes the expiry bucket, and if that is empty the nearest expiry as before, so no option stops being valued. Pairs outside the surface's pip table use its moneyness grid.

Effect on 2026-11-16 (53,375 forex prints)

Surfaces, empirical basis:

Pair Spot before Spot now Cells Vol points moved, median / max
EURUSD 1.10224 1.10105 70 to 63 0.38 / 4.66
USDJPY 159.503 159.545 61 to 62 0.43 / 3.66
GBPUSD 1.31915 1.31910 38 to 38 0.15 / 0.60
USDCAD 1.42388 1.42999 46 to 46 0.55 / 2.03
EURGBP 0.834642 0.834642 20 to 20 0 / 0
USDBRL 5.7508 5.7508 61 to 61 0 / 0.27
USDKRW 1335.24 1335.24 16 to 16 0 / 0.01
USDINR 93.9672 93.9672 21 to 21 0 / 0.06

The deliverable spots move because the old rule took every forward with a near effective date, whatever its maturity, so the median carried forward points. The direction matches each pair's points (EURUSD down, USDJPY and USDCAD up).

Valuations (value_fx_trade over the whole file):

  • Priced rows: 37,762 to 37,804. None lost; 42 gained (40 NZDUSD, 1 EURCHF, 1 AUDCNY).
  • Forwards: 36,817 valued in both. The market rate changes on 17, all USDHKD, where the forward comes from the two discount curves. The rest move by about 1e-6 of NPV, from the forward-aware discount factor.
  • Options: 945 valued in both. Implied vol changes on 828: median 0.27 vol points, 90th percentile 1.65, largest 8.4.
  • Valuation loop: 2.0 s before, 2.4 s now, slices already loaded.

Not included

  • ndf_forward_curve, observation_curve and ois_discount_factor no longer have a caller outside the tests. I left them; say if you want them removed with their tests.
  • fx_forward_points builds its own discount curves (min_trades=3, forward-aware). It was not part of the review and is unchanged.
  • An option's own print still counts in its cell, as in fix(cftc): value each FX forward against the pair's other prints #7833.

Tests

openbb_platform/providers/cftc: 1,254 passed locally (Python 3.12). New tests cover the builder's spot rule and floor, the cross through USD, forward-aware discount lookup, the surface and the valuation getting the same market, and the three levels of the option vol reading. ruff format and ruff check are clean on the touched files. No CI run yet.

🤖 Generated with Claude Code

…e valuation

The implied-vol surface and the forex valuations each built their own
market, with a different notional floor, curve depth, forward-aware
setting and spot rule. Both now call fx_vol.build_market:

- $1,000 floor on every print that sets spot or a curve node
- spot from the pair's forward curve, else its near prints, else
  deliverable forwards settling by the spot date (crossed through USD)
- forward-aware discount curves, deepest swap family first, at the
  caller's min_trades

A valued option now reads its vol from its own cell of the empirical
surface (expiry bucket and strike-grid step), then the expiry bucket,
then the nearest expiry as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant