Beispiel #1
0
    public static void MatrixCaplet()
    {
        #region Data
        // We load a set of data (not real)
        DataForCapletExample2 d = new DataForCapletExample2();
        double[]        df      = d.df();
        double[]        yf      = d.yf();
        double[]        T       = d.T();
        double[]        avT     = d.avT();
        List <double[]> VolArr  = d.VolArr();
        double[]        fwd     = d.fwd();
        double[]        strike  = d.strike();

        List <double[]> VolSilos = new List <double[]>();
        foreach (double[] cVol in VolArr)
        {
            LinearInterpolator LinearInt = new LinearInterpolator(avT, cVol);
            VolSilos.Add(LinearInt.Curve(T));
        }

        #endregion
        // Here you can change the MonoStrikeCaplet Builder
        CapletMatrixVolBuilder <MonoStrikeCapletVolBuilderPWC> B = new CapletMatrixVolBuilder <MonoStrikeCapletVolBuilderPWC>(T, df, fwd, yf, avT, VolSilos, strike);

        // CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderBestFitSmooth> B = new CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderBestFitSmooth>(T, df, fwd, yf, avT, VolSilos, strike);
        // and more...

        #region print results
        ExcelMechanisms exl    = new ExcelMechanisms();
        Vector <double> xarr   = new Vector <double>(T, 1);
        List <string>   labels = new List <string>();
        foreach (double myD in strike)
        {
            labels.Add(myD.ToString());
        }
        ;
        List <Vector <double> > yarrs = new List <Vector <double> >();
        foreach (double[] arr in B.CapletVolMatrix)
        {
            yarrs.Add(new Vector <double>(arr, 1));
        }

        exl.printInExcel <double>(xarr, labels, yarrs, "Caplet Vol Input Interpolation", "Term", "Volatility");
        #endregion
    }
Beispiel #2
0
    public static void MatrixCapletWithRateCurve()
    {
        #region Inputs
        // We load a set of data (not real)
        DataForCapletExample2 d = new DataForCapletExample2();
        RateSet         rs      = d.GetRateSet();
        double[]        T       = d.T();
        string[]        avT     = d.avTString();
        List <double[]> VolArr  = d.VolArr();
        double[]        strike  = d.strike();

        // We build our multi curve
        SingleCurveBuilderStandard <OnLogDf, SimpleCubicInterpolator> Curve = new SingleCurveBuilderStandard <OnLogDf, SimpleCubicInterpolator>(rs, OneDimensionInterpolation.LogLinear); // discount curve

        #endregion

        #region Testing all available MonoStrikeCapletVolBuilder
        // Uncomment one of these
        CapletMatrixVolBuilder <MonoStrikeCapletVolBuilderInputInterpLinear> B =
            new CapletMatrixVolBuilder <MonoStrikeCapletVolBuilderInputInterpLinear>(avT, Curve, strike, VolArr);

        // CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderInputInterpCubic> B =
        //    new CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderInputInterpCubic>(avT, Curve, strike, VolArr);

        // CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderBestFitStd> B =
        //    new CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderBestFitStd>(avT, Curve, strike, VolArr);

        // CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderBestFitSmooth> B =
        //    new CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderBestFitSmooth>(avT, Curve, strike, VolArr);

        // CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderBestFitPWL> B =
        //    new CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderBestFitPWL>(avT, Curve, strike, VolArr);

        // CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderBestFitCubic> B =
        //    new CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderBestFitCubic>(avT, Curve, strike, VolArr);

        // CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderBestFitFunct> B =
        //    new CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderBestFitFunct>(avT, Curve, strike, VolArr);

        // CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderPWC> B =
        //    new CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderPWC>(avT, Curve, strike, VolArr);

        #endregion

        List <double[]> VolSilos = B.CapletVolMatrix;

        #region print results
        ExcelMechanisms exl    = new ExcelMechanisms();
        Vector <double> xarr   = new Vector <double>(T, 1);
        List <string>   labels = new List <string>();
        foreach (double myD in strike)
        {
            labels.Add(myD.ToString());
        }
        ;
        List <Vector <double> > yarrs = new List <Vector <double> >();
        foreach (double[] arr in VolSilos)
        {
            yarrs.Add(new Vector <double>(arr, 1));
        }

        exl.printInExcel <double>(xarr, labels, yarrs, "Caplet Vol Input Interpolation", "Term", "Volatility");
        #endregion
    }