Calculates the convexity of a bond.
This function is normally used in combination with total_return() to compute bond total returns.
convexity(yields, maturity, format_out = "xts")The convexity or a series of convexities of a bond with the given yield and maturity
a series of yields
constant bond maturity in years
xts or tibble
This function is normally used in combination with total_return() to compute bond total returns.
The convexity is the interest rate sensitivity of the modified duration.
$$convexity = C_1 - C_2$$
where
$$C_1 = \frac{2}{y_t^2} (1-{z_t}^{-2M})$$ $$C_2 = \frac{2M}{y_t}{z_t}^{-2M-1}$$ $$z_t = 1+\frac{y_t}{2}$$
\(M\) is the maturity in years (e.g. 10), \(y_t\) is the yield at time \(t\).