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); }
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) }; }
public void TestHullWhite1FForwardsLowRates() { Date valueDate = new Date(2016, 9, 17); double flatRate = 0.01; HullWhite1F usdRatesSim = new HullWhite1F(Currency.USD, 0.05, 0.01, flatRate, flatRate, valueDate); usdRatesSim.AddForecast(FloatingIndex.LIBOR3M); List <Date> simDates = new List <Date>(); simDates.Add(valueDate.AddMonths(24)); simDates.Add(simDates[0].AddTenor(FloatingIndex.LIBOR3M.tenor)); usdRatesSim.Reset(); usdRatesSim.SetNumeraireDates(simDates); usdRatesSim.Prepare(); int N = 10000; double[,] simFwdValues = Matrix.Zeros(N, 2); for (int i = 0; i < N; i++) { usdRatesSim.RunSimulation(i); simFwdValues[i, 0] = usdRatesSim.GetIndices(FloatingIndex.LIBOR3M, simDates)[0]; simFwdValues[i, 1] = 1.0 / usdRatesSim.Numeraire(simDates[1]); } double dt = (simDates[1] - simDates[0]) / 365.0; double impliedFwd = (Math.Exp(flatRate * dt) - 1) / dt; double[] discountedFRA = simFwdValues.GetColumn(0).Subtract(impliedFwd); discountedFRA = Elementwise.Multiply(discountedFRA, simFwdValues.GetColumn(1)); double actual = discountedFRA.Mean(); Assert.AreEqual(0.0, actual, 1e-4); }
public void TestHullWhite1FForwardsLowRates() { var valueDate = new Date(2016, 9, 17); var flatRate = 0.01; var usdRatesSim = new HullWhite1F(TestHelpers.USD, 0.05, 0.01, flatRate, flatRate); usdRatesSim.AddForecast(TestHelpers.Libor3M); var simDates = new List <Date>(); simDates.Add(valueDate.AddMonths(24)); simDates.Add(simDates[0].AddTenor(TestHelpers.Libor3M.Tenor)); usdRatesSim.Reset(); usdRatesSim.SetNumeraireDates(simDates); usdRatesSim.Prepare(valueDate); var N = 10000; var simFwdValues = Matrix.Zeros(N, 2); for (var i = 0; i < N; i++) { usdRatesSim.RunSimulation(i); simFwdValues[i, 0] = usdRatesSim.GetIndices(TestHelpers.Libor3M, simDates)[0]; simFwdValues[i, 1] = 1.0 / usdRatesSim.Numeraire(simDates[1]); } var dt = (simDates[1] - simDates[0]) / 365.0; var impliedFwd = (Math.Exp(flatRate * dt) - 1) / dt; var discountedFRA = simFwdValues.GetColumn(0).Subtract(impliedFwd); discountedFRA = discountedFRA.Multiply(simFwdValues.GetColumn(1)); var actual = discountedFRA.Mean(); Assert.AreEqual(0.0, actual, 2e-4); }
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) }; }
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(); }
/// <summary> /// Initializes a new instance of the <see cref="MultiHWAndFXToy"/> class. /// </summary> /// <param name="anchorDate">The anchor date.</param> /// <param name="numeraireCcy">The numeraire currency.</param> /// <param name="rateSimulators"></param> /// <param name="currencyPairs"></param> /// <param name="spots">The exchange rates at the anchor date. Discounted from the spot values. Quoted in units of the numeraire currency per unit of the foreign currency.</param> /// <param name="vols"></param> /// <param name="correlations"></param> /// <exception cref="System.ArgumentException">A rate simulator must be provided for the numeraire currency: " + numeraireCcy.ToString()</exception> public MultiHWAndFXToy(Date anchorDate, Currency numeraireCcy, HullWhite1F[] rateSimulators, CurrencyPair[] currencyPairs, double[] spots, double[] vols, double[,] correlations) { this.anchorDate = anchorDate; this.numeraireCcy = numeraireCcy; this.rateSimulators = rateSimulators; this.currencyPairs = currencyPairs; this.spots = spots; this.vols = vols; this.correlations = correlations; normal = new MultivariateNormalDistribution(Vector.Zeros(currencyPairs.Length), correlations); numeraireSimulator = null; ccySimMap = new Dictionary <Currency, HullWhite1F>(); foreach (HullWhite1F simulator in rateSimulators) { if (simulator.GetNumeraireCurrency() == numeraireCcy) { numeraireSimulator = simulator; } ccySimMap[simulator.GetNumeraireCurrency()] = simulator; } if (numeraireSimulator == null) { throw new ArgumentException("A rate simulator must be provided for the numeraire currency: " + numeraireCcy.ToString()); } }
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); }
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); }
public void TestCallableBond() { var valueDate = new Date(2017, 1, 23); var a = 0.05; var vol = 0.01; var flatCurveRate = 0.18; var hullWiteSim = new HullWhite1F(TestHelpers.ZAR, a, vol, flatCurveRate, flatCurveRate); var coordinator = new Coordinator(hullWiteSim, new List <Simulator>(), 5000); var callableBond = new CallableBond(TestHelpers.ZAR); var value1 = coordinator.Value(new Product[] { callableBond }, valueDate); }
public static HullWhite1F CreateHWModelDemo([ExcelArgument(Description = "The constant rate of mean reversion.")] double meanReversion, [ExcelArgument(Description = "The constant short rate volatility. Note that this is a Gaussian vol and will in general be lower than the vol that would be used in Black.")] double flatVol, [ExcelArgument(Description = "The curve to which zero coupon bond prices will be calibrated.")] IDiscountingSource baseCurve, [ExcelArgument(Description = "The indices that should be forecast with this same cuve. No spreads are added.")] FloatingIndex forecastIndices) { Date anchorDate = baseCurve.GetAnchorDate(); double flatCurveRate = -Math.Log(baseCurve.GetDF(anchorDate.AddTenor(Tenor.Years(1)))); HullWhite1F model = new HullWhite1F(baseCurve.GetCurrency(), meanReversion, flatVol, flatCurveRate, flatCurveRate, anchorDate); model.AddForecast(forecastIndices); return(model); }
public void TestCallableBond() { Date valueDate = new Date(2017, 1, 23); double a = 0.05; double vol = 0.01; double flatCurveRate = 0.18; HullWhite1F hullWiteSim = new HullWhite1F(Currency.ZAR, a, vol, flatCurveRate, flatCurveRate, valueDate); Coordinator coordinator = new Coordinator(hullWiteSim, new List <Simulator>(), 5000); CallableBond callableBond = new CallableBond(); double value1 = coordinator.Value(new Product[] { callableBond }, valueDate); }
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); }
public void TestMultiHWAndFXToyCCIRS() { 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.01, 0.01, 0.01); usdRatesSim.AddForecast(TestHelpers.Libor3M); var eurRatesSim = new HullWhite1F(TestHelpers.EUR, 0.05, 0.01, 0.005, 0.005); eurRatesSim.AddForecast(TestHelpers.Euribor3M); var currencyPairs = new[] { TestHelpers.USDZAR, TestHelpers.EURZAR }; 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, TestHelpers.ZAR, new[] { zarRatesSim, usdRatesSim, eurRatesSim }, currencyPairs, spots, vols, correlations); var portfolio = new List <IProduct> { CreateFloatingLeg(TestHelpers.ZAR, valueDate, -15e6, TestHelpers.Jibar3M, 7), CreateFloatingLeg(TestHelpers.EUR, valueDate, +1e6, TestHelpers.Euribor3M, 7), CreateFloatingLeg(TestHelpers.ZAR, valueDate, 13e6, TestHelpers.Jibar3M, 13), CreateFloatingLeg(TestHelpers.USD, valueDate, -1e6, TestHelpers.Euribor3M, 13), TestHelpers.CreateZARSwap(0.07, true, 20e6, valueDate, Tenor.FromYears(4), TestHelpers.Jibar3M) }; 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(1489695, epe[0], 5000); Assert.AreEqual(2194183, epe[87], 5000); Assert.AreEqual(0, epe[155], 5); //QuantSA.Shared.Debug.Debug.WriteToFile("c:\\dev\\quantsa\\temp\\epeTest_singlethread_10000.csv", epe); }
private Dictionary <int, double[]> simulation; // stores the simulated spot rates at each required date /// <summary> /// Initializes a new instance of the <see cref="MultiHWAndFXToy"/> class. /// </summary> /// <param name="anchorDate">The anchor date.</param> /// <param name="numeraireCurve">The numeraire curve.</param> /// <param name="numeraireHWParams"></param> /// <param name="otherCcys">The other currencies that will be simulated.</param> /// <param name="otherCcySpots">The exchange rates at the anchor date. Discounted from the spot values. Quoted in units of the numeraire currency per unit of the foreign currency.</param> /// <param name="otherCcyVols"></param> /// <param name="otherCcyCurves"></param> /// <param name="otherCcyHwParams"></param> /// <param name="correlations">The correlation matrix ordered by: numeraireRate, otherCcy1Rate, ..., otherCcyFX1, ...</param> /// <exception cref="System.ArgumentException">A rate simulator must be provided for the numeraire currency: " + numeraireCcy.ToString()</exception> public MultiHWAndFXToy(Date anchorDate, IDiscountingSource numeraireCurve, List <FloatingIndex> numeraireCcyRequiredIndices, HWParams numeraireHWParams, List <Currency> otherCcys, List <double> otherCcySpots, List <double> otherCcyVols, List <IDiscountingSource> otherCcyCurves, List <List <FloatingIndex> > otherCcyRequiredIndices, List <HWParams> otherCcyHwParams, double[,] correlations) { this.anchorDate = anchorDate; numeraireCcy = numeraireCurve.GetCurrency(); List <HullWhite1F> rateSimulatorsList = new List <HullWhite1F>(); ccySimMap = new Dictionary <Currency, HullWhite1F>(); double rate = -Math.Log(numeraireCurve.GetDF(anchorDate.AddMonths(12))); numeraireSimulator = new HullWhite1F(numeraireCcy, numeraireHWParams.meanReversionSpeed, numeraireHWParams.vol, rate, rate, anchorDate); foreach (FloatingIndex index in numeraireCcyRequiredIndices) { numeraireSimulator.AddForecast(index); } rateSimulatorsList.Add(numeraireSimulator); ccySimMap[numeraireCcy] = numeraireSimulator; for (int i = 0; i < otherCcys.Count; i++) { rate = -Math.Log(otherCcyCurves[i].GetDF(anchorDate.AddMonths(12))); HullWhite1F thisSim = new HullWhite1F(otherCcys[i], otherCcyHwParams[i].meanReversionSpeed, otherCcyHwParams[i].vol, rate, rate, anchorDate); foreach (FloatingIndex index in otherCcyRequiredIndices[i]) { thisSim.AddForecast(index); } rateSimulatorsList.Add(thisSim); ccySimMap[otherCcys[i]] = thisSim; } currencyPairs = otherCcys.Select(ccy => new CurrencyPair(ccy, numeraireCcy)).ToArray(); spots = otherCcySpots.ToArray(); vols = otherCcyVols.ToArray(); this.correlations = Matrix.Identity(otherCcys.Count); normal = new MultivariateNormalDistribution(Vector.Zeros(currencyPairs.Length), correlations); rateSimulators = rateSimulatorsList.ToArray(); }
public static object _CreateHWModelDemo(string objectName, object[,] meanReversion, object[,] flatVol, object[,] baseCurve, object[,] forecastIndices) { try { Double _meanReversion = XU.GetDouble0D(meanReversion, "meanReversion"); Double _flatVol = XU.GetDouble0D(flatVol, "flatVol"); IDiscountingSource _baseCurve = XU.GetObject0D <IDiscountingSource>(baseCurve, "baseCurve"); FloatingIndex _forecastIndices = XU.GetFloatingIndex0D(forecastIndices, "forecastIndices"); HullWhite1F _result = XLRates.CreateHWModelDemo(_meanReversion, _flatVol, _baseCurve, _forecastIndices); return(XU.AddObject(objectName, _result)); } catch (Exception e) { return(XU.Error0D(e)); } }
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.FromYears(5); var swap = TestHelpers.CreateZARSwap(rate, payFixed, notional, startDate, tenor, TestHelpers.Jibar3M); // 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(TestHelpers.ZAR, a, vol, flatCurveRate, flatCurveRate); hullWiteSim.AddForecast(TestHelpers.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.FromDays(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); }
public void TestCoordinatorEPESwap() { // Make the swap double rate = 0.07; bool payFixed = true; double notional = 1000000; Date startDate = new Date(2016, 9, 17); Tenor tenor = Tenor.Years(5); IRSwap swap = IRSwap.CreateZARSwap(rate, payFixed, notional, startDate, tenor); // Set up the model Date valueDate = new Date(2016, 9, 17); double a = 0.05; double vol = 0.005; double flatCurveRate = 0.07; HullWhite1F hullWiteSim = new HullWhite1F(Currency.ZAR, a, vol, flatCurveRate, flatCurveRate, valueDate); hullWiteSim.AddForecast(FloatingIndex.JIBAR3M); Coordinator coordinator = new Coordinator(hullWiteSim, new List <Simulator>(), 5000); Date date = valueDate; Date endDate = valueDate.AddTenor(tenor); List <Date> fwdValueDates = new List <Date>(); while (date < endDate) { fwdValueDates.Add(date); date = date.AddTenor(Tenor.Days(10)); } double[] 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); }
public void HullWhite1F_CanCloneViaSerialize() { var model = new HullWhite1F(TestHelpers.ZAR, 0.05, 0.01, 0.07, 0.07); var newModel = (HullWhite1F)Cloner.Clone(model); }