forward_fx#
- rateslib.fx.forward_fx(date, curve_domestic, curve_foreign, fx_rate, fx_settlement=None)#
Return a forward FX rate based on interest rate parity.
- Parameters:
date (datetime) – The target date to determine the adjusted FX rate for.
curve_domestic (Curve) – The discount curve for the domestic currency. Should be collateral adjusted.
curve_foreign (Curve) – The discount curve for the foreign currency. Should be collateral consistent with
domestic curve
.fx_rate (float or Dual) – The known FX rate, typically spot FX given with a spot settlement date.
fx_settlement (datetime, optional) – The date the given
fx_rate
will settle, i.e. spot T+2. If None is assumed to be immediate settlement, i.e. date upon which bothcurves
have a DF of precisely 1.0. Method is more efficient iffx_rate
is given for immediate settlement.
- Return type:
Notes
We use the formula,
\[(EURUSD) f_i = \frac{(EUR:USD-CSA) w^*_i}{(USD:USD-CSA) v_i} F_0 = \frac{(EUR:EUR-CSA) v^*_i}{(USD:EUR-CSA) w_i} F_0\]where \(w\) is a collateral adjusted discount curve and \(v\) is the locally derived discount curve in a given currency, and * denotes the domestic currency. \(F_0\) is the immediate FX rate, i.e. aligning with the initial date on curves such that discounts factors are precisely 1.0.
This implies that given the dates and rates supplied,
\[f_i = \frac{w^*_iv_j}{v_iw_j^*} f_j = \frac{v^*_iw_j}{w_iv_j^*} f_j\]where j denotes the settlement date provided.
Examples
Using this function directly.
In [1]: domestic_curve = Curve({dt(2022, 1, 1): 1.0, dt(2023, 1, 1): 0.96}) In [2]: foreign_curve = Curve({dt(2022, 1, 1): 1.0, dt(2023, 1, 1): 0.99}) In [3]: forward_fx( ...: date=dt(2022, 7, 1), ...: curve_domestic=domestic_curve, ...: curve_foreign=foreign_curve, ...: fx_rate=2.0, ...: fx_settlement=dt(2022, 1, 3) ...: ) ...: Out[3]: 1.9700450724927536
Best practice is to use
FXForwards
classes but this method provides an efficient alternative and is occasionally used internally in the library.In [4]: fxr = FXRates({"usdgbp": 2.0}, settlement=dt(2022, 1, 3)) In [5]: fxf = FXForwards(fxr, { ...: "usdusd": domestic_curve, ...: "gbpgbp": foreign_curve, ...: "gbpusd": foreign_curve, ...: }) ...: In [6]: fxf.rate("usdgbp", dt(2022, 7, 1)) Out[6]: <Dual: 1.970045, (fx_usdgbp), [1.0]>