bondInstrumentCalculator

首发版本:3.00.4.1

语法

bondInstrumentCalculator(bond, settlement, price, priceType, [calcRisk=false], [benchmark='Qeubee'], [isExercised], [taxRate=0], [taxStartDate=2025.08.08])

详情

债券计算器,实现债券价格 (ytm / cleanPrice / dirtyPrice) 三者互算,同时计算久期、凸度等风险指标。

支持浮动利率债券。计算时将 lastFixing + spread 作为票面利率,并按照固定利率债券的规则进行价格、收益率和风险指标计算。

参数

bond INSTRUMENT 类型标量或向量,表示债券金融工具。
注:
bond instrument 的 instrumentId 字段如果指定了后缀,且后缀为 .SH 或者 .SZ, 则债券会被视为交易所债券,它的应计利息计算会增加一天。

settlement DATE 类型标量或向量,表示债券的结算日,即购买日期。

price 数值型标量或向量,具体含义取决于 priceType 的取值:

  • priceType 为 "YTM" 时,price 表示债券的到期收益率;
  • priceType 为 "CleanPrice" 时,price 表示债券的净价;
  • priceType 为 "DirtyPrice" 时,price 表示债券的全价。
  • priceType 为 "YTE" 时,price 表示债券的行权收益率。

priceType STRING 类型的标量或向量,用于指定债券价格类型,可选值为:

  • "YTM":到期收益率
  • "CleanPrice":净价
  • "DirtyPrice":全价
  • "YTE":行权收益率,仅在 bond 为 OptionBond 时可用。

calcRisk 可选参数,布尔值,默认为 false,只计算输出全价、净价、应计利息和收益率。若设置为 true,除上述4项外,还会计算并输出麦考利久期、修正久期、凸度、基点价值。

benchmark 可选参数,STRING 类型标量,表示算法参考基准。目前支持:
  • "Qeubee"(默认值):表示终端算法。
  • "CSI":表示中证算法。
isExercised 可选参数,BOOL 类型标量,表示是否行权。
  • 如果不指定则会自动判断是否行权。
  • 如果指定为 true,则按照行权来计算。
  • 如果指定为 false 则按照不行权来计算。

taxRate DOUBLE 类型标量或向量,指定税率,用于对票息进行征税,本金不征税。默认值为 0,取值范围为 [0, 1)。该参数只适用于固定利率债券,其它品种债券若指定 taxRate > 0 会报错。

taxStartDate DATE 类型标量或向量,指定开始征税的日期。债券的起息日>=taxStartDate 时需要征税,之前发行的债券不需要。默认值为 2025.08.08。

返回值

一个字典,包含以下键值对:

是否必有
dirtyPrice 全价:包含应计利息的债券价格
cleanPrice 净价:不包含应计利息的债券价格
accruedInterest 应计利息
ytm 到期收益率
macaulayDuration 麦考利久期:投资者收回债券投资成本所需的平均时间

否,仅在 calcRisk=true 时返回

modifiedDuration 修正久期:用于衡量债券价格对收益率变化的敏感程度
convexity 凸度:用于衡量债券价格对利率变化的“二阶敏感度”
pvbp 基点价值:用于衡量债券价值对收益率变动的敏感程度,表示收益率变动一个基点所引起的债券价值变化金额
afterTaxDirty 税后全价 否,仅在 taxRate>0 时返回
afterTaxClean 税后净价
afterTaxYtm 税后到期收益率

例子

例1. 计算固定利率债券的价格、到期收益率、应计利息和风险指标。

fixedRateBondDict = {
    "productType": "Cash",
    "assetType": "Bond",
    "bondType": "FixedRateBond",
    "start": 2022.07.15,
    "maturity": 2072.07.15,
    "issuePrice": 100.0,
    "coupon": 0.034,
    "dayCountConvention": "ActualActualISMA",
    "calendar": "CFET",
    "frequency": "Semiannual"
}
fixedRateBond = parseInstrument(fixedRateBondDict);
bondInstrumentCalculator(fixedRateBond, settlement=2025.04.10, price=0.02, priceType="YTM", calcRisk=true);

/* Output:
dirtyPrice->143.4689
cleanPrice->142.6705
ytm->0.02
accruedInterest->0.7983
macaulayDuration->27.4761
modifiedDuration->27.2041
convexity->1025.4003
pvbp->0.3902
*/


bondInstrumentCalculator(fixedRateBond, settlement=2072.04.18, price=100.2143, priceType="CleanPrice", calcRisk=false);

/* Output:
dirtyPrice: 101.0923
cleanPrice: 100.2143
ytm: 0.0250
accruedInterest: 0.8780
*/

例2. 计算零息债券的价格、到期收益率、应计利息和风险指标。

zeroCouponBondDict = {
    "productType": "Cash",
    "assetType": "Bond",
    "bondType": "ZeroCouponBond",
    "coupon": 0.0119,
    "start": 2025.01.09,
    "maturity": 2026.02.05,
    "issuePrice": 100.0,
    "dayCountConvention": "ActualActualISMA",
    "calendar": "CFET"
}
zeroCouponBond = parseInstrument(zeroCouponBondDict);
bondInstrumentCalculator(zeroCouponBond, settlement=2025.04.10, price=0.025, priceType="YTM", calcRisk=true);

/* Output:
dirtyPrice->99.2322
cleanPrice->98.9355
ytm->0.025
accruedInterest->0.2966
macaulayDuration->0.8246
modifiedDuration->0.8079
convexity->1.3057
pvbp->0.0080
*/

例3. 计算贴现债券的价格、到期收益率、应计利息和风险指标。

discountBondDict = {
    "productType": "Cash",
    "assetType": "Bond",
    "bondType": "Discount",
    "start": 2025.02.13,
    "maturity": 2025.05.15,
    "issuePrice": 99.663,
    "dayCountConvention": "ActualActualISMA",
    "calendar": "CFET"
}
discountBond = parseInstrument(discountBondDict);
bondInstrumentCalculator(discountBond, settlement=2025.04.10, price=0.02, priceType="YTM", calcRisk=true);

/* Output:
dirtyPrice->99.8085
cleanPrice->99.6012
ytm->0.02
accruedInterest->0.2073
macaulayDuration->0.0958
modifiedDuration->0.0957
convexity->0.0183
pvbp->0.0009
*/

例4. 同时计算多种债券的价格、到期收益率、应计利息和风险指标。

result = bondInstrumentCalculator([discountBond, zeroCouponBond, fixedRateBond], settlement=[2025.04.10, 2025.04.10, 2072.04.18], price=[0.02, 0.025, 100.2143], priceType=["YTM", "YTM", "CleanPrice"], calcRisk=true);

print result

/* Output:
dirtyPrice->[99.8086,99.2322,101.09234]
cleanPrice->[99.6012,98.9356,100.2143]
accruedInterest->[0.2074,0.2969,0.8780]
ytm->[0.02,0.025,0.025]
macaulayDuration->[0.0959,0.8247,0.2404]
modifiedDuration->[0.0957,0.808,0.2397]
convexity->[0.0183,1.3057,0.1142]
pvbp->[0.0009,0.008,0.0024]
*/

例5. 计算含权债券的价格、到期收益率、应计利息和风险指标。

optionBond = {
    "productType": "Cash",
    "assetType": "Bond",
    "bondType": "OptionBond",
    "version": 0,
    "instrumentId": "242659.SH",
    "nominal": 100.0,
    "start": 2025.03.26,
    "maturity": 2030.03.26,
    "coupon": 0.0207,
    "frequency": "Annual",
    "exerciseDates": [2028.03.26],
    "hasCallOption": true,
    "hasPutOption": true,
    "hasCouponAdjust": true,
    "dayCountConvention": "ActualActualISMA"
}
ins = parseInstrument(optionBond)

bondInstrumentCalculator(ins, settlement=2025.12.19, price=0.0195216, priceType="YTM", calcRisk=true, benchmark="CSI");

/* Output:
dirtyPrice: 101.9939
cleanPrice: 100.4683
accruedInterest: 1.5256
ytm: 0.0195
yte: 0.0185
macaulayDuration: 2.2056
modifiedDuration: 2.1654
convexity: 6.9085
pvbp: 0.0221
*/

例6. 计算浮动利率债券的全价、净价、到期收益率和应计利息。

// 构造浮动利率债券产品字典
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
}

// 调用债券工具计算器

bondresult = bondInstrumentCalculator(
    bond = parseInstrument(floatingBond),
    settlement = 2025.04.10,
    price = 0.025,
    priceType = "YTM",
    calcRisk = false
)

print(bondresult)

/* Output:
ytm->0.025
accruedInterest->0.7918
cleanPrice->105.9626
dirtyPrice->106.7544
*/

例7. 计算固定利率债券的税前和税后价格、到期收益率以及应计利息。

fixedRateBondDict = {
    "productType": "Cash",
    "assetType": "Bond",
    "bondType": "FixedRateBond",
    "start": 2026.04.25,
    "maturity": 2027.04.25,
    "issuePrice": 100.0,
    "coupon": 0.0106,
    "dayCountConvention": "ActualActualISMA",
    "frequency": "Semiannual"
}
fixedRateBond = parseInstrument(fixedRateBondDict);


res = bondInstrumentCalculator(
    fixedRateBond,
    settlement=2026.06.25,
    price=0.0102996,
    priceType="YTM",
    calcRisk=false,
    taxRate=0.0634,
    taxStartDate=2025.08.08
);

res
/*
dirtyPrice: 100.20122678523695
cleanPrice: 100.02456011857029
accruedInterest: 0.17666666666666667
afterTaxDirty: 100.26806073041192
afterTaxClean: 100.09139406374526
afterTaxYtm: 0.009492960236371169
ytm: 0.0102996
*/

相关函数:bondPricer