irSwaptionVolatilityCubeBuilder
First introduced in version: 3.00.6
Syntax
irSwaptionVolatilityCubeBuilder(referenceDate, underlying, atmTenors,
atmTerms, atmVols, otmTenors, otmTerms, otmStrikes, otmVols, discountCurve,
forwardCurve, [volType='Normal'], [model='SABR'], [cubeName])
Details
Builds an interest rate swaption volatility cube.
Parameters
referenceDate is a DATE scalar specifying the reference date of the volatility cube.
underlying is a STRING scalar specifying the name of the underlying asset. It can be "CNY_FR_007", "CNY_SHIBOR_3M", "CNY_LPR_1Y", "CNY_LPR_5Y".
atmTenors is a DURATION vector specifying the tenor of the interest rate swap for at-the-money (ATM) options.
atmTerms is a DURATION vector specifying the term of the ATM options.
atmVols is a DOUBLE matrix specifying the volatilities of the ATM options. The number of rows matches the length of atmTerms, and the number of columns matches the length of atmTenors. The element at row i and column j corresponds to the volatility of the ATM option with the term of atmTerms[i] and the tenor of atmTenors[j].
otmTenors is a DURATION vector specifying the tenors of the interest rate swap for out-of-the-money (OTM) options.
otmTerms is a tuple of DURATION vectors specifying the terms of OTM options. It has the same length as otmTenors, where otmTerms[i] is the term vector of OTM options corresponding to otmTenors[i].
otmStrikes is a DOUBLE vector specifying the strikes of out-of-the-money (OTM) options expressed as offsets relative to the forward swap rate (under the standard Black/Bachelier forward-ATM convention, where the ATM strike equals the forward par swap rate).
otmVols is a tuple of DOUBLE matrices specifying the volatilities of OTM options. It has the same length as otmTenors, where otmVols[i] is the volatility matrix of OTM options corresponding to otmTenors[i]. The number of rows in the matrix matches the length of otmTerms[i], and the number of columns matches the length of otmStrikes. Within each matrix, the element at row m and column m corresponds to the volatility of an OTM option with the tenor of otmTerms[i][m] and a strike offset of otmStrikes[n].
discountCurve is a MKTDATA scalar/vector of IrYieldCurve type specifying the discount curve(s).
forwardCurve is a MKTDATA scalar/vector of IrYieldCurve type specifying the spot curve(s).
volType (optional) is a STRING scalar specifying the volatility type. The default value is "Normal". It can be "Normal" (normal volatility) or "Lognormal" (lognormal volatility).
model (optional) is a STRING scalar specifying the model used to build the volatility cube. Currently, only "SABR" is supported.
cubeName (optional) is a STRING scalar specifying the name of the volatility cube. The default value is "IRSWAPTIONVOLCUBE/{underlying}". with underlying indicating the underlying parameter.
Returns
A MKTDATA object of type IrSwaptionVolatilityCube indicating the interest rate swaption volatility cube.
Examples
Builds an interest rate swaption volatility cube.
// =====================================================
// I. Custom Yield Curve Creation Function
// =====================================================
def createLpr1yFlatCurve(asOfDate, zeroRate){
// -------------------------------------------------
// 1. Construct the pillar dates for the yield curve
// -------------------------------------------------
pillarDates = asOfDate + [1, 92, 183, 365, 730, 1095, 1460, 1825, 2555, 3650]
// -------------------------------------------------
// 2. Construct the zero rates at each pillar date
// -------------------------------------------------
pillarValues = take(zeroRate, size(pillarDates))
// -------------------------------------------------
// 3. Construct the market data dictionary for the yield curve
// -------------------------------------------------
curveDict = {
// Market data type: "Curve" indicates curve-type market data
"mktDataType": "Curve",
// Curve type: "IrYieldCurve" represents an interest rate yield curve
"curveType": "IrYieldCurve",
// Curve valuation date
"referenceDate": asOfDate,
// Currency: CNY (Chinese Yuan)
"currency": "CNY",
// Curve name
"curveName": "CNY_LPR_1Y",
// Day count convention: Actual365
"dayCountConvention": "Actual365",
// Compounding method: Continuous compounding
"compounding": "Continuous",
// Interpolation method: Linear
"interpMethod": "Linear",
// Extrapolation method: Flat
"extrapMethod": "Flat",
// Payment frequency: No frequency
"frequency": "NoFrequency",
// Curve pillar dates
"dates": pillarDates,
// Zero rates corresponding to each curve pillar
"values": pillarValues
}
// -------------------------------------------------
// 4. Parse the dictionary into a market data object and return it
// -------------------------------------------------
return parseMktData(curveDict)
}
// =====================================================
// II. Create Valuation Date and CNY LPR 1Y Flat Yield Curve
// =====================================================
aod = 2021.03.18
// Create a CNY LPR 1Y flat yield curve with a zero rate of 3.40%
cnyCurve = createLpr1yFlatCurve(aod, 0.0340)
// =====================================================
// III. Define ATM Swaption Volatility Grid
// =====================================================
// Option maturity terms
atmTerms = [6M, 1y, 2y]
// Underlying swap tenors (swap tenor)
atmTenors = [1y, 3y, 5y]
// -----------------------------------------------------
// At-The-Money (ATM) option volatility matrix
//
// atmVols is a 3 x 3 matrix:
// Rows correspond to atmTerms (option maturities): [6M, 1y, 2y]
// Columns correspond to atmTenors (underlying swap tenors): [1y, 3y, 5y]
// Note: In DolphinDB, matrices are column-major; the same applies to subsequent examples
// -----------------------------------------------------
atmVols = matrix(
0.0058 0.0061 0.0063,
0.0061 0.0065 0.0067,
0.0064 0.0066 0.0069
)
// =====================================================
// IV. Define OTM Swaption Volatility Data
// OTM = Out of The Money, representing out-of-the-money option volatilities.
// This is typically used to describe the volatility smile structure under different strike offsets.
// =====================================================
// Underlying swap tenors corresponding to OTM data
otmTenors = [1y, 3y, 5y]
// List of option terms corresponding to each OTM tenor
// Written as [atmTerms, atmTerms, atmTerms], meaning: for each underlying swap tenor (1y, 3y, 5y), the same set of option maturities [6M, 1y, 2y] is used.
otmTerms = [atmTerms, atmTerms, atmTerms]
// Strike offsets for out-of-the-money options
otmStrikes = [-0.0020, -0.0010, 0.0000, 0.0010, 0.0020]
// =====================================================
// V. OTM Volatility Matrices for Different Underlying Swap Tenors
//
// Each matrix corresponds to a swap tenor.
// For example:
// otmVols1y corresponds to an underlying swap tenor of 1y;
// otmVols3y corresponds to an underlying swap tenor of 3y;
// otmVols5y corresponds to an underlying swap tenor of 5y.
// Each matrix is 3 x 5:
// Columns correspond to otmStrikes, with 5 strike offsets in total;
// Rows correspond to option terms: [6M, 1y, 2y].
// =====================================================
// -----------------------------------------------------
// 1. OTM volatility matrix when the underlying swap tenor is 1y
// Columns: otmStrikes = [-20bp, -10bp, 0bp, +10bp, +20bp]
// Rows: atmTerms = [6M, 1y, 2y]
// -----------------------------------------------------
otmVols1y = matrix(
0.0063 0.0067 0.0068,
0.0060 0.0065 0.0066,
0.0058 0.0061 0.0063,
0.0061 0.0064 0.0065,
0.0063 0.0068 0.0069
)
// -----------------------------------------------------
// 2. OTM volatility matrix when the underlying swap tenor is 3y
// Columns: otmStrikes
// Rows: atmTerms
// -----------------------------------------------------
otmVols3y = matrix(
0.0066 0.0069 0.0072,
0.0063 0.0066 0.0070,
0.0061 0.0065 0.0067,
0.0064 0.0067 0.0069,
0.0067 0.0070 0.0071
)
// -----------------------------------------------------
// 3. OTM volatility matrix when the underlying swap tenor is 5y
// Columns: otmStrikes
// Rows: atmTerms
// -----------------------------------------------------
otmVols5y = matrix(
0.0070 0.0071 0.0074,
0.0067 0.0069 0.0072,
0.0064 0.0066 0.0069,
0.0067 0.0068 0.0071,
0.0070 0.0072 0.0075
)
// -----------------------------------------------------
// Put the OTM volatility matrices for different swap tenors into a list
// -----------------------------------------------------
otmVols = [otmVols1y, otmVols3y, otmVols5y]
// =====================================================
// VI. Build the Swaption Volatility Cube
// The swaption volatility cube organizes volatility data across three dimensions:
// 1. option term: option maturity, e.g., 6M, 1y, 2y
// 2. swap tenor: underlying swap tenor, e.g., 1y, 3y, 5y
// 3. strike: strike rate offset, e.g., -20bp, -10bp, ATM, +10bp, +20bp
// The ATM volatility matrix provides at-the-money volatilities;
// The OTM volatility matrices provide volatility smile information under different strike offsets.
// =====================================================
swaptionVolCube = irSwaptionVolatilityCubeBuilder(
// Valuation date
aod,
// Yield curve name
// Must be consistent with the curveName in the previous curveDict
"CNY_LPR_1Y",
// ATM underlying swap tenors
atmTenors,
// ATM option maturities
atmTerms,
// ATM volatility matrix
atmVols,
// OTM underlying swap tenors
otmTenors,
// OTM option maturities
otmTerms,
// OTM strike offsets
otmStrikes,
// List of OTM volatility matrices
otmVols,
// Discount curve
cnyCurve,
// Forward curve
cnyCurve
)
print(swaptionVolCube)
Releated links: parseMktData
