Skip to content

Commit

Permalink
REF/TYP: internal pricing object metrics for FXOption (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
attack68 authored Jan 19, 2025
1 parent 08f4e8c commit 4f9b9c2
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 85 deletions.
4 changes: 2 additions & 2 deletions docs/source/c_fx_smile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ this produces minor deviations from his calculated values.
for op in ops:
op.rate(fx=fxf)
strikes = [float(_._pricing["k"]) for _ in ops]
vols = [float(_._pricing["vol"]) for _ in ops]
strikes = [float(_._pricing.k) for _ in ops]
vols = [float(_._pricing.vol) for _ in ops]
data2 = DataFrame(
data=[strikes[0:3], vols[0:3], strikes[3:6], vols[3:6], strikes[6:9], vols[6:9]],
index=[("1y", "k"), ("1y", "vol"), ("18m", "k"), ("18m", "vol"), ("2y", "k"), ("2y", "vol")],
Expand Down
4 changes: 4 additions & 0 deletions docs/source/i_whatsnew.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ email contact, see `rateslib <https://rateslib.com>`_.
*FXRates* and *FXForwards* to allow auto-mutate detection of associated objects and ensure
consistent method results.
(`570 <https://github.com/attack68/rateslib/pull/570>`_)
* - Refactor
- The internal data objects for *FXOption* pricing are restructured to conform to more
strict data typing.
(`642 <https://github.com/attack68/rateslib/pull/642>`_)

1.6.0 (30th November 2024)
****************************
Expand Down
12 changes: 6 additions & 6 deletions python/rateslib/instruments/fx_volatility/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FXOptionStrat:
The multiplier for the *'vol'* metric that sums the options to a final *rate*.
"""

_pricing: dict[str, Any]
_greeks: dict[str, Any] = {}
_strat_elements: tuple[FXOption | FXOptionStrat, ...]
periods: list[FXOption]

Expand Down Expand Up @@ -733,7 +733,7 @@ def d_wrt_sigma1(period_index, greeks, smile_greeks, vol, eta1):
iters += 1

if record_greeks: # this needs to be explicitly called since it degrades performance
self._pricing["strangle_greeks"] = {
self._greeks["strangle"] = {
"single_vol": {
"FXPut": self.periods[0].analytic_greeks(curves, solver, fx, base, vol=tgt_vol),
"FXCall": self.periods[1].analytic_greeks(
Expand Down Expand Up @@ -900,16 +900,16 @@ def _maybe_set_vega_neutral_notional(self, curves, solver, fx, base, vol, metric
metric="single_vol",
record_greeks=True,
)
self._pricing["straddle_greeks"] = self.periods[1].analytic_greeks(
self._greeks["straddle"] = self.periods[1].analytic_greeks(
curves,
solver,
fx,
base,
vol=vol[1],
)
strangle_vega = self._pricing["strangle_greeks"]["market_vol"]["FXPut"]["vega"]
strangle_vega += self._pricing["strangle_greeks"]["market_vol"]["FXCall"]["vega"]
straddle_vega = self._pricing["straddle_greeks"]["vega"]
strangle_vega = self._greeks["strangle"]["market_vol"]["FXPut"]["vega"]
strangle_vega += self._greeks["strangle"]["market_vol"]["FXCall"]["vega"]
straddle_vega = self._greeks["straddle"]["vega"]
scalar = strangle_vega / straddle_vega
self.periods[1].kwargs["notional"] = float(
self.periods[0].periods[0].periods[0].notional * -scalar,
Expand Down
Loading

0 comments on commit 4f9b9c2

Please sign in to comment.