bondInstrumentCalculator
First introduced in version: 3.00.4.1
Syntax
bondInstrumentCalculator(bond, settlement, price, priceType,
[calcRisk=false], [benchmark='Qeubee'], [isExercised])
Details
Performs conversion among yield to maturity, clean price, and dirty price, and calculates risk measures such as duration and convexity.
Supports floating-rate bonds. The calculator uses lastFixing +
spread as the coupon rate and applies the fixed-rate bond calculation
rules for price, yield, and risk measures.
Parameters
bond is an INSTRUMENT scalar/vector representing the bond instrument(s). If the instrumentId field of the bond instrument has the .SH or .SZ suffix, the bond is treated as an exchange-traded bond and one day is added when calculating accrued interest.
settlement is a DATE scalar/vector indicating the bond settlement date.
price is a numeric scalar/vector. Its meaning depends on priceType:
- When priceType is "YTM", price indicates the yield to maturity.
- When priceType is "CleanPrice", price indicates the clean price.
- When priceType is "DirtyPrice", price indicates the dirty price.
- When priceType is "YTE", price indicates the yield to exercise.
priceType is a STRING scalar/vector specifying the bond price type. It can take the following values:
- "YTM": Yield to maturity.
- "CleanPrice": Clean price.
- "DirtyPrice": Dirty price.
- "YTE": Yield to exercise. It is available only when bond is an OptionBond.
calcRisk (optional) is a BOOL value. The default value is false, indicating that only dirty price, clean price, accrued interest, and yield are returned. If it is set to true, Macaulay duration, modified duration, convexity, and PVBP are also calculated.
benchmark (optional) is a STRING scalar indicating the benchmark algorithm. It can take the following values:
- "Qeubee" (default): Uses the terminal algorithm.
- "CSI": Uses the China Securities Index algorithm.
isExercised (optional) is a BOOL scalar indicating whether the option is exercised:
- If unspecified, the function automatically determines whether it is exercised.
- If set to true, the calculation assumes exercise.
- If set to false, the calculation assumes no exercise.
Returns
A dictionary or a tuple.
Examples
Calculate the dirty price, clean price, yield to maturity, and accrued interest of a floating-rate bond:
floatingBond = {
"productType": "Cash",
"assetType": "Bond",
"bondType": "FloatingRateBond",
"instrumentId": "240025.IB",
"start": 2022.07.15,
"maturity": 2032.07.15,
"frequency": "Semiannual",
"dayCountConvention": "Actual365",
"iborIndex": "LPR_1Y",
"spread": 0.004,
"lastFixing": 0.03
}
bondInstrumentCalculator(
bond=parseInstrument(floatingBond),
settlement=2025.04.10,
price=0.02,
priceType="YTM",
calcRisk=false
)
/* output:
ytm->0.02
accruedInterest->0.7917808219178083
cleanPrice->109.44019061145833
dirtyPrice->110.23197143337615
*/
Related functions: bondPricer
