|
14 | 14 | import net.finmath.montecarlo.BrownianMotion;
|
15 | 15 | import net.finmath.montecarlo.BrownianMotionFromMersenneRandomNumbers;
|
16 | 16 | import net.finmath.montecarlo.assetderivativevaluation.models.BlackScholesModel;
|
| 17 | +import net.finmath.montecarlo.assetderivativevaluation.products.AssetMonteCarloProduct; |
17 | 18 | import net.finmath.montecarlo.assetderivativevaluation.products.EuropeanOption;
|
18 | 19 | import net.finmath.montecarlo.model.ProcessModel;
|
19 | 20 | import net.finmath.montecarlo.process.EulerSchemeFromProcessModel;
|
@@ -65,20 +66,23 @@ public void testDirectValuation() throws CalculationException {
|
65 | 66 |
|
66 | 67 | final RandomVariable asset = process.getProcessValue(timeDiscretization.getTimeIndex(optionMaturity), assetIndex);
|
67 | 68 | final RandomVariable numeraireAtPayment = model.getNumeraire(process, optionMaturity);
|
68 |
| - final RandomVariable numeraireAtEval = model.getNumeraire(process, 0.0); |
| 69 | + final RandomVariable numeraireAtEval = model.getNumeraire(process, initialTime); |
69 | 70 |
|
70 | 71 | final RandomVariable payoff = asset.sub(optionStrike).floor(0.0);
|
71 | 72 | final double value = payoff.div(numeraireAtPayment).mult(numeraireAtEval).getAverage();
|
72 | 73 |
|
73 | 74 | final double valueAnalytic = AnalyticFormulas.blackScholesOptionValue(initialValue, riskFreeRate, volatility, optionMaturity, optionStrike);
|
74 |
| - System.out.println("value using Monte-Carlo.......: " + value); |
75 |
| - System.out.println("value using analytic formula..: " + valueAnalytic); |
| 75 | + |
| 76 | + System.out.println("Implementation using model " + model.getClass().getSimpleName() + " directly."); |
| 77 | + System.out.println("\tvalue using Monte-Carlo.......: " + value); |
| 78 | + System.out.println("\tvalue using analytic formula..: " + valueAnalytic); |
76 | 79 |
|
77 | 80 | Assert.assertEquals(valueAnalytic, value, 0.005);
|
78 | 81 | }
|
79 | 82 |
|
80 | 83 | @Test
|
81 | 84 | public void testProductImplementation() throws CalculationException {
|
| 85 | + |
82 | 86 | /*
|
83 | 87 | * Model
|
84 | 88 | */
|
@@ -107,19 +111,20 @@ public void testProductImplementation() throws CalculationException {
|
107 | 111 | */
|
108 | 112 |
|
109 | 113 | // Create product
|
110 |
| - final EuropeanOption europeanOption = new EuropeanOption(optionMaturity, optionStrike); |
| 114 | + final AssetMonteCarloProduct europeanOption = new EuropeanOption(optionMaturity, optionStrike); |
111 | 115 |
|
112 | 116 | // Value product using model
|
113 |
| - final double value = europeanOption.getValue(monteCarloBlackScholesModel); |
| 117 | + final double value = europeanOption.getValue(initialTime, monteCarloBlackScholesModel).expectation().doubleValue(); |
114 | 118 |
|
115 | 119 | /*
|
116 | 120 | * Analytic value using Black-Scholes formula
|
117 | 121 | */
|
118 | 122 |
|
119 | 123 | final double valueAnalytic = AnalyticFormulas.blackScholesOptionValue(initialValue, riskFreeRate, volatility, optionMaturity, optionStrike);
|
120 | 124 |
|
121 |
| - System.out.println("value using Monte-Carlo.......: " + value); |
122 |
| - System.out.println("value using analytic formula..: " + valueAnalytic); |
| 125 | + System.out.println("\nImplementation using model " + model.getClass().getSimpleName() + " with product " + europeanOption.getClass().getSimpleName()); |
| 126 | + System.out.println("\tvalue using Monte-Carlo.......: " + value); |
| 127 | + System.out.println("\tvalue using analytic formula..: " + valueAnalytic); |
123 | 128 |
|
124 | 129 | Assert.assertEquals(valueAnalytic, value, 0.005);
|
125 | 130 | }
|
|
0 commit comments