债券到底有多“长”?
到期日说明最后一笔款项何时到账,但付高额票息的债券会更早地收回大部分本金。麦考利久期是收到现金流的平均时间,把每个付款时间按其占价格的比例加权:sum(t * PV(t)) / 价格。零息债券的久期等于其期限;票息会拉低久期。我们这只收益率 6%、票息 5% 的 10 年期债券,久期是 7.9 年。久期是债券在时间上的真实长度。
import numpy as np
def bond_cashflows(face, coupon_rate, years, freq):
n = int(round(years * freq))
times = np.arange(1, n + 1) / freq
flows = np.full(n, face * coupon_rate / freq)
flows[-1] += face
return times, flows
times, flows = bond_cashflows(1000, 0.05, 10, 2)
pv = flows / (1 + 0.06 / 2) ** (2 * times) # present value of each payment
price = pv.sum()
macaulay = (times * pv).sum() / price # the average time, weighted by present value
print(round(price, 4), round(macaulay, 4)) # 925.6126 7.895 shorter than the 10-year maturity从久期到价格风险
除以 1 + ytm / freq 得到修正久期,它有直接的含义:收益率上升一个单位(100 个点)时价格下跌的百分比,所以修正久期 7.67 表示一阶近似下收益率每升 1 个百分点价格约跌 7.67%:dP / P ≈ -D_mod * dy。风险部门把这个数字作为债券的利率敏感度。它还解释了上一节中长期债券为什么比短期债券跌得多得多:久期更高。
modified = macaulay / (1 + 0.06 / 2)
print(round(modified, 4)) # 7.6654 about -7.67% of price for +1 percentage point of yield
dy = 0.01
print(round(price * (1 - modified * dy), 2)) # 854.66 the first-order estimate after a rise to 7%
# the exact price at 7% is 857.88: duration alone underestimates it凸性:曲率
价格与收益率的关系是一条曲线而不是直线,久期只是它的切线。由于曲线向上弯曲,切线对任一方向的变动都低估价格:收益率下降时债券的获利大于同等幅度上升时的亏损。凸性由二阶导数度量这种弯曲:sum(现金流 * t * (t + 1/freq) / (1 + y/freq) ** (freq * t + 2)) / 价格。把 0.5 * 凸性 * dy² 这一项加到久期估计上,价格预测会好得多,变动越大越重要。
convexity = (flows * times * (times + 1 / 2) / (1 + 0.06 / 2) ** (2 * times + 2)).sum() / price
print(round(convexity, 3)) # 71.785
for dy in (0.01, -0.01, 0.03):
exact = bond_price(1000, 0.05, 0.06 + dy, 10)
duration_only = price * (1 - modified * dy)
with_convexity = price * (1 - modified * dy + 0.5 * convexity * dy ** 2)
print(dy, round(exact, 2), round(duration_only, 2), round(with_convexity, 2))
# 0.01 857.88 854.66 857.99
# -0.01 1000.0 996.56 999.88
# 0.03 739.84 712.77 742.67 for a big move convexity matters most# Duration by maturity for a 5% bond at a 6% yield: it grows with maturity, but slower than one for one
for years in (1, 5, 10, 30):
t_, f_ = bond_cashflows(1000, 0.05, years, 2)
p_ = f_ / (1 + 0.06 / 2) ** (2 * t_)
print(years, round((t_ * p_).sum() / p_.sum(), 3))
# 1 0.988
# 5 4.472
# 10 7.895
# 30 14.77久期适用于小幅变动久期假设单一收益率平行移动;真实曲线会扭曲,大幅变动还需要凸性。用久期比较债券的利率风险并对冲小幅变化。对于几个点的情景,请像
bond_price 那样把债券完整重新定价。- 麦考利久期 =
sum(t * PV) / 价格,收回资金的平均时间;零息债券的久期等于期限。 - 修正久期 = 麦考利久期 /
(1 + ytm / freq):收益率每升 1 的相对价格跌幅,dP / P ≈ -D_mod * dy。 - 价格估计 =
价格 * (1 - D_mod * dy + 0.5 * 凸性 * dy²);凸性项修正切线,对大幅变动尤其重要。
下一节:收益率曲线与插值,因为不同期限有不同的利率。
实验:评分内容
- 用
macaulay_duration求收回资金的平均时间25 分 - 用
modified_duration把它变成价格敏感度25 分 - 用
convexity捕捉曲率25 分 - 用
price_estimate不重新定价就预测新价格25 分