Ejemplo n.º 1
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.º 2
0
 private void setDates()
 {
     exDates = new List <Date>();
     for (int i = 0; i < couponDates.Length; i++)
     {
         if (couponDates[i] > firstCouponDate)
         {
             exDates.Add(couponDates[i]);
         }
     }
     exProducts = new List <Product>();
     for (int i = 0; i < couponDates.Length; i++)
     {
         if (couponDates[i] > firstCouponDate)
         {
             exProducts.Add(new CashLeg(new Date[] { couponDates[i].AddTenor(Tenor.Days(1)) }, new double[] { -notional }, new Currency[] { Currency.ZAR }));
         }
     }
 }
Ejemplo n.º 3
0
        public void TestPhysicalSwaptionEPE()
        {
            Coordinator coordinator = new Coordinator(hullWiteSim, new List <Simulator>(), 5000);
            List <Date> exDate      = new List <Date> {
                new Date(2018, 9, 17)
            };
            // Couterparty has option to enter into a receive fixed swap
            BermudanSwaption physicalSwaption = new BermudanSwaption(swapPay, exDate, false);

            Date        date          = valueDate;
            Date        endDate       = valueDate.AddTenor(new Tenor(0, 0, 3, 5));
            List <Date> fwdValueDates = new List <Date>();

            while (date <= endDate)
            {
                fwdValueDates.Add(date);
                date = date.AddTenor(Tenor.Days(10));
            }
            double[] epe = coordinator.EPE(new Product[] { physicalSwaption }, valueDate, fwdValueDates.ToArray());
            //Debug.WriteToFile(@"c:\dev\temp\ene_physicalswaption_HW.csv", epe);
        }
Ejemplo n.º 4
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.º 5
0
        /// <summary>
        /// Add extra dates to make sure that the minimum spacing is not too large to make the Monte Carlo errors bad.
        /// <para/>
        /// At this point the dates are all copied.
        /// </summary>
        public override void Prepare()
        {
            double minStepSize = 20;

            allDates.Insert(0, time0);
            allDates = allDates.Distinct().ToList <Date>();
            allDates.Sort();
            List <Date> newDates = new List <Date>();

            newDates.Add(new Date(allDates[0]));
            for (int i = 1; i < allDates.Count; i++)
            {
                int nSteps = (int)Math.Floor((allDates[i] - allDates[i - 1]) / minStepSize);
                int days   = (allDates[i] - allDates[i - 1]) / (nSteps + 1);
                for (int j = 0; j < nSteps; j++)
                {
                    newDates.Add(new Date(allDates[i - 1].AddTenor(Tenor.Days((j + 1) * days))));
                }
                newDates.Add(new Date(allDates[i]));
            }
            allDates       = newDates;
            allDatesDouble = allDates.Select(date => (double)date).ToArray();
        }