开始使用免费开始使用

预测价格与实际价格 I

使用久期在不同收益率水平下预测债券价格,并将这些预测价格与债券的实际价格进行比较,是直观检验久期准确性的好方法。

本练习中,您将先计算该债券的久期,以及在不同收益率下的债券价格。下一练习,您将用久期得出预测价格并绘制二者差异。

所考虑的债券为一只期限 10 年、年付 5% 息票、到期收益率(YTM)为 5% 的债券。

numpynumpy_financialpandasmatplotlib 已分别以 npnpfpdplt 的别名为您导入。

本练习是课程的一部分

用 Python 进行债券定价与分析

查看课程

练习说明

  • 计算该债券的久期和美元久期。
  • 创建一个从 0 到 10、步长为 0.1 的债券收益率数组,并将其转换为名为 bond_yieldpandas DataFrame。
  • 添加名为 price 的列,包含每个收益率水平对应的债券价格。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Price a 10 year bond with 5% coupon and 5% yield, reprice at higher and lower yields
price = ____
price_up = ____
price_down = ____

# Find the duration and dollar duration of the bond
duration = ____
dollar_duration = ____ * ____ * ____

# Create an array of yields from 0 to 10 in steps of 0.1, convert to DataFrame
bond_yields = np.arange(____, ____, ____)
bond = pd.DataFrame(____, columns=['bond_yield'])

# Add a column called price with the bond price for each yield level
bond['price'] = -npf.pv(rate=bond['bond_yield'] / 100, ____, ____, ____)
编辑并运行代码