Ejemplo n.º 1
0
        public void Init()
        {
            // Set up the model
            valueDate = new Date(2016, 9, 17);
            var a             = 0.05;
            var vol           = 0.01;
            var flatCurveRate = 0.07;

            hullWiteSim = new HullWhite1F(Currency.ZAR, a, vol, flatCurveRate, flatCurveRate, valueDate);
            hullWiteSim.AddForecast(FloatingIndex.JIBAR3M);

            // Make the underlying swap
            var    rate      = 0.07;
            var    payFixed  = true;
            double notional  = 1000000;
            var    startDate = new Date(2016, 9, 17);
            var    tenor     = Tenor.Years(5);

            swapPay = IRSwap.CreateZARSwap(rate, payFixed, notional, startDate, tenor);
            swapRec = IRSwap.CreateZARSwap(rate, !payFixed, notional, startDate, tenor);

            // Full set of exercise dates
            exDates = new List <Date>
            {
                new Date(2017, 9, 17),
                new Date(2018, 9, 17),
                new Date(2019, 9, 17),
                new Date(2020, 9, 17)
            };
        }
Ejemplo n.º 2
0
        public void TestCoordinatorAllData()
        {
            // Make the swap
            var    rate      = 0.07;
            var    payFixed  = true;
            double notional  = 1000000;
            var    startDate = new Date(2016, 9, 17);
            var    tenor     = Tenor.Years(5);
            var    swap      = IRSwap.CreateZARSwap(rate, payFixed, notional, startDate, tenor);

            // Set up the model
            var valueDate     = new Date(2016, 9, 17);
            var a             = 0.05;
            var vol           = 0.01;
            var flatCurveRate = 0.07;
            var hullWiteSim   = new HullWhite1F(Currency.ZAR, a, vol, flatCurveRate, flatCurveRate, valueDate);

            hullWiteSim.AddForecast(FloatingIndex.JIBAR3M);
            var coordinator = new Coordinator(hullWiteSim, new List <Simulator>(), 5000);

            var date          = valueDate;
            var endDate       = valueDate.AddTenor(tenor);
            var fwdValueDates = new List <Date>();

            while (date < endDate)
            {
                fwdValueDates.Add(date);
                date = date.AddTenor(Tenor.Days(10));
            }

            var allDetails = coordinator.GetValuePaths(new Product[] { swap }, valueDate, fwdValueDates.ToArray());

            allDetails.GetNames();
        }
Ejemplo n.º 3
0
        public void TestSwapHW()
        {
            // Make the swap
            var    rate      = 0.08;
            var    payFixed  = true;
            double notional  = 1000000;
            var    startDate = new Date(2016, 9, 17);
            var    tenor     = Tenor.Years(5);
            var    swap      = IRSwap.CreateZARSwap(rate, payFixed, notional, startDate, tenor);

            // Set up the model
            var valueDate     = new Date(2016, 9, 17);
            var a             = 0.05;
            var vol           = 0.01;
            var flatCurveRate = 0.07;
            var hullWiteSim   = new HullWhite1F(Currency.ZAR, a, vol, flatCurveRate, flatCurveRate, valueDate);

            hullWiteSim.AddForecast(FloatingIndex.JIBAR3M);
            var coordinator = new Coordinator(hullWiteSim, new List <Simulator>(), 10000);

            // Run the valuation
            var value    = coordinator.Value(new Product[] { swap }, valueDate);
            var refValue = -41838.32; // See RateProductTest.xlsx

            Assert.AreEqual(refValue, value, 4000);
        }
Ejemplo n.º 4
0
        private Product[] GetListOfSwaps()
        {
            int    N          = 50000;
            Date   anchorDate = new Date(2016, 11, 21);
            double rate       = 0.08;
            bool   payFixed   = true;
            double notional   = 1000000;

            double[,] swapDist = new double[, ] {
                { 0.171 }, { 0.148 }, { 0.101 }, { 0.094 }, { 0.108 }, { 0.056 }, { 0.041 }, { 0.049 }, { 0.047 }, { 0.056 }, { 0.013 }, { 0.013 }, { 0.010 }, { 0.011 }, { 0.011 }, { 0.004 }, { 0.003 }, { 0.005 }, { 0.007 }, { 0.006 }, { 0.004 }, { 0.004 }, { 0.007 }, { 0.005 }, { 0.006 }, { 0.006 }, { 0.003 }, { 0.003 }, { 0.002 }, { 0.005 }
            };
            IRandomNumberGenerator <double> generator1   = new ZigguratUniformGenerator(0, 1);
            IRandomNumberGenerator <double> generator365 = new ZigguratUniformGenerator(1, 365);

            double[,] cumSum = swapDist.CumulativeSum(1);

            Product[] allSwaps = new Product[N];
            for (int swapNum = 0; swapNum < N; swapNum++)
            {
                double x     = generator1.Generate();
                int    years = 0;
                while (years < cumSum.GetLength(0) && x > cumSum[years, 0])
                {
                    years++;
                }
                int  days      = (int)Math.Round(generator365.Generate());
                Date endDate   = anchorDate.AddTenor(new Tenor(days, 0, 0, years));
                Date startDate = endDate.AddTenor(Tenor.Years(-years - 1));
                allSwaps[swapNum] = IRSwap.CreateZARSwap(rate, payFixed, notional, startDate, Tenor.Years(years + 1));
            }

            return(allSwaps);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Constructor for ZAR market standard, fixed for float 3m Jibar swap.
        /// </summary>
        /// <param name="rate">The fixed rate paid or received</param>
        /// <param name="payFixed">Is the fixed rate paid?</param>
        /// <param name="notional">Flat notional for all dates.</param>
        /// <param name="startDate">First reset date of swap</param>
        /// <param name="tenor">Tenor of swap, must be a whole number of years.</param>
        /// <param name="floatRateIndex"></param>
        /// <returns></returns>
        public static IRSwap CreateZARSwap(double rate, bool payFixed, double notional, Date startDate, Tenor tenor,
                                           FloatRateIndex floatRateIndex)
        {
            var quarters         = tenor.Years * 4 + tenor.Months / 3;
            var indexDates       = new Date[quarters];
            var paymentDates     = new Date[quarters];
            var spreads          = new double[quarters];
            var accrualFractions = new double[quarters];
            var notionals        = new double[quarters];
            var fixedRate        = rate;

            var date1 = new Date(startDate);

            for (var i = 0; i < quarters; i++)
            {
                var date2 = startDate.AddMonths(3 * (i + 1));
                indexDates[i]       = new Date(date1);
                paymentDates[i]     = new Date(date2);
                spreads[i]          = 0.0;
                accrualFractions[i] = (date2 - date1) / 365.0;
                notionals[i]        = notional;
                date1 = new Date(date2);
            }

            var newSwap = new IRSwap(payFixed ? -1 : 1, indexDates, paymentDates, floatRateIndex, spreads,
                                     accrualFractions,
                                     notionals, fixedRate, floatRateIndex.Currency);

            return(newSwap);
        }
Ejemplo n.º 6
0
        public static double ValueSwap(IRSwap swap, Date valueDate, IDiscountingSource curve)
        {
            // Get the required objects off the map
            var index = swap.GetFloatingIndex();

            // Calculate the first fixing off the curve to use at all past dates.
            var df1       = curve.GetDF(valueDate);
            var laterDate = valueDate.AddTenor(index.Tenor);
            var df2       = curve.GetDF(laterDate);
            var dt        = (laterDate - valueDate) / 365.0;
            var rate      = (df1 / df2 - 1) / dt;

            //Set up the valuation engine.
            IFloatingRateSource forecastCurve = new ForecastCurveFromDiscount(curve, index,
                                                                              new FloatingRateFixingCurve1Rate(valueDate, rate, index));
            var curveSim = new DeterministicCurves(curve);

            curveSim.AddRateForecast(forecastCurve);
            var coordinator = new Coordinator(curveSim, new List <Simulator>(), 1);

            // Run the valuation
            var value = coordinator.Value(new Product[] { swap }, valueDate);

            return(value);
        }
Ejemplo n.º 7
0
        public static double[] SwapZeroRisk(IRSwap swap, Date valueDate, Date[] dates, double[] rates, Currency currency)
        {
            // set the base curve
            for (var i = 1; i < dates.Length; i++)
            {
                if (dates[i].value <= dates[i - 1].value)
                {
                    throw new ArgumentException("Dates must be strictly increasing");
                }
            }
            var basecurve = new DatesAndRates(currency, dates[0], dates, rates);

            // Calculate the base value of the swap
            var basevalue = ValueSwap(swap, valueDate, basecurve);

            double shift = 0.0001;
            var    temp  = new double[dates.Length];
            var    PV01s = new double[dates.Length];

            for (int i = 0; i < dates.Length; i++)
            {
                rates.CopyTo(temp, 0);
                temp[i] += shift;

                PV01s[i] = ValueSwap(swap, valueDate, new DatesAndRates(currency, dates[0], dates, temp)) - basevalue;
            }

            return(PV01s);
        }
Ejemplo n.º 8
0
        public static double ValueZARSwap1Curve([ExcelArgument(Description = "The name of the swap.")] IRSwap swap,
                                                [ExcelArgument(Description = "The date on which valuation is required.  Cannot be before the anchor date of the curve.")] Date valueDate,
                                                [ExcelArgument(Description = "The discounting curve.  Will also be used for forecasting Jibar and providing the most recent required Jibar fix.")] IDiscountingSource curve)
        {
            // Get the required objects off the map
            FloatingIndex index = swap.GetFloatingIndex();

            // Calculate the first fixing off the curve to use at all past dates.
            double df1       = curve.GetDF(valueDate);
            Date   laterDate = valueDate.AddTenor(index.tenor);
            double df2       = curve.GetDF(laterDate);
            double dt        = (laterDate - valueDate) / 365.0;
            double rate      = (df1 / df2 - 1) / dt;

            //Set up the valuation engine.
            IFloatingRateSource forecastCurve = new ForecastCurveFromDiscount(curve, index,
                                                                              new FloatingRateFixingCurve1Rate(rate, index));
            DeterminsiticCurves curveSim = new DeterminsiticCurves(curve);

            curveSim.AddRateForecast(forecastCurve);
            Coordinator coordinator = new Coordinator(curveSim, new List <Simulator>(), 1);

            // Run the valuation
            double value = coordinator.Value(new Product[] { swap }, valueDate);

            return(value);
        }
Ejemplo n.º 9
0
        public void TestSwap()
        {
            // Make the swap
            var    rate      = 0.08;
            var    payFixed  = true;
            double notional  = 1000000;
            var    startDate = new Date(2016, 9, 17);
            var    tenor     = Tenor.Years(5);
            var    swap      = IRSwap.CreateZARSwap(rate, payFixed, notional, startDate, tenor);

            // Set up the model
            var valueDate = new Date(2016, 9, 17);

            Date[]              dates         = { new Date(2016, 9, 17), new Date(2026, 9, 17) };
            double[]            rates         = { 0.07, 0.07 };
            IDiscountingSource  discountCurve = new DatesAndRates(Currency.ZAR, valueDate, dates, rates);
            IFloatingRateSource forecastCurve = new ForecastCurve(valueDate, FloatingIndex.JIBAR3M, dates, rates);
            var curveSim = new DeterminsiticCurves(discountCurve);

            curveSim.AddRateForecast(forecastCurve);
            var coordinator = new Coordinator(curveSim, new List <Simulator>(), 1);

            // Run the valuation
            var value    = coordinator.Value(new Product[] { swap }, valueDate);
            var refValue = -41838.32; // See RateProductTest.xlsx

            Assert.AreEqual(refValue, value, 0.01);
        }
Ejemplo n.º 10
0
        public void Init()
        {
            // Set up the model
            _valueDate = new Date(2016, 9, 17);
            var a             = 0.05;
            var vol           = 0.01;
            var flatCurveRate = 0.07;

            _hullWhiteSim = new HullWhite1F(TestHelpers.ZAR, a, vol, flatCurveRate, flatCurveRate);
            _hullWhiteSim.AddForecast(TestHelpers.Jibar3M);

            // Make the underlying swap
            var    rate      = 0.07;
            var    payFixed  = true;
            double notional  = 1000000;
            var    startDate = new Date(2016, 9, 17);
            var    tenor     = Tenor.FromYears(5);

            _swapPay = TestHelpers.CreateZARSwap(rate, payFixed, notional, startDate, tenor, TestHelpers.Jibar3M);
            _swapRec = TestHelpers.CreateZARSwap(rate, !payFixed, notional, startDate, tenor, TestHelpers.Jibar3M);

            // Full set of exercise dates
            _exDates = new List <Date>
            {
                new Date(2017, 9, 17),
                new Date(2018, 9, 17),
                new Date(2019, 9, 17),
                new Date(2020, 9, 17)
            };
        }
Ejemplo n.º 11
0
 public static IRSwap CreateZARSwap([ExcelArgument(Description = "First reset date of the swap")] Date startDate,
                                    [ExcelArgument(Description = "Tenor of swap, must be a whole number of years.  Example '5Y'.")] Tenor tenor,
                                    [ExcelArgument(Description = "The fixed rate paid or received")] double rate,
                                    [ExcelArgument(Description = "Is the fixed rate paid? Enter 'TRUE' for yes.")] bool payFixed,
                                    [ExcelArgument(Description = "Flat notional for all dates.")] double notional)
 {
     return(IRSwap.CreateZARSwap(rate, payFixed, notional, startDate, tenor));
 }
Ejemplo n.º 12
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.º 13
0
        public static double ValueZARSwap1Curve([ExcelArgument(Description = "The name of the swap.")]
                                                IRSwap swap,
                                                [ExcelArgument(Description =
                                                                   "The date on which valuation is required.  Cannot be before the anchor date of the curve.")]
                                                Date valueDate,
                                                [ExcelArgument(Description =
                                                                   "The discounting curve.  Will also be used for forecasting Jibar and providing the most recent required Jibar fix.")]
                                                IDiscountingSource curve)
        {
            var value = IRSwapEx.ValueSwap(swap, valueDate, curve);

            return(value);
        }
Ejemplo n.º 14
0
        public void TestFloatLeg()
        {
            // Make the reference swap
            var    rate      = 0.0;
            var    payFixed  = true;
            double notional  = 1000000;
            var    startDate = new Date(2016, 9, 17);
            var    tenor     = Tenor.Years(1);
            var    swap      = IRSwap.CreateZARSwap(rate, payFixed, notional, startDate, tenor);

            // Make a FloatLeg
            var resetDates       = new Date[4];
            var paymentDates     = new Date[4];
            var accrualFractions = new double[4];
            var runningDate      = new Date(2016, 9, 17);

            for (var i = 0; i < 4; i++)
            {
                resetDates[i]       = new Date(runningDate);
                paymentDates[i]     = resetDates[i].AddMonths(3);
                accrualFractions[i] = (paymentDates[i] - resetDates[i]) / 365.0;
                runningDate         = paymentDates[i];
            }

            var floatLeg = new FloatLeg(Currency.ZAR, paymentDates, new[] { 1e6, 1e6, 1e6, 1e6 },
                                        resetDates,
                                        new[] { FloatingIndex.JIBAR3M, FloatingIndex.JIBAR3M, FloatingIndex.JIBAR3M, FloatingIndex.JIBAR3M },
                                        new double[] { 0, 0, 0, 0 }, accrualFractions);

            // Set up the model
            var valueDate = new Date(2016, 9, 17);

            Date[]              dates         = { new Date(2016, 9, 17), new Date(2026, 9, 17) };
            double[]            rates         = { 0.07, 0.07 };
            IDiscountingSource  discountCurve = new DatesAndRates(Currency.ZAR, valueDate, dates, rates);
            IFloatingRateSource forecastCurve = new ForecastCurve(valueDate, FloatingIndex.JIBAR3M, dates, rates);
            var curveSim = new DeterminsiticCurves(discountCurve);

            curveSim.AddRateForecast(forecastCurve);

            // Run the valuation
            var coordinator   = new Coordinator(curveSim, new List <Simulator>(), 1);
            var swapValue     = coordinator.Value(new Product[] { swap }, valueDate);
            var floatLegValue = coordinator.Value(new Product[] { floatLeg }, valueDate);

            Assert.AreEqual(swapValue, floatLegValue, 0.01);
        }
Ejemplo n.º 15
0
 public static object _ValueZARSwap1Curve(object[,] swap,
                                          object[,] valueDate,
                                          object[,] curve)
 {
     try
     {
         IRSwap             _swap      = XU.GetObject0D <IRSwap>(swap, "swap");
         Date               _valueDate = XU.GetDate0D(valueDate, "valueDate");
         IDiscountingSource _curve     = XU.GetObject0D <IDiscountingSource>(curve, "curve");
         Double             _result    = XLRates.ValueZARSwap1Curve(_swap, _valueDate, _curve);
         return(XU.ConvertToObjects(_result));
     }
     catch (Exception e)
     {
         return(XU.Error0D(e));
     }
 }
Ejemplo n.º 16
0
        public void TestMultiHWAndFXToyCCIRS()
        {
            var valueDate   = new Date(2016, 9, 17);
            var zarRatesSim = new HullWhite1F(Currency.ZAR, 0.05, 0.01, 0.07, 0.07, valueDate);

            zarRatesSim.AddForecast(FloatingIndex.JIBAR3M);
            var usdRatesSim = new HullWhite1F(Currency.USD, 0.05, 0.01, 0.01, 0.01, valueDate);

            usdRatesSim.AddForecast(FloatingIndex.LIBOR3M);
            var eurRatesSim = new HullWhite1F(Currency.EUR, 0.05, 0.01, 0.005, 0.005, valueDate);

            eurRatesSim.AddForecast(FloatingIndex.EURIBOR3M);

            var currencyPairs = new[]
            { new CurrencyPair(Currency.USD, Currency.ZAR), new CurrencyPair(Currency.EUR, Currency.ZAR) };
            var spots        = new[] { 13.6, 15.0 };
            var vols         = new[] { 0.15, 0.15 };
            var correlations = new[, ]
            {
                { 1.0, 0.0 },
                { 0.0, 1.0 }
            };
            var model = new MultiHWAndFXToy(valueDate, Currency.ZAR, new[] { zarRatesSim, usdRatesSim, eurRatesSim },
                                            currencyPairs, spots, vols, correlations);

            var portfolio = new List <Product>();

            portfolio.Add(CreateFloatingLeg(Currency.ZAR, valueDate, -15e6, FloatingIndex.JIBAR3M, 7));
            portfolio.Add(CreateFloatingLeg(Currency.EUR, valueDate, +1e6, FloatingIndex.EURIBOR3M, 7));
            portfolio.Add(CreateFloatingLeg(Currency.ZAR, valueDate, 13e6, FloatingIndex.JIBAR3M, 13));
            portfolio.Add(CreateFloatingLeg(Currency.USD, valueDate, -1e6, FloatingIndex.EURIBOR3M, 13));
            portfolio.Add(IRSwap.CreateZARSwap(0.07, true, 20e6, valueDate, Tenor.Years(4)));

            var stepInMonths  = 1;
            var fwdValueDates = Enumerable.Range(1, 13 * 12 / stepInMonths)
                                .Select(i => valueDate.AddMonths(stepInMonths * i)).ToArray();
            var coord = new Coordinator(model, new List <Simulator>(), 1000);
            //coord.SetThreadedness(false);
            var epe = coord.EPE(portfolio.ToArray(), valueDate, fwdValueDates);

            Assert.AreEqual(1555002, epe[0], 5000);
            Assert.AreEqual(2170370, epe[87], 5000);
            Assert.AreEqual(0, epe[155], 5);

            //Debug.WriteToFile("c:\\dev\\quantsa\\temp\\epeTest_singlethread_10000.csv", epe);
        }
Ejemplo n.º 17
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);
             */
        }
Ejemplo n.º 18
0
        public void EvaluateMetricsTest()
        {
            PricingStructuresTest pricingStructuresTest = new PricingStructuresTest();

            pricingStructuresTest.CreatePricingStructureTest();

            CrossCurrencySwapTest crossCurrencySwapTest = new CrossCurrencySwapTest();

            crossCurrencySwapTest.CreateAmortisedSwapTest();

            string[] swapProductReferenceKeys = { "SWAP-1" };

            string[] requestedMetrics = { "BreakEvenRate" };

            string   marketEnvironmentId = PricingStructuresTest.MarketEnvironmentId;
            DateTime valuationDate       = Convert.ToDateTime("15/05/2009");
            bool     withHeaders         = false;

            object[,] actual = (object[, ])IRSwap.EvaluateMetrics(swapProductReferenceKeys, requestedMetrics, marketEnvironmentId, valuationDate, withHeaders);
            Assert.AreEqual(0.0407, (double)(decimal)actual[0, 0], 0.0001);
        }
Ejemplo n.º 19
0
 public static object _CreateZARSwap(string objectName,
                                     object[,] startDate,
                                     object[,] tenor,
                                     object[,] rate,
                                     object[,] payFixed,
                                     object[,] notional)
 {
     try
     {
         Date    _startDate = XU.GetDate0D(startDate, "startDate");
         Tenor   _tenor     = XU.GetTenor0D(tenor, "tenor");
         Double  _rate      = XU.GetDouble0D(rate, "rate");
         Boolean _payFixed  = XU.GetBoolean0D(payFixed, "payFixed");
         Double  _notional  = XU.GetDouble0D(notional, "notional");
         IRSwap  _result    = XLRates.CreateZARSwap(_startDate, _tenor, _rate, _payFixed, _notional);
         return(XU.AddObject(objectName, _result));
     }
     catch (Exception e)
     {
         return(XU.Error0D(e));
     }
 }
Ejemplo n.º 20
0
        public void TestCoordinatorEPESwap()
        {
            // Make the swap
            var    rate      = 0.07;
            var    payFixed  = true;
            double notional  = 1000000;
            var    startDate = new Date(2016, 9, 17);
            var    tenor     = Tenor.Years(5);
            var    swap      = IRSwap.CreateZARSwap(rate, payFixed, notional, startDate, tenor);

            // Set up the model
            var valueDate     = new Date(2016, 9, 17);
            var a             = 0.05;
            var vol           = 0.005;
            var flatCurveRate = 0.07;
            var hullWiteSim   = new HullWhite1F(Currency.ZAR, a, vol, flatCurveRate, flatCurveRate, valueDate);

            hullWiteSim.AddForecast(FloatingIndex.JIBAR3M);
            var coordinator = new Coordinator(hullWiteSim, new List <Simulator>(), 5000);

            var date          = valueDate;
            var endDate       = valueDate.AddTenor(tenor);
            var fwdValueDates = new List <Date>();

            while (date < endDate)
            {
                fwdValueDates.Add(date);
                date = date.AddTenor(Tenor.Days(10));
            }

            var epe = coordinator.EPE(new Product[] { swap }, valueDate, fwdValueDates.ToArray());

            //Debug.WriteToFile(@"c:\dev\temp\epe_rate08_vol005.csv", epe);

            Assert.AreEqual(2560, epe[0], 100.0);
            Assert.AreEqual(6630, epe[90], 100.0);
            Assert.AreEqual(734, epe[182], 30);
        }
Ejemplo n.º 21
0
        public void CreateAmortisedSwapTest()
        {
            object[,] swapTermsList
                = new object[, ]
                {
                { "SwapReferenceIdentifier", "SWAP-1" },
                { "EffectiveDate", Convert.ToDateTime("15/05/2009") },
                { "TerminationDate", Convert.ToDateTime("15/05/2014") },
                { "AdjustCalculationDates", true },
                { "BasePartyPaysRecievesInd", "Pays" },
                { "CounterpartyName", "Telstra" },
                { "QuotedCurrencyPair", "AUD-AUD" },
                { "NotionalAmount", 1000000 },
                { "NotionalCurrency", "AUD" },
                { "PayReceiveSpotRate", 1 },
                { "hasInitialExchange", false },
                { "hasFinallExchange", false },
                { "principleExchangeBusinessCenters", "Sydney" },
                { "principleExchangeAdjustementConvention", "MODFOLLOWING" }
                };

            object[,] payLegTermsList
                = new object[, ]
                {
                { "StreamType", "Fixed" },
                { "NotionalAmount", 1000000.00 },
                { "Currency", "AUD" },
                { "ScheduleGeneration", "Forward" },
                { "BusinessCenters", "Sydney" },
                { "CouponPeriod", "6m" },
                { "RollDay", "1" },
                { "CouponDateAdjustment", "FOLLOWING" },
                { "DayCountConvention", "ACT/365.FIXED" },
                { "DiscountingType", "Standard" },
                { "DiscountCurveReference", "RateCurve.AUD-LIBOR-BBA-3M" },
                { "FixedOrObservedRate", 0.06 },
                { "ObservedRateSpecified", false },
                { "ForwardCurveReference", "RateCurve.AUD-LIBOR-BBA-3M" },
                { "FixingDateBusinessCenters", "Sydney" },
                { "FixingDateResetInterval", "0D" },
                { "FixingDateAdjustmentConvention", "NONE" },
                { "RateIndexName", "AUD-LIBOR-BBA" },
                { "RateIndexTenor", "6m" },
                { "Spread", 0.0022 }
                };

            object[,] receiveLegTermsList = new object[, ]
            {
                { "StreamType", "Floating" },
                { "NotionalAmount", 1000000 },
                { "Currency", "AUD" },
                { "ScheduleGeneration", "Forward" },
                { "BusinessCenters", "Sydney" },
                { "CouponPeriod", "6m" },
                { "RollDay", "1" },
                { "CouponDateAdjustment", "FOLLOWING" },
                { "DayCountConvention", "ACT/365.FIXED" },
                { "DiscountingType", "Standard" },
                { "DiscountCurveReference", "RateCurve.AUD-LIBOR-BBA-3M" },
                { "FixedOrObservedRate", 0 },
                { "ObservedRateSpecified", false },
                { "ForwardCurveReference", "RateCurve.AUD-LIBOR-BBA-3M" },
                { "FixingDateBusinessCenters", "Sydney" },
                { "FixingDateResetInterval", "0D" },
                { "FixingDateAdjustmentConvention", "NONE" },
                { "RateIndexName", "AUD-LIBOR-BBA" },
                { "RateIndexTenor", "6m" },
                { "Spread", 0.0007 }
            };

            object[,] payLegAmortisationStepSchedule     = null; // TODO: Initialize to an appropriate value
            object[,] receiveLegAmortisationStepSchedule = null; // TODO: Initialize to an appropriate value
            object[,] payCouponStepSchedule     = null;          // TODO: Initialize to an appropriate value
            object[,] receiveCouponStepSchedule = null;          // TODO: Initialize to an appropriate value
            string expected = "SWAP-1";
            string actual;

            actual = IRSwap.CreateAmortisedSwap(swapTermsList, payLegTermsList, receiveLegTermsList, payLegAmortisationStepSchedule, receiveLegAmortisationStepSchedule, payCouponStepSchedule, receiveCouponStepSchedule);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 22
0
 public void SetUp()
 {
     _swap = ExcelTestHelpers.ZARSwap();
 }
Ejemplo n.º 23
0
        public void TestMultiHWAndFXToyCCIRSAltConstructor()
        {
            var valueDate = new Date(2016, 9, 17);
            var spots     = new List <double> {
                13.6, 15.0
            };
            var vols = new List <double> {
                0.15, 0.15
            };
            var correlations = new[, ]
            {
                { 1.0, 0.0 },
                { 0.0, 1.0 }
            };
            // ZAR HW specs
            IDiscountingSource zarCurve = new DatesAndRates(Currency.ZAR, valueDate,
                                                            new[] { valueDate, valueDate.AddMonths(240) },
                                                            new[] { 0.07, 0.07 });
            var zarHWParams = new HWParams {
                vol = 0.01, meanReversionSpeed = 0.05
            };
            var zarRequiredIndices = new List <FloatingIndex> {
                FloatingIndex.JIBAR3M
            };

            // Lists to be populated for other currencies
            var otherCcys               = new List <Currency>();
            var otherCcyCurves          = new List <IDiscountingSource>();
            var otherCcyHwParams        = new List <HWParams>();
            var otherCcyRequiredIndices = new List <List <FloatingIndex> >();

            // USD HW specs
            otherCcys.Add(Currency.USD);
            otherCcyCurves.Add(new DatesAndRates(Currency.USD, valueDate, new[] { valueDate, valueDate.AddMonths(240) },
                                                 new[] { 0.01, 0.01 }));
            otherCcyHwParams.Add(new HWParams {
                vol = 0.01, meanReversionSpeed = 0.05
            });
            otherCcyRequiredIndices.Add(new List <FloatingIndex> {
                FloatingIndex.LIBOR3M
            });

            // EUR HW specs
            otherCcys.Add(Currency.EUR);
            otherCcyCurves.Add(new DatesAndRates(Currency.EUR, valueDate, new[] { valueDate, valueDate.AddMonths(240) },
                                                 new[] { 0.005, 0.005 }));
            otherCcyHwParams.Add(new HWParams {
                vol = 0.01, meanReversionSpeed = 0.05
            });
            otherCcyRequiredIndices.Add(new List <FloatingIndex> {
                FloatingIndex.EURIBOR3M
            });

            // Construct the model
            var model = new MultiHWAndFXToy(valueDate, zarCurve, zarRequiredIndices, zarHWParams,
                                            otherCcys, spots, vols, otherCcyCurves, otherCcyRequiredIndices, otherCcyHwParams, correlations);

            var portfolio = new List <Product>();

            portfolio.Add(CreateFloatingLeg(Currency.ZAR, valueDate, -15e6, FloatingIndex.JIBAR3M, 7));
            portfolio.Add(CreateFloatingLeg(Currency.EUR, valueDate, +1e6, FloatingIndex.EURIBOR3M, 7));
            portfolio.Add(CreateFloatingLeg(Currency.ZAR, valueDate, 13e6, FloatingIndex.JIBAR3M, 13));
            portfolio.Add(CreateFloatingLeg(Currency.USD, valueDate, -1e6, FloatingIndex.EURIBOR3M, 13));
            portfolio.Add(IRSwap.CreateZARSwap(0.07, true, 20e6, valueDate, Tenor.Years(4)));

            var stepInMonths  = 1;
            var fwdValueDates = Enumerable.Range(1, 13 * 12 / stepInMonths)
                                .Select(i => valueDate.AddMonths(stepInMonths * i)).ToArray();
            var coord = new Coordinator(model, new List <Simulator>(), 1000);
            //coord.SetThreadedness(false);
            var epe = coord.EPE(portfolio.ToArray(), valueDate, fwdValueDates);

            Assert.AreEqual(1555002, epe[0], 5000);
            Assert.AreEqual(2170370, epe[87], 5000);
            Assert.AreEqual(0, epe[155], 5);

            //Debug.WriteToFile("c:\\dev\\quantsa\\temp\\epeTest_2.csv", epe);
        }