Esempio n. 1
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);
        }
Esempio n. 2
0
        private Product[] GetListOfSwaps()
        {
            var    N          = 50000;
            var    anchorDate = new Date(2016, 11, 21);
            var    rate       = 0.08;
            var    payFixed   = true;
            double notional   = 1000000;

            var swapDist = new[, ]
            {
                { 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);
            var cumSum = swapDist.CumulativeSum(1);

            var allSwaps = new Product[N];

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

            return(allSwaps);
        }