From 990bc430f97e67e67f97b41182d4781f868283aa Mon Sep 17 00:00:00 2001 From: Christian Fries Date: Thu, 27 Jun 2024 13:49:13 +0200 Subject: [PATCH] Improved output. Impelenting against an interface. --- .../MonteCarloBlackScholesModelTest.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/test/java/net/finmath/montecarlo/assetderivativevaluation/MonteCarloBlackScholesModelTest.java b/src/test/java/net/finmath/montecarlo/assetderivativevaluation/MonteCarloBlackScholesModelTest.java index 53dbd1acaa..e4bab61255 100644 --- a/src/test/java/net/finmath/montecarlo/assetderivativevaluation/MonteCarloBlackScholesModelTest.java +++ b/src/test/java/net/finmath/montecarlo/assetderivativevaluation/MonteCarloBlackScholesModelTest.java @@ -14,6 +14,7 @@ import net.finmath.montecarlo.BrownianMotion; import net.finmath.montecarlo.BrownianMotionFromMersenneRandomNumbers; import net.finmath.montecarlo.assetderivativevaluation.models.BlackScholesModel; +import net.finmath.montecarlo.assetderivativevaluation.products.AssetMonteCarloProduct; import net.finmath.montecarlo.assetderivativevaluation.products.EuropeanOption; import net.finmath.montecarlo.model.ProcessModel; import net.finmath.montecarlo.process.EulerSchemeFromProcessModel; @@ -65,20 +66,23 @@ public void testDirectValuation() throws CalculationException { final RandomVariable asset = process.getProcessValue(timeDiscretization.getTimeIndex(optionMaturity), assetIndex); final RandomVariable numeraireAtPayment = model.getNumeraire(process, optionMaturity); - final RandomVariable numeraireAtEval = model.getNumeraire(process, 0.0); + final RandomVariable numeraireAtEval = model.getNumeraire(process, initialTime); final RandomVariable payoff = asset.sub(optionStrike).floor(0.0); final double value = payoff.div(numeraireAtPayment).mult(numeraireAtEval).getAverage(); final double valueAnalytic = AnalyticFormulas.blackScholesOptionValue(initialValue, riskFreeRate, volatility, optionMaturity, optionStrike); - System.out.println("value using Monte-Carlo.......: " + value); - System.out.println("value using analytic formula..: " + valueAnalytic); + + System.out.println("Implementation using model " + model.getClass().getSimpleName() + " directly."); + System.out.println("\tvalue using Monte-Carlo.......: " + value); + System.out.println("\tvalue using analytic formula..: " + valueAnalytic); Assert.assertEquals(valueAnalytic, value, 0.005); } @Test public void testProductImplementation() throws CalculationException { + /* * Model */ @@ -107,10 +111,10 @@ public void testProductImplementation() throws CalculationException { */ // Create product - final EuropeanOption europeanOption = new EuropeanOption(optionMaturity, optionStrike); + final AssetMonteCarloProduct europeanOption = new EuropeanOption(optionMaturity, optionStrike); // Value product using model - final double value = europeanOption.getValue(monteCarloBlackScholesModel); + final double value = europeanOption.getValue(initialTime, monteCarloBlackScholesModel).expectation().doubleValue(); /* * Analytic value using Black-Scholes formula @@ -118,8 +122,9 @@ public void testProductImplementation() throws CalculationException { final double valueAnalytic = AnalyticFormulas.blackScholesOptionValue(initialValue, riskFreeRate, volatility, optionMaturity, optionStrike); - System.out.println("value using Monte-Carlo.......: " + value); - System.out.println("value using analytic formula..: " + valueAnalytic); + System.out.println("\nImplementation using model " + model.getClass().getSimpleName() + " with product " + europeanOption.getClass().getSimpleName()); + System.out.println("\tvalue using Monte-Carlo.......: " + value); + System.out.println("\tvalue using analytic formula..: " + valueAnalytic); Assert.assertEquals(valueAnalytic, value, 0.005); }