// constructor
    public CapletMatrixVolBuilder(string[] Tenor, IRateCurve Curve, double[] strike, List <double[]> VolSilos)
    {
        #region preparing data

        // yf of longer cap
        SwapStyle y        = (SwapStyle) new BuildingBlockFactory().CreateBuildingBlock(Curve.RefDate(), 0, Tenor.Last(), Curve.GetSwapStyle().buildingBlockType);
        double[]  yf       = y.scheduleLeg2.GetYFVect(Dc._Act_360);
        int       toRemove = yf.Length - 1;
        yf = yf.Where((val, inx) => inx != toRemove).ToArray();

        // T all tenor needed. They are more than input
        Date        refDate = Curve.RefDate();
        List <Date> ToDate  = y.scheduleLeg2.toDates.ToList();
        ToDate.RemoveAt(ToDate.Count - 1);    // remove last element
        double[] T = (from c in ToDate
                      select refDate.YF_365(c)).ToArray();

        // available T from input
        double[] Tquoted = new double[Tenor.Length];
        for (int i = 0; i < Tquoted.Length; i++)
        {        // calculate yf of each available T as it was a swap
            SwapStyle myS    = (SwapStyle) new BuildingBlockFactory().CreateBuildingBlock(Curve.RefDate(), 0, Tenor[i], Curve.GetSwapStyle().buildingBlockType);
            int       L      = myS.scheduleLeg2.toDates.Count() - 1;
            Date[]    toDate = myS.scheduleLeg2.toDates;
            Tquoted[i] = refDate.YF_365(toDate[L - 1]);
        }

        // df- getting relevant dates
        Date[]   dfDate  = y.scheduleLeg2.payDates;
        int      Ncaplet = yf.Length; // number of caplets
        double[] df      = new double[Ncaplet];
        // fwd rate
        double[] fwd     = new double[Ncaplet];
        Date[]   fwdDate = y.scheduleLeg2.fromDates;

        for (int i = 0; i < Ncaplet; i++) // Note the loop start from 1
        {                                 // first discount factor is on first payment date of caplet (first caplet skipped)
            df[i]  = Curve.Df(dfDate[i + 1]);
            fwd[i] = Curve.Fwd(fwdDate[i + 1]);
        }

        #endregion

        Ini(T, df, fwd, yf, Tquoted, VolSilos, strike);
    }
Esempio n. 2
0
    public static double FwdBasis(Date StartDate, string SwapTenor, IRateCurve Curve1, IRateCurve Curve2)
    {
        SwapStyle S1 = (SwapStyle) new BuildingBlockFactory().CreateBuildingBlock(StartDate, 0.0, SwapTenor, Curve1.GetSwapStyle().buildingBlockType);
        SwapStyle S2 = (SwapStyle) new BuildingBlockFactory().CreateBuildingBlock(StartDate, 0.0, SwapTenor, Curve2.GetSwapStyle().buildingBlockType);

        double[] yfFloatLeg1 = S1.scheduleLeg2.GetYFVect(S1.swapLeg2.DayCount);

        // using LINQ syntax
        double[] dfFloatLeg1 = (from d in S1.scheduleLeg2.payDates
                                select Curve1.Df(d)).ToArray <double>();
        double[] fwdFloatLeg1 = (from d in S1.scheduleLeg2.fromDates
                                 select Curve1.Fwd(d)).ToArray <double>();

        double[] yfFloatLeg2 = S2.scheduleLeg2.GetYFVect(S2.swapLeg2.DayCount);
        // using LINQ syntax
        double[] dfFloatLeg2 = (from d in S2.scheduleLeg2.payDates
                                select Curve2.Df(d)).ToArray <double>();

        double[] fwdFloatLeg2 = (from d in S2.scheduleLeg2.fromDates
                                 select Curve2.Fwd(d)).ToArray <double>();

        return(SpreadBasisFormula(yfFloatLeg1, dfFloatLeg1, fwdFloatLeg1,
                                  yfFloatLeg2, dfFloatLeg2, fwdFloatLeg2));
    }
Esempio n. 3
0
    public static double CapBlack(string Tenor, double strike, double N, IRateCurve curve, BilinearInterpolator VolCapletMatrix)
    {
        Date      refDate = curve.RefDate();
        SwapStyle y       = (SwapStyle) new BuildingBlockFactory().CreateBuildingBlock(refDate, 0, Tenor, curve.GetSwapStyle().buildingBlockType);

        double[] yf       = y.scheduleLeg2.GetYFVect(Dc._Act_360);
        int      toRemove = yf.Length - 1;

        yf = yf.Where((val, inx) => inx != toRemove).ToArray();

        List <Date> ToDate = y.scheduleLeg2.toDates.ToList();

        ToDate.RemoveAt(ToDate.Count - 1);      // remove last element
        double[] T = (from c in ToDate
                      select refDate.YF_365(c)).ToArray();

        // df- getting relevant dates
        Date[] dfDate  = y.scheduleLeg2.payDates;
        int    Ncaplet = yf.Length;   // number of caplets

        double[] df = new double[Ncaplet];
        // fwd rate
        double[] fwd     = new double[Ncaplet];
        Date[]   fwdDate = y.scheduleLeg2.fromDates;

        for (int i = 0; i < Ncaplet; i++) // Note the loop start from 1
        {                                 // first discount factor is on first payment date of caplet (first caplet skipped)
            df[i]  = curve.Df(dfDate[i + 1]);
            fwd[i] = curve.Fwd(fwdDate[i + 1]);
        }

        double[] sigma = (from t in T
                          select VolCapletMatrix.Solve(t, strike)).ToArray();
        return(CapBlack(T, yf, N, strike, sigma, df, fwd));
    }
Esempio n. 4
0
    public static double Swaption(double N, double K, string Start, string SwapTenor, bool isPayer, double sigma, IRateCurve Curve)
    {
        Date refDate = Curve.RefDate();                         // curve ref date
        // false/true with fwd swap matrix
        Date      startDate = refDate.add_period(Start, false); // swap start 2 business days after the expiry
        Date      expDate   = startDate.add_workdays(-2);       // expiry of swaption
        Date      today     = refDate.add_workdays(-2);
        double    T         = today.YF_365(expDate);
        Period    p         = new Period(SwapTenor); // should be in year 1Y, 2Y (not 3m,...)
        SwapStyle y         = (SwapStyle) new BuildingBlockFactory().CreateBuildingBlock(startDate, 0, SwapTenor, Curve.GetSwapStyle().buildingBlockType);

        double[] yf = y.scheduleLeg1.GetYFVect(Dc._30_360);
        double[] df = (from payDay in y.scheduleLeg1.payDates
                       select Curve.Df(payDay)).ToArray();

        return(Swaption(N, Curve.SwapFwd(startDate, SwapTenor), K, sigma, T, isPayer, yf, df));
    }
Esempio n. 5
0
    // used in constructor
    private void Ini(string tenor, IRateCurve curve, BilinearInterpolator capletVolMatrix, double nominal)
    {
        stringTenor = tenor;
        rateCurve   = curve;
        volMatrix   = capletVolMatrix;
        N           = nominal;

        // yf of longer cap
        SwapStyle y = (SwapStyle) new BuildingBlockFactory().CreateBuildingBlock(curve.RefDate(), 0, tenor, curve.GetSwapStyle().buildingBlockType);

        yf          = y.scheduleLeg2.GetYFVect(Dc._Act_360);
        capSchedule = y.scheduleLeg2;
        int toRemove = yf.Length - 1;

        yf = yf.Where((val, inx) => inx != toRemove).ToArray();

        // T all tenor needed. They are more than input
        Date        refDate = curve.RefDate();
        List <Date> ToDate  = y.scheduleLeg2.toDates.ToList();

        ToDate.RemoveAt(ToDate.Count - 1);  // remove last element
        T = (from c in ToDate
             select refDate.YF_365(c)).ToArray();
        // df- getting relevant dates
        Date[] dfDate  = y.scheduleLeg2.payDates;
        int    Ncaplet = yf.Length; // number of caplets

        df = new double[Ncaplet];
        // fwd rate
        fwd = new double[Ncaplet];
        Date[] fwdDate = y.scheduleLeg2.fromDates;

        for (int i = 0; i < Ncaplet; i++) // Note the loop start from 1
        {                                 // first discount factor is on first payment date of caplet (first caplet skipped)
            df[i]  = curve.Df(dfDate[i + 1]);
            fwd[i] = curve.Fwd(fwdDate[i + 1]);
        }
    }