public static void CapletVol20Y_InputInterp() { #region Data // We load a set of data (not real) DataForCapletExample1 d = new DataForCapletExample1(); double[] df = d.df(); double[] yf = d.yf(); double[] T = d.T(); double[] fwd = d.fwd(); double[] atmfwd = d.atmfwd(); double[] capVol = d.capVol(); double[] avT = d.avT(); double[] avcapVol = d.avcapVol(); #endregion // All Data available double[] CapletVol = Formula.CapletVolBootstrapping(T, df, fwd, yf, capVol, atmfwd); // Cubic input SimpleCubicInterpolator CubicInt = new SimpleCubicInterpolator(avT, avcapVol); double[] cubicInterpCapVol = CubicInt.Curve(T); double[] CapletVolCubicInput = Formula.CapletVolBootstrapping(T, df, fwd, yf, cubicInterpCapVol, atmfwd); // Linear Input LinearInterpolator LinearInt = new LinearInterpolator(avT, avcapVol); double[] linearInterpCapVol = LinearInt.Curve(T); double[] CapletVolLinearInput = Formula.CapletVolBootstrapping(T, df, fwd, yf, linearInterpCapVol, atmfwd); #region print results ExcelMechanisms exl = new ExcelMechanisms(); Vector <double> CapletVol_ = new Vector <double>(CapletVol, 1); Vector <double> CapletVolCubicInput_ = new Vector <double>(CapletVolCubicInput, 1); Vector <double> CapletVolLinearInput_ = new Vector <double>(CapletVolLinearInput, 1); Vector <double> xarr = new Vector <double>(T, 1); List <string> labels = new List <string>() { "CapletVol All input", "CapVol Cubic Input", "CapVol Linear Input" }; List <Vector <double> > yarrs = new List <Vector <double> >() { CapletVol_, CapletVolCubicInput_, CapletVolLinearInput_ }; exl.printInExcel <double>(xarr, labels, yarrs, "Caplet Vol Input Interpolation", "Term", "Volatility"); #endregion }
// Target function to be minimised public void function_fvec(double[] VolGuess, double[] fi, object obj) { // Uncomment to change interpolator // LinearInterpolator interp = new LinearInterpolator(x, VolGuess); SimpleCubicInterpolator interp = new SimpleCubicInterpolator(x, VolGuess); double[] Vols = interp.Curve(T); // interpolated caplet vols double cP = 0.0; // Calculate Cap price using Caplet volatility for (int i = 0; i < x.Length; i++) { int maxJ = Array.IndexOf(T, x[i]); // right index cP = 0.0; for (int j = 0; j <= maxJ; j++) { cP += Formula.CapletBlack(T[j], yf[j], 1, atmfwd[maxJ], Vols[j], df[j], fwd[j]); } fi[i] = (capPremium[i] - cP) * 10000000; // minimise it! } }
// Calculate cubic interpolated rate for each starting time in T public double[] AllFwd_Cubic(double[] knownRatesStart, double[] knownFwd) { SimpleCubicInterpolator CU = new SimpleCubicInterpolator(knownRatesStart, knownFwd); return(CU.Curve(T)); // getting Cubic interpolated data }