FX#

The rateslib.fx module provides FX functionality. This is a necessary part of a fixed income library because it allows:

  • consistent treatment of cashflows and values expressed in one currency relative to another,

  • the construction of multi-currency derivatives, and of FX forward rates,

  • valuation of derivatives with CSAs priced in non-local currencies,

  • stored FX rate sensitivity calculations via automatic differentiation.

FX Rates#

The FXRates class is a simple object designed to record and store FX exchange rate values for a particular settlement date, i.e. it is expected to be used for spot FX rates, and for value conversion from one currency to another.

In [1]: fxr = FXRates(fx_rates={"audusd": 0.62}, settlement=dt(2003, 4, 7))

In [2]: fxr.rates_table()
Out[2]: 
     usd  aud
usd 1.00 1.61
aud 0.62 1.00

Read more here about these and other methods of the FXRates class .

FX Forwards#

The FXForwards class is a more comprehensive object that uses a mapping of interest rate curves to derive forward FX rates for any settlement date. In the curves mapping, the key “audusd” should be regarded as; the Curve to discount AUD cashflows, collateralised by USD.

As a brief, blast from the past example, we replicate John Hull’s Options, Futures and Other Derivatives (fifth edition: equation 3.13). He derives the 2y forward rate for AUDUSD FX, via interest rate parity, with known continuously compounded domestic and foreign interest rates, and the spot (although technically immediate) FX rate as above.

\[\begin{split}F_0 &= S_0 e^{(r_{rhs}-r_{lhs}) T} \\ 0.645303 &= 0.6200 e^{(0.07 - 0.05) \times 2}\end{split}\]
In [3]: aud = Curve({dt(2003, 4, 7): 1.0, dt(2005, 4, 7): math.exp(-0.05*2)}, id="aud")

In [4]: usd = Curve({dt(2003, 4, 7): 1.0, dt(2005, 4, 7): math.exp(-0.07*2)}, id="usd")

In [5]: fxf = FXForwards(
   ...:    fx_rates=fxr,
   ...:    fx_curves={"audaud": aud, "usdusd": usd, "audusd": aud},
   ...: )
   ...: 

The discount factors (DFs) on the currency Curves have been specified directly to match the continuously compounded zero rates in accordance with the specification in Hull’s book (this could have been done in other ways, see Cookbook: Curve from Zero Rates).

The value \(F_0\) is then directly available, along with forward rates on any chosen settlement.

In [6]: fxf.rate("audusd", dt(2005, 4, 7))
Out[6]: <Dual: 0.645303, (fx_audusd), [1.0]>

Read more here about the FXForwards class.

FX Volatility#

Rateslib also has some support for FX volatility. Read more here.