Last updated: 2023-03-16.
tf_quant_finance.models.hull_white.swaption_price#
Calculates the price of European Swaptions using the Hull-White model.
tf_quant_finance.models.hull_white.swaption_price(
*, expiries, floating_leg_start_times, floating_leg_end_times,
fixed_leg_payment_times, floating_leg_daycount_fractions,
fixed_leg_daycount_fractions, fixed_leg_coupon, reference_rate_fn,
mean_reversion, volatility, notional=None, is_payer_swaption=True,
use_analytic_pricing=True, num_samples=100, random_type=None, seed=None, skip=0,
time_step=None, dtype=None, name=None
)
A European Swaption is a contract that gives the holder an option to enter a swap contract at a future date at a prespecified fixed rate. A swaption that grants the holder to pay fixed rate and receive floating rate is called a payer swaption while the swaption that grants the holder to receive fixed and pay floating payments is called the receiver swaption. Typically the start date (or the inception date) of the swap concides with the expiry of the swaption. Mid-curve swaptions are currently not supported (b/160061740).
Analytic pricing of swaptions is performed using the Jamshidian decomposition [1].
References:#
[1]: D. Brigo, F. Mercurio. Interest Rate Models-Theory and Practice. Second Edition. 2007.
Example#
The example shows how value a batch of 1y x 1y and 1y x 2y swaptions using the Hull-White model.
import numpy as np
import tensorflow as tf
import tf_quant_finance as tff
dtype = tf.float64
expiries = [1.0, 1.0]
float_leg_start_times = [[1.0, 1.25, 1.5, 1.75, 2.0, 2.0, 2.0, 2.0],
[1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75]]
float_leg_end_times = [[1.25, 1.5, 1.75, 2.0, 2.0, 2.0, 2.0, 2.0],
[1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0]]
fixed_leg_payment_times = [[1.25, 1.5, 1.75, 2.0, 2.0, 2.0, 2.0, 2.0],
[1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0]]
float_leg_daycount_fractions = [[0.25, 0.25, 0.25, 0.25, 0.0, 0.0, 0.0, 0.0],
[0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25]]
fixed_leg_daycount_fractions = [[0.25, 0.25, 0.25, 0.25, 0.0, 0.0, 0.0, 0.0],
[0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25]]
fixed_leg_coupon = [[0.011, 0.011, 0.011, 0.011, 0.0, 0.0, 0.0, 0.0],
[0.011, 0.011, 0.011, 0.011, 0.011, 0.011, 0.011, 0.011]]
zero_rate_fn = lambda x: 0.01 * tf.ones_like(x, dtype=dtype)
price = tff.models.hull_white.swaption_price(
expiries=expiries,
floating_leg_start_times=float_leg_start_times,
floating_leg_end_times=float_leg_end_times,
fixed_leg_payment_times=fixed_leg_payment_times,
floating_leg_daycount_fractions=float_leg_daycount_fractions,
fixed_leg_daycount_fractions=fixed_leg_daycount_fractions,
fixed_leg_coupon=fixed_leg_coupon,
reference_rate_fn=zero_rate_fn,
notional=100.,
dim=1,
mean_reversion=[0.03],
volatility=[0.02],
dtype=dtype)
# Expected value: [0.7163243383624043, 1.4031415262337608] # shape = (2,1)
Args:#
expiries: A realTensorof any shape and dtype. The time to expiration of the swaptions. The shape of this input determines the number (and shape) of swaptions to be priced and the shape of the output.floating_leg_start_times: A realTensorof the same dtype asexpiries. The times when accrual begins for each payment in the floating leg. The shape of this input should beexpiries.shape + [m]wheremdenotes the number of floating payments in each leg.floating_leg_end_times: A realTensorof the same dtype asexpiries. The times when accrual ends for each payment in the floating leg. The shape of this input should beexpiries.shape + [m]wheremdenotes the number of floating payments in each leg.fixed_leg_payment_times: A realTensorof the same dtype asexpiries. The payment times for each payment in the fixed leg. The shape of this input should beexpiries.shape + [n]wherendenotes the number of fixed payments in each leg.floating_leg_daycount_fractions: A realTensorof the same dtype and compatible shape asfloating_leg_start_times. The daycount fractions for each payment in the floating leg.fixed_leg_daycount_fractions: A realTensorof the same dtype and compatible shape asfixed_leg_payment_times. The daycount fractions for each payment in the fixed leg.fixed_leg_coupon: A realTensorof the same dtype and compatible shape asfixed_leg_payment_times. The fixed rate for each payment in the fixed leg.reference_rate_fn: A Python callable that accepts expiry time as a realTensorand returns aTensorof either shapeinput_shapeorinput_shape. Returns the continuously compounded zero rate at the present time for the input expiry time.mean_reversion: A real positive scalarTensoror a Python callable. The callable can be one of the following: (a) A left-continuous piecewise constant object (e.g.,tff.math.piecewise.PiecewiseConstantFunc) that has a propertyis_piecewise_constantset toTrue. In this case the object should have a methodjump_locations(self)that returns aTensorof shape[num_jumps]. The return value ofmean_reversion(t)should return aTensorof shapet.shape,tis a rank 1Tensorof the samedtypeas the output. See example in the class docstring. (b) A callable that accepts scalars (stands for timet) and returns a scalarTensorof the samedtypeasstrikes. Corresponds to the mean reversion rate.volatility: A real positiveTensorof the samedtypeasmean_reversionor a callable with the same specs as above. Corresponds to the long run price variance.notional: An optionalTensorof same dtype and compatible shape asstrikesspecifying the notional amount for the underlying swap. Default value: None in which case the notional is set to 1.is_payer_swaption: A booleanTensorof a shape compatible withexpiries. Indicates whether the swaption is a payer (if True) or a receiver (if False) swaption. If not supplied, payer swaptions are assumed.use_analytic_pricing: A Python boolean specifying if analytic valuation should be performed. Analytic valuation is only supported for constantmean_reversionand piecewise constantvolatility. If the input isFalse, then valuation using Monte-Carlo simulations is performed. Default value: The default value isTrue.num_samples: Positive scalarint32Tensor. The number of simulation paths during Monte-Carlo valuation. This input is ignored during analytic valuation. Default value: The default value is 1.random_type: Enum value ofRandomType. The type of (quasi)-random number generator to use to generate the simulation paths. This input is relevant only for Monte-Carlo valuation and ignored during analytic valuation. Default value:Nonewhich maps to the standard pseudo-random numbers.seed: Seed for the random number generator. The seed is only relevant ifrandom_typeis one of[STATELESS, PSEUDO, HALTON_RANDOMIZED, PSEUDO_ANTITHETIC, STATELESS_ANTITHETIC]. ForPSEUDO,PSEUDO_ANTITHETICandHALTON_RANDOMIZEDthe seed should be an Python integer. ForSTATELESSandSTATELESS_ANTITHETICmust be supplied as an integerTensorof shape[2]. This input is relevant only for Monte-Carlo valuation and ignored during analytic valuation. Default value:Nonewhich means no seed is set.skip:int320-dTensor. The number of initial points of the Sobol or Halton sequence to skip. Used only whenrandom_typeis ‘SOBOL’, ‘HALTON’, or ‘HALTON_RANDOMIZED’, otherwise ignored. Default value:0.time_step: Scalar realTensor. Maximal distance between time grid points in Euler scheme. Relevant when Euler scheme is used for simulation. This input is ignored during analytic valuation. Default value:None.dtype: The default dtype to use when converting values toTensors. Default value:Nonewhich means that default dtypes inferred by TensorFlow are used.name: Python string. The name to give to the ops created by this function. Default value:Nonewhich maps to the default namehw_swaption_price.
Returns:#
A Tensor of real dtype and shape expiries.shape containing the
computed swaption prices. For swaptions that have. reset in the past
(expiries<0), the function sets the corresponding option prices to 0.0.