Bond convexity
Convexity is the sensitivity measure of the duration of a bond to yield changes. Think of convexity as the second derivative of the relationship between the price and yield:
Bond traders use convexity as a risk management tool to measure the amount of market risk in their portfolio. Higher convexity portfolios are less affected by interest rate volatilities than lower convexity portfolio, given the same bond duration and yield. As such, higher convexity bonds are more expensive than lower convexity ones, everything else being equal.
The implementation of a bond convexity is given as follows:
""" Calculate convexity of a bond """ from bond_ytm import bond_ytm from bond_price import bond_price def bond_convexity(price, par, T, coup, freq, dy=0.01): ytm = bond_ytm(price, par, T, coup, freq) ytm_minus = ytm - dy price_minus = bond_price(par, T, ytm_minus, coup, freq) ytm_plus = ytm + dy price_plus = bond_price(par, T, ytm_plus, coup, freq) ...