Added example.
@@ -29,6 +29,44 @@ with respect to *all* its input <code>RandomVariableDifferentiableInterface</cod
/* Get the derivative of X with respect to Y: */
RandomVariableInterface derivative = gradientOfX.get(Y.getID());
+### Example
+The following sample code calculate delta, vega and rho for an
+almost arbitrary product (here an EuropeanOption) using
+AAD on the Monte-Carlo valuation
+ RandomVariableDifferentiableAADFactory randomVariableFactory = new RandomVariableDifferentiableAADFactory();
+
+ // Generate independent variables (quantities w.r.t. to which we like to differentiate)
+ RandomVariableDifferentiableInterface initialValue = randomVariableFactory.createRandomVariable(modelInitialValue);
+ RandomVariableDifferentiableInterface riskFreeRate = randomVariableFactory.createRandomVariable(modelRiskFreeRate);
+ RandomVariableDifferentiableInterface volatility = randomVariableFactory.createRandomVariable(modelVolatility);
+
+ // Create a model
+ AbstractModel model = new BlackScholesModel(initialValue, riskFreeRate, volatility);
+
+ // Create a time discretization
+ TimeDiscretizationInterface timeDiscretization = new TimeDiscretization(0.0 /* initial */, numberOfTimeSteps, deltaT);
+
+ // Create a corresponding MC process
+ AbstractProcess process = new ProcessEulerScheme(new BrownianMotion(timeDiscretization, 1 /* numberOfFactors */, numberOfPaths, seed));
+
+ // Using the process (Euler scheme), create an MC simulation of a Black-Scholes model
+ AssetModelMonteCarloSimulationInterface monteCarloBlackScholesModel = new MonteCarloAssetModel(model, process);
+
+ /*
+ * Value a call option (using the product implementation)
+ */
+ EuropeanOption europeanOption = new EuropeanOption(optionMaturity, optionStrike);
+ RandomVariableInterface value = (RandomVariableDifferentiableInterface) europeanOption.getValue(0.0, monteCarloBlackScholesModel);
+
+ /*
+ * Calculate sensitivities using AAD
+ */
+ Map<Long, RandomVariableInterface> derivative = ((RandomVariableDifferentiableInterface)value).getGradient();
+
+ double valueMonteCarlo = value.getAverage();
+ double deltaAAD = derivative.get(initialValue.getID()).getAverage();
+ double rhoAAD = derivative.get(riskFreeRate.getID()).getAverage();
+ double vegaAAD = derivative.get(volatility.getID()).getAverage();
