直接比較兩檔債券的存續期間
快速檢查某個因素對存續期間影響的方法,是比較兩檔只在該因素上有所差異的債券,觀察存續期間如何變化。
在本練習中,你要計算兩檔債券的存續期間:10 年期與 20 年期,兩者皆為年付 3% 息票、面額 USD 100,到期殖利率為 5%。
numpy_financial 已替你匯入為 npf。
本練習屬於課程
使用 Python 進行債券評價與分析
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Find & print duration of 10 year bond with 3% coupon & 5% yield
price_10y = -npf.pv(rate=0.05, nper=____, pmt=____, fv=____)
price_up_10y = -npf.pv(rate=0.06, nper=____, pmt=____, fv=____)
price_down_10y = -npf.pv(rate=0.04, nper=____, pmt=____, fv=____)
duration_10y = (____ - ____) / (____ * ____ * ____)
print("10 Year Bond: ", ____)