FXExchange#

class rateslib.instruments.FXExchange(settlement, currency, leg2_currency, fx_rate=NoInput.blank, notional=NoInput.blank, curves=NoInput.blank)#

Bases: Sensitivities, BaseMixin

Create a simple exchange of two currencies.

Parameters:
  • settlement (datetime) – The date of the currency exchange.

  • currency (str) – The currency of the cashflow for which notional is applicable (3-digit code).

  • leg2_currency (str) – The currency of the cashflow on the alternate Leg.

  • fx_rate (float, optional) – The FX rate used to derive the notional exchange on Leg2.

  • notional (float) – The cashflow amount for the initial currency.

  • curves (Curve, LineCurve, str or list of such, optional) –

    A single Curve, LineCurve or id or a list of such. A list defines the following curves in the order:

Attributes Summary

fixed_rate

If set will also set the fixed_rate of the contained leg1.

float_spread

If set will also set the float_spread of contained leg1.

fx_rate

index_base

If set will also set the index_base of the contained leg1.

leg2_fixed_rate

If set will also set the fixed_rate of the contained leg2.

leg2_float_spread

If set will also set the float_spread of contained leg2.

leg2_index_base

If set will also set the index_base of the contained leg1.

Methods Summary

analytic_delta(*args[, leg])

Return the analytic delta of a leg of the derivative object.

cashflows([curves, solver, fx, base])

Return the cashflows of the FXExchange by aggregating legs.

cashflows_table([curves, solver, fx, base])

delta(*args, **kwargs)

Calculate the delta of the Instrument.

gamma(*args, **kwargs)

Calculate the gamma of the Instrument.

npv([curves, solver, fx, base, local])

Return the NPV of the FXExchange by summing legs.

rate([curves, solver, fx, base])

Return the mid-market rate of the instrument.

Attributes Documentation

fixed_rate#

If set will also set the fixed_rate of the contained leg1.

Note

fixed_rate, float_spread, leg2_fixed_rate and leg2_float_spread are attributes only applicable to certain Instruments. AttributeErrors are raised if calling or setting these is invalid.

Type:

float or None

float_spread#

If set will also set the float_spread of contained leg1.

Type:

float or None

fx_rate#
index_base#

If set will also set the index_base of the contained leg1.

Note

index_base and leg2_index_base are attributes only applicable to certain Instruments. AttributeErrors are raised if calling or setting these is invalid.

Type:

float or None

leg2_fixed_rate#

If set will also set the fixed_rate of the contained leg2.

Type:

float or None

leg2_float_spread#

If set will also set the float_spread of contained leg2.

Type:

float or None

leg2_index_base#

If set will also set the index_base of the contained leg1.

Note

index_base and leg2_index_base are attributes only applicable to certain Instruments. AttributeErrors are raised if calling or setting these is invalid.

Type:

float or None

Methods Documentation

abstract analytic_delta(*args, leg=1, **kwargs)#

Return the analytic delta of a leg of the derivative object.

Parameters:
  • args – Required positional arguments supplied to BaseLeg.analytic_delta.

  • leg (int in [1, 2]) – The leg identifier of which to take the analytic delta.

  • kwargs – Required Keyword arguments supplied to BaseLeg.analytic_delta().

Return type:

float, Dual, Dual2

Examples

In [12]: curve = Curve({dt(2021,1,1): 1.00, dt(2025,1,1): 0.83}, id="SONIA")

In [13]: fxr = FXRates({"gbpusd": 1.25}, base="usd")
In [14]: irs = IRS(
   ....:     effective=dt(2022, 1, 1),
   ....:     termination="6M",
   ....:     frequency="Q",
   ....:     currency="gbp",
   ....:     notional=1e9,
   ....:     fixed_rate=5.0,
   ....: )
   ....: 

In [15]: irs.analytic_delta(curve, curve)
Out[15]: 47156.00216054951

In [16]: irs.analytic_delta(curve, curve, fxr)
Out[16]: <Dual: 58945.002701, (fx_gbpusd), [47156.0]>

In [17]: irs.analytic_delta(curve, curve, fxr, "gbp")
Out[17]: 47156.00216054951
cashflows(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank)#

Return the cashflows of the FXExchange by aggregating legs.

For arguments see BaseMixin.npv

cashflows_table(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank)#
delta(*args, **kwargs)#

Calculate the delta of the Instrument.

For arguments see Sensitivities.delta().

gamma(*args, **kwargs)#

Calculate the gamma of the Instrument.

For arguments see Sensitivities.gamma().

npv(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank, local=False)#

Return the NPV of the FXExchange by summing legs.

For arguments see BaseMixin.npv

rate(curves=NoInput.blank, solver=NoInput.blank, fx=NoInput.blank, base=NoInput.blank)#

Return the mid-market rate of the instrument.

For arguments see BaseMixin.rate