Esempio n. 1
0
        public void TestMultiHWAndFXToyForwards()
        {
            Date        valueDate   = new Date(2016, 9, 17);
            HullWhite1F zarRatesSim = new HullWhite1F(Currency.ZAR, 0.05, 0.01, 0.07, 0.07, valueDate);

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

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

            eurRatesSim.AddForecast(FloatingIndex.EURIBOR3M);

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

            List <Date> simDates = new List <Date>();

            simDates.Add(valueDate.AddMonths(24));
            model.Reset();
            model.SetNumeraireDates(simDates);
            model.SetRequiredDates(currencyPairs[0], simDates); // Will simulate both currency pairs
            model.Prepare();

            int N = 100;

            double[,] fwdSpotValues = Matrix.Zeros(N, 5);

            for (int i = 0; i < N; i++)
            {
                model.RunSimulation(i);
                fwdSpotValues[i, 0] = model.GetIndices(currencyPairs[0], simDates)[0];
                fwdSpotValues[i, 1] = model.GetIndices(currencyPairs[1], simDates)[0];
                fwdSpotValues[i, 2] = model.GetIndices(FloatingIndex.JIBAR3M, simDates)[0];
                fwdSpotValues[i, 3] = model.GetIndices(FloatingIndex.LIBOR3M, simDates)[0];
                fwdSpotValues[i, 4] = model.GetIndices(FloatingIndex.EURIBOR3M, simDates)[0];
            }
            double meanUSDZAR  = fwdSpotValues.GetColumn(0).Mean();
            double meanEURZAR  = fwdSpotValues.GetColumn(1).Mean();
            double meanJibar   = fwdSpotValues.GetColumn(2).Mean();
            double meanLibor   = fwdSpotValues.GetColumn(3).Mean();
            double meanEuribor = fwdSpotValues.GetColumn(4).Mean();

            Assert.AreEqual(15.7, meanUSDZAR, 0.1);
            Assert.AreEqual(17.2, meanEURZAR, 0.1);
            Assert.AreEqual(0.071, meanJibar, 1e-4);
            Assert.AreEqual(0.01, meanLibor, 1e-4);
            Assert.AreEqual(0.005, meanEuribor, 1e-4);
        }
Esempio n. 2
0
        public void TestMultiHWAndFXToyForwards()
        {
            var valueDate   = new Date(2016, 9, 17);
            var zarRatesSim = new HullWhite1F(TestHelpers.ZAR, 0.05, 0.01, 0.07, 0.07);

            zarRatesSim.AddForecast(TestHelpers.Jibar3M);
            var usdRatesSim = new HullWhite1F(TestHelpers.USD, 0.05, 0.0000001, 0.01, 0.01);

            usdRatesSim.AddForecast(TestHelpers.Libor3M);
            var eurRatesSim = new HullWhite1F(TestHelpers.EUR, 0.05, 0.0000001, 0.005, 0.005);

            eurRatesSim.AddForecast(TestHelpers.Euribor3M);

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

            var simDates = new List <Date>();

            simDates.Add(valueDate.AddMonths(24));
            model.Reset();
            model.SetNumeraireDates(simDates);
            model.SetRequiredDates(currencyPairs[0], simDates); // Will simulate both currency pairs
            model.Prepare(valueDate);

            var N             = 100;
            var fwdSpotValues = Matrix.Zeros(N, 5);

            for (var i = 0; i < N; i++)
            {
                model.RunSimulation(i);
                fwdSpotValues[i, 0] = model.GetIndices(currencyPairs[0], simDates)[0];
                fwdSpotValues[i, 1] = model.GetIndices(currencyPairs[1], simDates)[0];
                fwdSpotValues[i, 2] = model.GetIndices(TestHelpers.Jibar3M, simDates)[0];
                fwdSpotValues[i, 3] = model.GetIndices(TestHelpers.Libor3M, simDates)[0];
                fwdSpotValues[i, 4] = model.GetIndices(TestHelpers.Euribor3M, simDates)[0];
            }

            var meanUSDZAR  = fwdSpotValues.GetColumn(0).Mean();
            var meanEURZAR  = fwdSpotValues.GetColumn(1).Mean();
            var meanJibar   = fwdSpotValues.GetColumn(2).Mean();
            var meanLibor   = fwdSpotValues.GetColumn(3).Mean();
            var meanEuribor = fwdSpotValues.GetColumn(4).Mean();

            Assert.AreEqual(15.0, meanUSDZAR, 0.1);
            Assert.AreEqual(17.2, meanEURZAR, 0.1);
            Assert.AreEqual(0.07, meanJibar, 2e-3);
            Assert.AreEqual(0.01, meanLibor, 1e-4);
            Assert.AreEqual(0.005, meanEuribor, 1e-4);
        }