public unsafe void PriceCall() { double maturity = 3.0; int optionSize = 1; double strike = 100.0; double[] payoffCoefficients = new double[1] { 1.0 }; int nbSamples = 1000000; double[] spots = new double[1] { 100.0 }; double[] volatilities = new double[1] { 0.05 }; double interestRate = 0.05; double[] correlations = new double[1] { 1.0 }; double[] trends = new double[1] { 0.05 }; double price; double ic; API1.PriceBasket( maturity, //maturity in years optionSize, //optionSize strike, //strike when applicable payoffCoefficients, //payoffCoefficients nbSamples, //nbSamples spots, //spots volatilities, //volatilities interestRate, //interest rate correlations, //correlations trends, //trends (donc égaux au taux d'intérêt) &price, &ic); //price et ics contiennent prix et intervalle de couverture selon le pricer double realPrice = TestsCall.RealPrice(maturity, strike, spots, volatilities, interestRate, correlations, 0.0); // directive assert : Assure que le prix renvoyé par la formule fermée et celui renvoyé par la simulation sont dans un intervalle de confiance de largeur 2%. Assert.IsTrue(Math.Abs((realPrice - price) / price) < 0.05); }
public void TestDeltaCall_0() { double maturity = 3.0; int optionSize = 1; double strike = 100.0; double[] payoffCoefficients = new double[1] { 1.0 }; int nbSamples = 1000000; double[] spots = new double[1] { 100.0 }; double[] volatilities = new double[1] { 0.1 }; double interestRate = 0.05; double[] correlations = new double[1] { 1.0 }; // int timestepNumber = 1; double[] trends = new double[1] { 0.05 }; API1.DeltasMultiCurrencyBasket( maturity, optionSize, strike, payoffCoefficients, nbSamples, spots, volatilities, interestRate, correlations, trends, out IntPtr deltasPtr); double[] deltas = new double[1]; System.Runtime.InteropServices.Marshal.Copy(deltasPtr, deltas, 0, 1); //< -deltas contient maintenant les deltas double realDelta = PricerDll.CustomTests.TestsCall.RealDelta0(maturity, strike, spots, volatilities, interestRate, correlations, 0.0); //Assure que le delta calculé et simulé sont dans un intervalle de confiance de largeur inferieure à 2%. Assert.IsTrue(Math.Abs((realDelta - deltas[0]) / deltas[0]) < 0.02); }
public unsafe void PerformPriceTests() { int nbSamples; double[] currentPrices; double[] volatilities; double[] interestRates; double[] correlations; double[] past; int nbRows; double t; double price; double ic; nbSamples = 100000; currentPrices = new double[11] { 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 1.0, 1.0, 1.0, 1.0, 1.0 }; volatilities = new double[11] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; interestRates = new double[6] { 0, 0, 0, 0, 0, 0 }; correlations = new double[11 * 11]; for (int i = 0; i < 11; i++) { for (int j = 0; j < 11; j++) { correlations[11 * i + j] = i == j ? 1 : 0; } } past = currentPrices; nbRows = 1; t = 0; API1.PriceMultimonde2021Quanto( nbSamples, past, nbRows, t, currentPrices, volatilities, interestRates, correlations, &price, &ic); Assert.IsTrue(price == 100); }
public unsafe void PerformPriceTestAnyTime() { double price; double ic; int nbSamples = 100000; double[] volatilities = new double[11] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; double[] interestRates = new double[6] { 0, 0, 0, 0, 0, 0 }; double[] correlations = new double[11 * 11]; for (int i = 0; i < 11; i++) { for (int j = 0; j < 11; j++) { correlations[11 * i + j] = i == j ? 1 : 0; } } int nbRows = 6; double t = (371 / 365.25) * 5.999; double[] past = new double[6 * 11] { 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 1.0, 1.0, 1.0, 1.0, 1.0, 99.0, 100000.0, 100000.0, 100000.0, 100000.0, 100000.0, 1.0, 1.0, 1.0, 1.0, 1.0, 99.0, 100000.0, 100000.0, 100000.0, 100000.0, 100000.0, 1.0, 1.0, 1.0, 1.0, 1.0, 99.0, 100000.0, 100000.0, 100000.0, 100000.0, 100000.0, 1.0, 1.0, 1.0, 1.0, 1.0, 99.0, 100000.0, 100000.0, 100000.0, 100000.0, 100000.0, 1.0, 1.0, 1.0, 1.0, 1.0, 99.0, 100000.0, 100000.0, 100000.0, 100000.0, 100000.0, 1.0, 1.0, 1.0, 1.0, 1.0 }; double[] currentPrices = new double[11] { 99.0, 100000.0, 100000.0, 100000.0, 100000.0, 100000.0, 1.0, 1.0, 1.0, 1.0, 1.0 }; API1.PriceMultimonde2021Quanto( nbSamples, past, nbRows, t, currentPrices, volatilities, interestRates, correlations, &price, &ic); }
public unsafe void PriceTestQuanto() { double maturity = 3.0; double strike = 100.0; int nbSamples = 1000000; double currFXRate = 1.0; double[] interestRates = new double[2] { 0.05, 0.05 }; double[] spots = new double[2] { 100.0, currFXRate *Math.Exp(-interestRates[1] * maturity) }; double[] volatilities = new double[2] { 0.05, 0.00 }; double[] correlations = new double[4] { 1.0, 0.0, 0.0, 1.0 }; double price; double ic; API1.PriceQuanto( maturity, //maturity in years strike, //strike when applicable nbSamples, //nbSamples spots, //spots volatilities, //volatilities interestRates, //interest rate correlations, //correlations 0.0, spots, &price, &ic); double date = 0.0; //price et ics contiennent prix et intervalle de couverture selon le pricer double realPrice = TestsQuanto.RealPriceCallQuanto(maturity, strike, spots, volatilities, interestRates, correlations, date); Assert.IsTrue((realPrice < price + 1.5 * ic / 2) || (realPrice > price - 1.5 * ic / 2)); }
public void DeltaTestAnyTime() { double maturity = 3.0; int optionSize = 1; double strike = 100.0; double[] payoffCoefficients = new double[1] { 1.0 }; int nbSamples = 1000000; double[] volatilities = new double[1] { 0.05 }; double interestRate = 0.05; double[] correlations = new double[1] { 1.0 }; double[] trends = new double[1] { 0.05 }; double t = 1.0; double[] past = new double[1] { 100.00 }; int nbRows = 1; double[] currents = new double[1] { 95.0 }; double[] deltas = new double[1]; double nbTimeStep = 1; API1.DeltasMultiCurrencyBasketAnyTime( maturity, optionSize, strike, payoffCoefficients, nbSamples, past, nbRows, t, currents, volatilities, interestRate, correlations, trends, nbTimeStep, out IntPtr deltasPtr); System.Runtime.InteropServices.Marshal.Copy(deltasPtr, deltas, 0, 1); //< -deltas contient maintenant les deltas double realDelta = TestsCall.RealDeltaAnyTime(maturity, strike, currents, volatilities, interestRate, correlations, t); Assert.IsTrue(Math.Abs((realDelta - deltas[0]) / deltas[0]) < 0.02); }
public void DeltaTest0() { double maturity = 3.0; double strike = 100.0; int nbSamples = 10000; double currFXRate = 1.2; double[] interestRates = new double[2] { 0.05, 0.03 };; double[] spots = new double[2] { 100.0, currFXRate *Math.Exp(-interestRates[1] * maturity) }; double[] volatilities = new double[2] { 0.01, 0.02 }; double[] correlations = new double[4] { 1.0, 0.05, 0.05, 1.0 }; //call quanto = une seule monnaie pour l'actif (un actif quoi), elle est etrangère API1.SimulDeltasQuanto( maturity, strike, nbSamples, spots, volatilities, interestRates, correlations, 0, spots, out IntPtr deltasAssets, out IntPtr deltasFXRates); double date = 0.0; //price et ics contiennent prix et intervalle de couverture selon le pricer double[] realDelta = TestsQuanto.RealDeltaQuanto0(maturity, strike, spots, volatilities, interestRates, correlations, new double[1] { currFXRate }, date); double[] deltas = new double[2]; double[] tmp = new double[1]; System.Runtime.InteropServices.Marshal.Copy(deltasAssets, tmp, 0, 1); deltas[0] = tmp[0]; System.Runtime.InteropServices.Marshal.Copy(deltasFXRates, tmp, 0, 1); deltas[1] = tmp[0]; double realPrice = TestsQuanto.RealPriceCallQuanto(maturity, strike, spots, volatilities, interestRates, correlations, 0); double tmpD = realPrice - realDelta[0] * spots[0] * currFXRate - realDelta[1] * Math.Exp(-interestRates[0] * maturity); tmpD /= spots[1]; realDelta[1] = tmpD; Assert.IsTrue(Math.Abs((realDelta[0] - deltas[0]) / deltas[0]) < 0.05); }
public unsafe void PriceTestCallAnyTime() { double maturity = 3.0; int optionSize = 1; double strike = 100.0; double[] payoffCoefficients = new double[1] { 1.0 }; int nbSamples = 1000000; double[] past = new double[1] { 100.0 }; int nbRows = 1; double[] currents = new double[1] { 105.0 }; double t = 1.0; double[] volatilities = new double[1] { 0.05 }; double interestRate = 0.05; double[] correlations = new double[1] { 1.0 }; double[] trends = new double[1] { 0.05 }; double nbTimeStep = 1; double price; double ic; API1.PriceBasketAnyTime( maturity, optionSize, strike, payoffCoefficients, nbSamples, past, nbRows, t, currents, volatilities, interestRate, correlations, trends, nbTimeStep, &price, &ic); //price et ics contiennent prix et intervalle de couverture selon le pricer double realPrice = TestsCall.RealPrice(maturity, strike, currents, volatilities, interestRate, correlations, t); //assure que prix formule fermée et prix simulé en tout t<T dans un intervalle de confiance de largeur 2% Assert.IsTrue(Math.Abs((realPrice - price) / price) < 0.05); }