예제 #1
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));
    }
예제 #2
0
    public static double Swaption(double N, double K, string Start, string SwapTenor, bool isPayer, BilinearInterpolator VolMatrix, 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,...)
        double sigma     = VolMatrix.Solve(T, p.tenor);

        return(Swaption(N, K, Start, SwapTenor, isPayer, sigma, Curve));
    }
예제 #3
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]);
        }
    }
예제 #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));
    }
예제 #5
0
    // 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);
    }