Bond Valuation and Analysis in Python
Joshua Mayhew
Options Trader
Convexity = % change in duration for 1% change in yields
Dollar convexity = $ change in duration for 1% change in yields:
$ \text{Dollar Convexity} = \text{Convexity} \times \text{Bond Price} \times 0.01^2$
price = -npf.pv(rate=0.05, nper=10, pmt=3, fv=100)
price_up = -npf.pv(rate=0.06, nper=10, pmt=3, fv=100)
price_down = -npf.pv(rate=0.04, nper=10, pmt=3, fv=100)
convexity = (price_down + price_up - 2 * price) / (price * 0.01 ** 2)
dollar_convexity = convexity * price * 0.01 ** 2
print("Dollar Convexity: ", dollar_convexity)
Dollar Convexity: 0.69
$ \text{Convexity Adjustment} = 0.5 \times \text{Dollar Convexity} \times 100^2 \times (\Delta y)^2$
price = -npf.pv(rate=0.05, nper=10, pmt=3, fv=100) price_up = -npf.pv(rate=0.06, nper=10, pmt=3, fv=100) price_down = -npf.pv(rate=0.04, nper=10, pmt=3, fv=100) convexity = (price_down + price_up - 2 * price) / (price * 0.01 ** 2)
dollar_convexity = convexity * price * 0.01 ** 2
convexity_adjustment = 0.5 * dollar_convexity * 100 ** 2 * 0.01 ** 2 print("Convexity Adjustment: ", convexity_adjustment)
Convexity Adjustment: 0.35
$ \text{Price Change} = -100 \times \text{Dollar Duration} \times \Delta y$
$ \text{Price Change} = -100 \times \text{Dollar Duration} \times \Delta y \ + \ \text{Convexity Adjustment}$
$ = -100 \times \text{Dollar Duration} \times \Delta y \ + \ 0.5 \times \text{Dollar Convexity} \times 100^2 \times (\Delta y)^2$
price = -npf.pv(rate=0.05, nper=10, pmt=3, fv=100)
price_up = -npf.pv(rate=0.06, nper=10, pmt=3, fv=100)
price_down = -npf.pv(rate=0.04, nper=10, pmt=3, fv=100)
duration = (price_down - price_up) / (2 * price * 0.01)
dollar_duration = duration * price * 0.01
convexity = (price_down + price_up - 2 * price) / (price * 0.01 ** 2)
dollar_convexity = convexity * price * 0.01
convexity_adjustment = dollar_convexity * 100 ** 2 * 0.01 ** 2
combined_prediction = -100 * dollar_duration * 0.01 + convexity_adjustment
print("Predicted Price Change: ", combined_prediction)
Predicted Price Change: -6.64
Bond Valuation and Analysis in Python