Example: Convexity for a Security
The convexity of a 10 year bond which pays interest semiannually is returned in this example.
using System;
using Imsl.Finance;
public class convexityEx1
{
public static void Main(String[] args)
{
DateTime settlement = DateTime.Parse("7/1/90");
DateTime maturity = DateTime.Parse("7/1/00");
double coupon = .075;
double yield = .09;
Bond.Frequency freq = Bond.Frequency.SemiAnnual;
DayCountBasis dcb = DayCountBasis.BasisActual365;
double convexity = Bond.Convexity(settlement, maturity, coupon,
yield, freq, dcb);
Console.Out.WriteLine("The convexity of the bond with semiannual "
+ "interest payments is " + convexity);
}
}
Output
The convexity of the bond with semiannual interest payments is 59.4049912915856
Link to C# source.