public void TestCurveStripSingleCurve()
        {
            Date     valueDate = new Date(2017, 1, 13);
            Currency zar       = Currency.ZAR;
            double   N         = 1.0;
            double   r1        = 0.07;
            double   r2        = 0.075;
            Date     date1     = valueDate.AddMonths(3);
            Date     date2     = valueDate.AddMonths(6);

            ZeroRatesCurveForStripping zarDiscUSDColl = new ZeroRatesCurveForStripping(valueDate, zar);
            ZeroRatesCurveForStripping zarDisc        = new ZeroRatesCurveForStripping(valueDate, zar);

            Product depo1 = new CashLeg(new Date[] { valueDate, date1 }, new double[] { -N, N * (1 + r1 * 0.25) }, new Currency[] { zar, zar });
            Product depo2 = new CashLeg(new Date[] { valueDate, date2 }, new double[] { -N, N * (1 + r2 * 0.5) }, new Currency[] { zar, zar });

            DeterminsiticCurves modelZARDisc = new DeterminsiticCurves(zarDisc);
            Coordinator         coordZARDisc = new Coordinator(modelZARDisc, new List <Simulator>(), 1);

            coordZARDisc.SetThreadedness(false);

            MultiCurveStripper mcs = new MultiCurveStripper(valueDate);

            mcs.AddDiscounting(depo1, () => coordZARDisc.Value(depo1, valueDate), N, 1.0, zarDisc);
            mcs.AddDiscounting(depo2, () => coordZARDisc.Value(depo2, valueDate), N, 1.0, zarDisc);
            mcs.Strip();

            Assert.AreEqual(N, coordZARDisc.Value(depo1, valueDate), 1e-6);
            Assert.AreEqual(N, coordZARDisc.Value(depo2, valueDate), 1e-6);
        }
Ejemplo n.º 2
0
        public void TestCurveStripTwoZARDiscount()
        {
            var valueDate = new Date(2017, 1, 13);
            var zar       = Currency.ZAR;

            // Empty curves
            var zarDiscUSDColl = new ZeroRatesCurveForStripping(valueDate, zar);
            var zarDisc        = new ZeroRatesCurveForStripping(valueDate, zar);
            var jibarCurve     = new ForwardRatesCurveForStripping(valueDate, FloatingIndex.JIBAR3M);

            // Models
            var modelZARDiscUSDColl = new DeterminsiticCurves(zarDiscUSDColl);

            modelZARDiscUSDColl.AddRateForecast(jibarCurve);
            var coordZARDiscUSDColl = new Coordinator(modelZARDiscUSDColl, new List <Simulator>(), 1);

            coordZARDiscUSDColl.SetThreadedness(false);
            var modelZARDisc = new DeterminsiticCurves(zarDisc);

            modelZARDisc.AddRateForecast(jibarCurve); // same jibar curve in both coordinators.
            var coordZARDisc = new Coordinator(modelZARDisc, new List <Simulator>(), 1);

            coordZARDisc.SetThreadedness(false);

            //Instruments for USDColl discounting curve.
            var mcs   = new MultiCurveStripper(valueDate);
            var depo1 = MakeDepo(valueDate, 0.07, 24);
            var depo2 = MakeDepo(valueDate, 0.072, 48);

            mcs.AddDiscounting(depo1, () => coordZARDiscUSDColl.Value(depo1, valueDate), 1.0, 1.0, zarDiscUSDColl);
            mcs.AddDiscounting(depo2, () => coordZARDiscUSDColl.Value(depo2, valueDate), 1.0, 1.0, zarDiscUSDColl);

            Product swapUSDColl1 = IRSwap.CreateZARSwap(0.07, true, 1.0, valueDate, Tenor.Months(24));
            Product swapUSDColl2 = IRSwap.CreateZARSwap(0.072, true, 1.0, valueDate, Tenor.Months(48));

            mcs.AddForecast(swapUSDColl1, () => coordZARDiscUSDColl.Value(swapUSDColl1, valueDate), 0, 1, jibarCurve,
                            FloatingIndex.JIBAR3M);
            mcs.AddForecast(swapUSDColl2, () => coordZARDiscUSDColl.Value(swapUSDColl2, valueDate), 0, 1, jibarCurve,
                            FloatingIndex.JIBAR3M);

            Product swapNoColl1 = IRSwap.CreateZARSwap(0.0709, true, 1.0, valueDate, Tenor.Months(36));
            Product swapNoColl2 = IRSwap.CreateZARSwap(0.0719, true, 1.0, valueDate, Tenor.Months(48));

            mcs.AddDiscounting(swapNoColl1, () => coordZARDisc.Value(swapNoColl1, valueDate), 0, 1, zarDisc);
            mcs.AddDiscounting(swapNoColl2, () => coordZARDisc.Value(swapNoColl2, valueDate), 0, 1, zarDisc);

            mcs.Strip();

            Assert.AreEqual(1.0, coordZARDiscUSDColl.Value(depo1, valueDate), 1e-6);
            Assert.AreEqual(1.0, coordZARDiscUSDColl.Value(depo2, valueDate), 1e-6);
            Assert.AreEqual(0.0, coordZARDiscUSDColl.Value(swapUSDColl2, valueDate), 1e-6);
            Assert.AreEqual(0.0, coordZARDiscUSDColl.Value(swapUSDColl2, valueDate), 1e-6);
            //Assert.AreNotEqual(0.0, coordZARDisc.Value(swapUSDColl1, valueDate), 1e-6); No discount sensitivity
            Assert.AreNotEqual(0.0, coordZARDisc.Value(swapUSDColl2, valueDate), 1e-6);
            Assert.AreEqual(0.0, coordZARDisc.Value(swapNoColl1, valueDate), 1e-6);
            Assert.AreEqual(0.0, coordZARDisc.Value(swapNoColl2, valueDate), 1e-6);
        }
Ejemplo n.º 3
0
        public void TestCurveStripSeparateForecastAndDiscount()
        {
            var valueDate = new Date(2017, 1, 13);
            var zar       = Currency.ZAR;
            var N         = 1.0;
            var r1        = 0.12;
            var r2        = 0.08;
            var date1     = valueDate.AddMonths(6);
            var date2     = valueDate.AddMonths(12);

            var zarDisc         = new ZeroRatesCurveForStripping(valueDate, zar);
            var jibar3mForecast = new ForwardRatesCurveForStripping(valueDate, FloatingIndex.JIBAR3M, zarDisc);

            Product depo1 = new CashLeg(new[] { valueDate, date1 }, new[] { -N, N * (1 + r1 * 0.5) }, new[] { zar, zar });
            Product depo2 = new CashLeg(new[] { valueDate, date2 }, new[] { -N, N * (1 + r2 * 1) }, new[] { zar, zar });
            Product swap  = IRSwap.CreateZARSwap(0.08, true, 1.0, valueDate, Tenor.Months(9));

            var modelZARDisc = new DeterminsiticCurves(zarDisc);

            modelZARDisc.AddRateForecast(jibar3mForecast);
            var coordZARDisc = new Coordinator(modelZARDisc, new List <Simulator>(), 1);

            coordZARDisc.SetThreadedness(false);

            var mcs = new MultiCurveStripper(valueDate);

            mcs.AddDiscounting(depo1, () => coordZARDisc.Value(depo1, valueDate), N, 1.0, zarDisc);
            mcs.AddDiscounting(depo2, () => coordZARDisc.Value(depo2, valueDate), N, 1.0, zarDisc);
            mcs.AddForecast(swap, () => coordZARDisc.Value(swap, valueDate), 0.0, 1.0, jibar3mForecast,
                            FloatingIndex.JIBAR3M);
            mcs.Strip();

            Assert.AreEqual(N, coordZARDisc.Value(depo1, valueDate), 1e-6);
            Assert.AreEqual(N, coordZARDisc.Value(depo2, valueDate), 1e-6);
            Assert.AreEqual(0, coordZARDisc.Value(swap, valueDate), 1e-6);

            /*double[] fwdRates = new double[180];
             * for (int i=0; i<180; i++ )
             * {
             *  fwdRates[i] = jibar3mForecast.GetForwardRate(valueDate.AddTenor(Tenor.Days(i)));
             * }
             * Debug.WriteToFile("c:\\dev\\quantsa\\temp\\fwdRates.csv", fwdRates);
             */
        }
        public void TestCurveStripWithUnderlying()
        {
            Date                       valueDate      = new Date(2017, 1, 13);
            Currency                   zar            = Currency.ZAR;
            double                     N              = 1.0;
            double                     r1             = 0.07;
            double                     r2             = 0.075;
            Date                       date1          = valueDate.AddMonths(3);
            Date                       date2          = valueDate.AddMonths(6);
            double                     turnSize       = 0.05;
            IDiscountingSource         turnShapeCurve = new DFCurveWithTurn(valueDate, zar, new Date(2017, 2, 20), turnSize);
            ZeroRatesCurveForStripping zarDisc        = new ZeroRatesCurveForStripping(valueDate, turnShapeCurve);

            Product depo1 = new CashLeg(new Date[] { valueDate, date1 }, new double[] { -N, N * (1 + r1 * 0.25) }, new Currency[] { zar, zar });
            Product depo2 = new CashLeg(new Date[] { valueDate, date2 }, new double[] { -N, N * (1 + r2 * 0.5) }, new Currency[] { zar, zar });

            DeterminsiticCurves modelZARDisc = new DeterminsiticCurves(zarDisc);
            Coordinator         coordZARDisc = new Coordinator(modelZARDisc, new List <Simulator>(), 1);

            coordZARDisc.SetThreadedness(false);

            MultiCurveStripper mcs = new MultiCurveStripper(valueDate);

            mcs.AddDiscounting(depo1, () => coordZARDisc.Value(depo1, valueDate), N, 1.0, zarDisc);
            mcs.AddDiscounting(depo2, () => coordZARDisc.Value(depo2, valueDate), N, 1.0, zarDisc);
            mcs.Strip();

            Assert.AreEqual(N, coordZARDisc.Value(depo1, valueDate), 1e-6);
            Assert.AreEqual(N, coordZARDisc.Value(depo2, valueDate), 1e-6);
            double df1   = zarDisc.GetDF(new Date(2017, 2, 19));
            double df2   = zarDisc.GetDF(new Date(2017, 2, 20));
            double df3   = zarDisc.GetDF(new Date(2017, 2, 21));
            double df4   = zarDisc.GetDF(new Date(2017, 2, 22));
            double rate1 = 365.0 * (df1 / df2 - 1);
            double rate2 = 365.0 * (df2 / df3 - 1);
            double rate3 = 365.0 * (df3 / df4 - 1);

            Assert.AreEqual(turnSize, rate2 - rate1, turnSize / 100);
            Assert.AreEqual(turnSize, rate2 - rate3, turnSize / 100);
        }