Beispiel #1
0
        private YieldTermStructure Forwardcurve(List <Date> dates, List <double> forwards, DayCounter dayCounter)
        {
            YieldTermStructure yieldts;

            switch (_interpolationMethod)
            {
            case InterpolationMethod.Linear:
                yieldts = new InterpolatedForwardCurve <Linear>(dates, forwards, dayCounter, new Linear());
                break;

            case InterpolationMethod.LogLinear:
                yieldts =
                    new InterpolatedForwardCurve <LogLinear>(dates, forwards, dayCounter, new LogLinear());
                break;

            case InterpolationMethod.NaturalCubic:
                yieldts = new InterpolatedForwardCurve <Cubic>(dates, forwards, dayCounter,
                                                               new Cubic(CubicInterpolation.DerivativeApprox.Kruger, true, CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0, CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0));
                break;

            case InterpolationMethod.FinancialCubic:
                yieldts = new InterpolatedForwardCurve <Cubic>(
                    dates, forwards, dayCounter,
                    new Cubic(CubicInterpolation.DerivativeApprox.Kruger, true, CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0, CubicInterpolation.BoundaryCondition.FirstDerivative, 0.0));
                break;

            case InterpolationMethod.ConvexMonotone:
                yieldts = new InterpolatedForwardCurve <ConvexMonotone>(dates, forwards, dayCounter);
                break;

            default:
                Utils.QL_FAIL("Interpolation method not recognised.");
                throw new Exception();
            }
            return(yieldts);
        }
Beispiel #2
0
        public void testCompositeZeroYieldStructures()
        {
            // Testing composite zero yield structures...

            Settings.setEvaluationDate(new Date(10, Month.Nov, 2017));

            // First curve
            var dates = new List <Date>
            {
                new Date(10, Month.Nov, 2017),
                new Date(13, Month.Nov, 2017),
                new Date(12, Month.Feb, 2018),
                new Date(10, Month.May, 2018),
                new Date(10, Month.Aug, 2018),
                new Date(12, Month.Nov, 2018),
                new Date(21, Month.Dec, 2018),
                new Date(15, Month.Jan, 2020),
                new Date(31, Month.Mar, 2021),
                new Date(28, Month.Feb, 2023),
                new Date(21, Month.Dec, 2026),
                new Date(31, Month.Jan, 2030),
                new Date(28, Month.Feb, 2031),
                new Date(31, Month.Mar, 2036),
                new Date(28, Month.Feb, 2041),
                new Date(28, Month.Feb, 2048),
                new Date(31, Month.Dec, 2141)
            };

            var rates = new List <double>
            {
                0.0655823213132524,
                0.0655823213132524,
                0.0699455024156877,
                0.0799107139233497,
                0.0813931951022577,
                0.0841615820666691,
                0.0501297919004145,
                0.0823483583439658,
                0.0860720030924466,
                0.0922887604375688,
                0.10588902278996,
                0.117021968693922,
                0.109824660896137,
                0.109231572878364,
                0.119218123236241,
                0.128647300167664,
                0.0506086995288751
            };

            var termStructure1 = new InterpolatedForwardCurve <BackwardFlat>(dates, rates, new Actual365Fixed(), new NullCalendar());

            // Second curve
            dates = new List <Date>();
            rates = new List <double>();

            dates.Add(new Date(10, Month.Nov, 2017));
            dates.Add(new Date(13, Month.Nov, 2017));
            dates.Add(new Date(11, Month.Dec, 2017));
            dates.Add(new Date(12, Month.Feb, 2018));
            dates.Add(new Date(10, Month.May, 2018));
            dates.Add(new Date(31, Month.Jan, 2022));
            dates.Add(new Date(7, Month.Dec, 2023));
            dates.Add(new Date(31, Month.Jan, 2025));
            dates.Add(new Date(31, Month.Mar, 2028));
            dates.Add(new Date(7, Month.Dec, 2033));
            dates.Add(new Date(1, Month.Feb, 2038));
            dates.Add(new Date(2, Month.Apr, 2046));
            dates.Add(new Date(2, Month.Jan, 2051));
            dates.Add(new Date(31, Month.Dec, 2141));

            rates.Add(0.056656806197189);
            rates.Add(0.056656806197189);
            rates.Add(0.0419541633454473);
            rates.Add(0.0286681050019797);
            rates.Add(0.0148840226959593);
            rates.Add(0.0246680238374363);
            rates.Add(0.0255349067810599);
            rates.Add(0.0298907184711927);
            rates.Add(0.0263943927922053);
            rates.Add(0.0291924526539802);
            rates.Add(0.0270049276163556);
            rates.Add(0.028775807327614);
            rates.Add(0.0293567711641792);
            rates.Add(0.010518655099659);

            var termStructure2 = new InterpolatedForwardCurve <BackwardFlat>(dates, rates, new Actual365Fixed(), new NullCalendar());

            var compoundCurve = new CompositeZeroYieldStructure
                                (
                new Handle <YieldTermStructure>(termStructure1),
                new Handle <YieldTermStructure>(termStructure2),
                sub
                                );

            // Expected values
            dates = new List <Date>();
            rates = new List <double>();

            dates.Add(new Date(10, Month.Nov, 2017));
            dates.Add(new Date(15, Month.Dec, 2017));
            dates.Add(new Date(15, Month.Jun, 2018));
            dates.Add(new Date(15, Month.Sep, 2029));
            dates.Add(new Date(15, Month.Sep, 2038));
            dates.Add(new Date(15, Month.Mar, 2046));
            dates.Add(new Date(15, Month.Dec, 2141));

            rates.Add(0.00892551511527986);
            rates.Add(0.0278755322562788);
            rates.Add(0.0512001768603456);
            rates.Add(0.0729941474263546);
            rates.Add(0.0778333309498459);
            rates.Add(0.0828451659139004);
            rates.Add(0.0503573807521742);

            double tolerance = 1.0e-10;

            for (var i = 0; i < dates.Count; ++i)
            {
                double actual   = compoundCurve.zeroRate(dates[i], new Actual365Fixed(), Compounding.Continuous).rate();
                double expected = rates[i];

                QAssert.IsTrue(Math.Abs(actual - expected) <= tolerance,
                               "unable to reproduce zero yield rate from composite input curve\n"
                               + "    calculated: " + actual + "\n"
                               + "    expected:   " + expected);
            }
        }