bondPricer
Syntax
bondPricer(instrument, pricingDate, discountCurve, [spreadCurve],
[setting])
Details
Prices a bond instrument, supporting output of multiple risk measures, including (NPV (Net Present Value), Delta (first-order sensitivity), Gamma (second-order sensitivity), and Key Rate Duration (sensitivity to interest rate shifts at specified key maturities).
Return value:
-
If setting is not specified, returns the NPV (a DOUBLE scalar).
-
If setting is specified, returns a Dictionary<STRING, ANY> with the following key-value pairs:
-
"npv": A DOUBLE scalar
-
"discountCurveDelta": A DOUBLE scalar
-
"discountCurveGamma": A DOUBLE scalar
-
"discountCurveKeyRateDuration": A DOUBLE vector
-
Arguments
instrument is an INSTRCMENT object representing the bond to be priced. The required key fields vary depending on the type of bond product; see Bond Product Field Specifications for details.
pricingDate is a DATE scalar specifying the pricing date.
discountCurve is a MKTDATA object of type IrYieldCurve representing the discount curve. See Curve Field Specifications for details.
spreadCurve (optional) is a MKTDATA object of type IrYieldCurve representing the credit spread curve. If not specified, defaults to a flat curve with 0% spread. See Curve Field Specifications for details.
setting (optional)is a Dictionary<STRING, ANY> with the following key-value pairs:
Key | Value Type | Description |
---|---|---|
"calcDiscountCurveDelta" | BOOL | Whether to compute the bond’s first-order sensitivity (delta) to the discount curve. |
"calcDiscountCurveGamma" | BOOL | Whether to compute the bond’s second-order sensitivity (gamma) to the discount curve. |
"calcDiscountCurveKeyRateDuration" | BOOL | Whether to compute the bond’s key rate durations. |
"discountCurveShift" | DOUBLE scalar | The parallel shift applied to the discount curve. For example, a bp(0.0001). |
"discountCurveKeyTerms" | DOUBLE scalar/vector | The specific maturity point(s) to calculate the key rate duration. For example, [1.0, 3.0, 5.0]. |
"discountCurveKeyShifts" | DOUBLE scalar/vector | The shift amounts corresponding to each maturity point. It has the same length with discountCurveKeyTerms. For example, [0.0001, 0.0002, 0.0015]. |
Examples
bond = {
"productType": "Cash",
"assetType": "Bond",
"bondType": "FixedRateBond",
"version": 0,
"instrumentId": "240025.IB",
"start": 2024.12.25,
"maturity": 2031.12.25,
"issuePrice": 100.0,
"coupon": 0.0149,
"frequency": "Annual",
"dayCountConvention": "ActualActualISDA"
}
pricingDate = 2025.08.18
curve = {
"mktDataType": "Curve",
"curveType": "IrYieldCurve",
"referenceDate": pricingDate,
"currency": "CNY",
"curveName": "CNY_TREASURY_BOND",
"dayCountConvention": "ActualActualISDA",
"compounding": "Compounded",
"interpMethod": "Linear",
"extrapMethod": "Flat",
"frequency": "Annual",
"dates":[2025.09.18, 2025.11.18, 2026.02.18, 2026.08.18, 2027.08.18, 2028.08.18, 2030.08.18,
2032.08.18, 2035.08.18, 2040.08.18, 2045.08.18, 2055.08.18,2065.08.18, 2075.08.18],
"values":[1.3000, 1.3700, 1.3898, 1.3865, 1.4299, 1.4471, 1.6401,
1.7654, 1.7966, 1.9930, 2.1834, 2.1397, 2.1987, 2.2225] / 100.0
}
instrument = parseInstrument(bond)
discountCurve = parseMktData(curve)
setting = dict(STRING, ANY)
setting["calcDiscountCurveDelta"] = true
setting["calcDiscountCurveGamma"] = true
setting["calcDiscountCurveKeyRateDuration"] = true
setting["discountCurveShift"] = 0.0001
setting["discountCurveKeyTerms"] = [1.0, 3.0, 5.0]
setting["discountCurveKeyShifts"] = [0.0002, 0.0003, 0.0001]
results = bondPricer(instrument, pricingDate, discountCurve, setting=setting)
print(results)
/* output:
npv->99.600846811350891
discountCurveDelta->-592.25994127828585
discountCurveGamma->4223.064257757869199
discountCurvekeyRateDuration->[0.012669167121743,0.069982332985636,1.955786205709234]
*/
Related functions: parseInstrument, parseMktData
Bond Product Field Specifications
Discount Bond
Field Name | Data Type | Description | Required |
---|---|---|---|
productType | STRING | Must be "Cash" | √ |
assetType | STRING | Must be "Bond" | √ |
bondType | STRING | Must be "DiscountBond" | √ |
version | INT | Version, default 0 | × |
nominal | DOUBLE | Nominal amount, defalut 100 | × |
instrumentId | STRING | Bond code, e.g., "259926.IB" | × |
start | DATE | Value date | √ |
maturity | DATE | Maturity date | √ |
dayCountConvention | STRING | The day count convention. It can be: "ActualActualISDA", "ActualActualISMA"," Actual365", "Actual360" | √ |
issuePrice | DOUBLE | Issue price | √ |
currency | STRING | Currency, defaults to "CNY" | × |
cashFlow | TABLE | Cash flow table | × |
discountCurve | STRING | The discount curve, e.g., "CNY_TRASURY_BOND" | × |
spreadCurve | STRING | The credit spread curve | × |
subType | STRING |
Subtypes. China's bonds include:
|
× |
creditRating | STRING | Credit rating. It can be: "B", "BB", "BBB", "BBB+", "A-", "A", "A+", "AA-", "AA", "AA+", "AAA-", "AAA", "AAA+" | × |
Zero Coupon Bond
Field Name | Data Type | Description | Required |
---|---|---|---|
productType | STRING | Must be "Cash" | √ |
assetType | STRING | Must be "Bond" | √ |
bondType | STRING | Must be "ZeroCouponBond" | √ |
version | INT | Version, default 0 | × |
nominal | DOUBLE | Nominal amount, defalut 100 | × |
instrumentId | STRING | Bond code, e.g., "259926.IB" | × |
start | DATE | Value date | √ |
maturity | DATE | Maturity date | √ |
coupon | DOUBLE | Coupon rate, e.g., 0.03 means 3% | √ |
frequency | STRING | Frequency of interest payment | √ |
dayCountConvention | STRING | The day count convention. It can be: "ActualActualISDA", "ActualActualISMA"," Actual365", "Actual360" | √ |
currency | STRING | Currency, defaults to "CNY" | × |
cashFlow | TABLE | Cash flow table | × |
discountCurve | STRING | The discount curve, e.g., "CNY_TRASURY_BOND" | × |
spreadCurve | STRING | The credit spread curve | × |
subType | STRING |
Subtypes. China's bonds include:
|
× |
creditRating | STRING | Credit rating. It can be: "B", "BB", "BBB", "BBB+", "A-", "A", "A+", "AA-", "AA", "AA+", "AAA-", "AAA", "AAA+" | × |
Fixed Rate Bond
Field Name | Data Type | Description | Required |
---|---|---|---|
productType | STRING | Must be "Cash" | √ |
assetType | STRING | Must be "Bond" | √ |
bondType | STRING | Must be "FixedRateBond" | √ |
version | INT | Version, default 0 | × |
nominal | DOUBLE | Nominal amount, defalut 100 | × |
instrumentId | STRING | Bond code, e.g., "259926.IB" | × |
start | DATE | Value date | √ |
maturity | DATE | Maturity date | √ |
coupon | DOUBLE | Coupon rate, e.g., 0.03 means 3% | √ |
frequency | STRING | Frequency of interest payment | √ |
dayCountConvention | STRING | The day count convention. It can be: "ActualActualISDA", "ActualActualISMA"," Actual365", "Actual360" | √ |
currency | STRING | Currency, defaults to "CNY" | × |
cashFlow | TABLE | Cash flow table | × |
discountCurve | STRING | The discount curve, e.g., "CNY_TRASURY_BOND" | × |
spreadCurve | STRING | The credit spread curve | × |
subType | STRING |
Subtypes. China's bonds include:
|
× |
creditRating | STRING | Credit rating. It can be: "B", "BB", "BBB", "BBB+", "A-", "A", "A+", "AA-", "AA", "AA+", "AAA-", "AAA", "AAA+" | × |
Curve Field Specifications
Field Name | Data Type | Description | Required |
---|---|---|---|
mktDataType | STRING | Must be "Curve" | √ |
referenceDate | DATE | Reference Date | √ |
version | INT | Version, default 0 | × |
curveType | STRING | Must be "IrYieldCurve" | √ |
dayCountConvention | STRING |
The day count convention to use. It can be:
|
√ |
interpMethod | STRING |
Interpolation method. It can be:
|
√ |
extrapMethod | STRING |
Extrapolation method. It can be
|
√ |
dates | DATE vector | Date of each data point | √ |
values | DOUBLE vector | Value of each data point, corresponding to the elements in dates. | √ |
curveName | STRING | Curve name | × |
currency | STRING | Currency. It can be CNY", "USD", "EUR", "GBP", "JPY", "HKD" | √ |
compounding | STRING |
The compounding interest. It can be:
|
√ |
settlement | DATE | Settlement date. If specified, all subsequent tenor intervals are computed starting from "settlement" rather than from "referenceDate". | × |
frequency | INTEGRAL/STRING |
The interest payment frequency. Supported values:
|
× |
curveModel | STRING |
Curve construction model; It can be "Bootstrap" (default), "NS", "NSS". When the value is "NSS" or "NS", the fields interpMethod, extrapMethod, dates, and values are not required. |
× |
curveParams | DICT |
Model parameters. It is required when curveModel is "NSS" or "NS":
|
× |