irEuropeanSwaptionPricer

First introduced in version 3.00.6

Syntax

irEuropeanSwaptionPricer(instrument, pricingDate, discountCurve, forwardCurve, volSurf, [setting], [model], [method])

Details

Prices European interest rate swaptions.

Parameters

instrument is an INSTRUMENT scalar or vector that specifies the European interest rate swaption to price. For field requirements, see the product field description.

pricingDate is a DATE scalar or vector that specifies the pricing date.

discountCurve is an MKTDATA scalar or vector that specifies the spot curve (IrYieldCurve) used to calculate discount factors.

forwardCurve is an MKTDATA scalar or vector that specifies the spot curve (IrYieldCurve) used to calculate forward interest rates.

volSurf is an MKTDATA scalar or vector that specifies the volatility cube (IrSwaptionVolatilityCube). For field requirements, see the volatility cube field description.

setting is an optional dictionary that specifies whether to calculate option price sensitivities (Greeks).

Key Value Description
calcDelta Boolean. The default is false. Whether to calculate Delta, which measures the sensitivity of the option price to the underlying asset price.
calcGamma Boolean. The default is false. Whether to calculate Gamma, which measures the sensitivity of the option Delta to the underlying asset price.
calcVega Boolean. The default is false. Whether to calculate Vega, which measures the sensitivity of the option price to the underlying asset volatility.
calcTheta Boolean. The default is false. Whether to calculate Theta, which measures the sensitivity of the option price to the passage of time.
calcRho Boolean. The default is false. Specifies whether to calculate Rho, the sensitivity of the option price to the risk-free interest rate.

model is an optional STRING scalar that specifies the pricing model. Valid values are “Black76” and “Bachelier” (default).

method is an optional STRING scalar that specifies the pricing method. The default and only supported value is “Analytic”, which indicates the analytic pricing method.

Returns

  • If the setting parameter is not specified, the function returns a DOUBLE scalar that indicates the option's net present value (NPV), which is the theoretical price of the option.
  • If the setting parameter is specified, the function returns a Dictionary that contains the option's NPV and option price sensitivities (Greeks). For descriptions of the sensitivity measures, see the setting parameter description.

Examples

This example constructs a European interest rate swaption, a discount curve, a forward curve, and a swaption volatility cube. It then uses irEuropeanSwaptionPricer to price the swaption with the Bachelier model and calculate the price and risk measures, including Delta, Gamma, Vega, Theta, and Rho.

// =====================================================
// 1. Set basic pricing parameters
// =====================================================

// Pricing date
pricingDate = 2021.03.18

// Notional principal
notional = 50000000.0

// Fixed rate
fixedRate = 0.0365

// =====================================================
// 2. Construct the underlying interest rate swap
// =====================================================

underlyingSwapDict = {

    // Product category: Swap
    "productType": "Swap",

    // Swap type: interest rate swap
    "swapType": "IrSwap",

    // Interest rate swap subtype: fixed-for-floating
    "irSwapType": "IrFixedFloatingSwap",

    // Product identifier of the underlying swap
    "instrumentId": "CNY_LPR_1Y",

    // Notional principal
    "notionalAmount": notional,

    // Notional principal currency
    "notionalCurrency": "CNY",

    // Effective date of the underlying swap
    "start": 2021.06.18,

    // Maturity date of the underlying swap
    "maturity": 2024.06.18,

    // Cash flow payment frequency
    "frequency": "Annual",

    // Fixed-leg rate
    "fixedRate": fixedRate,

    // Floating-leg spread
    "spread": 0.0000,

    // Fixed-leg day count convention
    "fixedDayCountConvention": "Actual365",

    // Floating-leg day count convention
    "floatingDayCountConvention": "Actual360",

    // Trading calendar
    "calendar": "CFET",

    // Pay indicates that the underlying swap pays the fixed rate and receives the floating rate
    "payReceive": "Pay",

    "iborIndex": "LPR_1Y",

    "discountCurve": "CNY",

    "forwardCurve": "LPR_1Y"
}

// =====================================================
// 3. Construct the European swaption
// =====================================================

swaptionDict = {

    // Product category: Option
    "productType": "Option",

    // Option type: European option
    "optionType": "EuropeanOption",

    // Underlying asset type: European interest rate swaption
    "assetType": "IrEuropeanSwaption",

    // Product identifier
    "instrumentId": "SWPT_LPR1Y_3M3Y_PAY",

    // Swaption notional amount
    "notionalAmount": notional,

    // Swaption notional currency
    "notionalCurrency": "CNY",

    // Swaption exercise date
    "start": 2021.06.16,

    // Final maturity date of the underlying swap
    "maturity": 2024.06.18,

    // Strike rate
    "strike": fixedRate,

    // payoffType = Call
    "payoffType": "Call",

    // Underlying swap
    "underlying": underlyingSwapDict,

    // Day count convention used by the swaption
    "dayCountConvention": "Actual365"
}

// -----------------------------------------------------
// Parse the product dictionary into a financial product object recognized by the DolphinDB system
// -----------------------------------------------------
swaption = parseInstrument(swaptionDict)

// =====================================================
// 4. Construct yield curve node dates
// =====================================================

curveDates = pricingDate + [1, 92, 183, 365, 730, 1095, 1460, 1825]

// =====================================================
// 5. Construct the discount curve
// =====================================================

discountCurveInfo = {

    // Market data type: Curve
    "mktDataType": "Curve",

    // Curve type: interest rate yield curve
    "curveType": "IrYieldCurve",

    // Curve reference date
    "referenceDate": pricingDate,

    // Currency: CNY
    "currency": "CNY",

    // Curve day count convention
    "dayCountConvention": "Actual365",

    // Compounding method: continuous compounding
    "compounding": "Continuous",

    // Interpolation method: linear interpolation
    "interpMethod": "Linear",

    // Extrapolation method: flat extrapolation
    "extrapMethod": "Flat",

    // Compounding frequency
    "frequency": "NoFrequency",

    // Curve tenor node dates
    "dates": curveDates,

 // Continuously compounded zero rates at each tenor node on the curve
    "values": take(0.029, size(curveDates))
}


// -----------------------------------------------------
// Parse the discount curve dictionary into a market data object recognized by the DolphinDB system
// -----------------------------------------------------
discountCurve = parseMktData(discountCurveInfo)


// =====================================================
// 6. Construct the forward curve
// =====================================================

forwardCurveInfo = {

    // Market data type: Curve
    "mktDataType": "Curve",

    // Curve type: interest rate yield curve
    "curveType": "IrYieldCurve",

    // Curve reference date
    "referenceDate": pricingDate,

    // Currency: CNY
    "currency": "CNY",

    // Curve day count convention
    "dayCountConvention": "Actual365",

    // Compounding method: continuous compounding
    "compounding": "Continuous",

    // Interpolation method: linear interpolation
    "interpMethod": "Linear",

    // Extrapolation method: flat extrapolation
    "extrapMethod": "Flat",

    // Compounding frequency
    "frequency": "NoFrequency",

    // Curve tenor node dates
    "dates": curveDates,

    // Continuously compounded zero rates at each tenor node on the curve
    "values": take(0.037, size(curveDates))
}

// -----------------------------------------------------
// Parse the forward curve dictionary into a market data object recognized by the DolphinDB system
// -----------------------------------------------------
forwardCurve = parseMktData(forwardCurveInfo)

// =====================================================
// 7. Build the Swaption volatility cube
// =====================================================

flatLpr1ySwaptionCube = {

    // Volatility cube name
    "cubeName": "CNY_LPR_1Y_SWAPTION",

    // Market data type
    "mktDataType": "Cube",

    // Cube type
    "cubeType": "IrSwaptionVolatilityCube",

    // Reference date
    "referenceDate": pricingDate,

    // Currency
    "currency": "CNY",

    // Associated floating rate index
    "iborIndex": "LPR_1Y",

    // ATM option expiries
    "atmTerms": [0.25, 1.0, 2.0],

    // ATM underlying swap tenors
    "atmTenors": [1.0, 3.0, 5.0],

    // ATM volatility matrix
    // Rows correspond to atmTerms, and columns correspond to atmTenors
    "atmVols": matrix(
        [0.0055096937, 0.0058291888, 0.0060394000],
        [0.0060092120, 0.0063268352, 0.0065345735],
        [0.0063079263, 0.0066216700, 0.0068254044]
    ),

    // OTM option expiries
    "otmTerms": [0.25, 1.0, 2.0],

    // OTM underlying swap tenors
    "otmTenors": [1.0, 3.0, 5.0],

    // SABR parameter cube
    "paramCube": {

        // alpha controls the baseline volatility level.
        "alpha": matrix(
            [0.0055, 0.0058, 0.0060],
            [0.0060, 0.0063, 0.0065],
            [0.0063, 0.0066, 0.0068]
        ),

        // beta controls the shape of the SABR model.
        "beta": matrix(
            [0.0, 0.0, 0.0],
            [0.0, 0.0, 0.0],
            [0.0, 0.0, 0.0]
        ),

        // rho represents the correlation between stochastic shocks to the forward rate and volatility.
        "rho": matrix(
            [-0.20, -0.15, -0.10],
            [-0.20, -0.15, -0.10],
            [-0.15, -0.10, -0.05]
        ),

        // nu represents the volatility of volatility.
        "nu": matrix(
            [0.30, 0.25, 0.20],
            [0.28, 0.23, 0.18],
            [0.25, 0.20, 0.15]
        )
    }
}


// -----------------------------------------------------
// Parse the volatility cube dictionary into a market data object recognized by the DolphinDB system
// -----------------------------------------------------
volSurf = parseMktData(flatLpr1ySwaptionCube)

// =====================================================
// 8. Set pricing outputs
// =====================================================

setting = dict(STRING, ANY)
setting["calcDelta"] = true
setting["calcGamma"] = true
setting["calcVega"] = true
setting["calcTheta"] = true
setting["calcRho"] = true


// =====================================================
// 9. Call the European swaption pricer
// =====================================================

bachelierResult = irEuropeanSwaptionPricer(
    swaption,
    pricingDate,
    discountCurve,
    forwardCurve,
    volSurf,
    setting
)

// =====================================================
// 10. Output pricing results
// =====================================================

print("LPR1Y_PAYER_SWAPTION_SAMPLE Bachelier result = " + string(bachelierResult))
/*npv->LPR1Y_PAYER_SWAPTION_SAMPLE Bachelier result = 265595.520334303262643
delta->LPR1Y_PAYER_SWAPTION_SAMPLE Bachelier result = 92079255.637157037854194
gamma->LPR1Y_PAYER_SWAPTION_SAMPLE Bachelier result = 1.727311841805548E10
vega->LPR1Y_PAYER_SWAPTION_SAMPLE Bachelier result = 25749948.686961725354194
theta->LPR1Y_PAYER_SWAPTION_SAMPLE Bachelier result = -20524909.91052808612585
rho->LPR1Y_PAYER_SWAPTION_SAMPLE Bachelier result = 790326.494059825199656*/

Related functions: parseInstrument and parseMktData

Product Field Description

Field Name Type Description Required
productType STRING Must be "Option". Yes
optionType STRING Must be "EuropeanOption". Yes
assetType STRING Must be "IrEuropeanSwaption". Yes
instrumentId STRING Contract code, in the following standard format:"SWPT_reference rate_option expiry x swap tenor C/P"For example, "SWPT_LPR1Y_1Y5YC" represents a fixed-rate payer swaption with LPR1Y as the reference rate, an option expiry of 1Y, and a swap tenor of 5Y. No
start DATE Value date Yes
maturity DATE Maturity date Yes
strike DOUBLE Strike rate Yes
payoffType STRING Payoff type. Valid values are "Call" and "Put". Yes
underlying DICT/INSTRUMENT Underlying asset: a dictionary that can be parsed into an IrFixedFloatingSwap object, or an IrFixedFloatingSwap object Yes
dayCountConvention STRING Day count convention. Valid values are "ActualActualISDA", "ActualActualISMA", "Actual365", and "Actual360". Yes
discountCurve STRING Name of the discount curve used for pricing. For CNY deposits, the default is "CNY_FR_007". No
forwardCurve STRING Name of the forward curve used for pricing, for example, "CNY_LPR_1Y". No

Volatility Cube Field Description

Field Name Type Description Required
cubeName STRING Volatility cube name No
mktDataType STRING Market data type. Set this field to "Cube". Yes
cubeType STRING Surface type. Set this field to "IrSwaptionVolatilityCube". Yes
referenceDate DATE Reference date Yes
currency STRING Currency, for example, "CNY". Yes
iborIndex STRING Reference rate for the underlying interest rate swap Yes
atmTerms DOUBLE[] Expiry of the at-the-money (ATM) option, expressed as a year fraction Yes
atmTenors DOUBLE[] Tenor of the underlying interest rate swap for the ATM option, expressed as a year fraction Yes
atmVols DOUBLE Matrix Volatility of the ATM option, with shape size(atmTerms) * size(atmTenors) Yes
otmTerms DOUBLE[] Expiry of the out-of-the-money (OTM) option, expressed as a year fraction Yes
otmTenors DOUBLE[] Tenor of the underlying interest rate swap for the OTM option, expressed as a year fraction Yes
paramCube Dict(String, Double Matrix) Volatility smile parameters for the OTM option. Contains four keys: 'alpha', 'beta', 'rho', and 'nu'. Each key corresponds to one parameter, and its value is a DOUBLE matrix with shape size(otmTerms) * size(otmTenors). The value in row i and column j of the matrix is the value of that parameter at otmTerms[i] and otmTenors[j]. Yes
volType STRING Volatility type. The default value is "Normal". No