finMath.net

Risk Neutral Density

Getting Started

Checkout finmath-experiments from git and run maven (mvn or mvnw) from its directory. This will start a JShell. See Getting Started for details.

Experiment 1-2: Risk neutral density

Run the following experiment from your JShell (which was launched from finmath-experiments).

Experiment 1

The following will plot the value of a European option as a function of the strike. That is \( V(0) = E^{\mathbb{Q}}\left( V(T,K) \frac{N(0)}{N(T)}\right) \) where \( V(T,K) = \max(S(T)-K,0) \) is the payoff function and \( N(T) = \exp(r T) \) is a numeraire.
JShell:

				DoubleUnaryOperator value = strike -> net.finmath.functions.AnalyticFormulas.blackScholesOptionValue(100.0, 0.05, 0.20, 2.0, strike);
				(new net.finmath.plots.Plot2D(0.0, 300.0, 100, value)).show();
			

Experiment 2

In the following we plot the finite difference approximation of the second derivative of the value of the European option. It can be shown that the second derivative of \( V \) with respect to \( K \) is related to the probability density of \( S(T) \) under \( \mathbb{Q} \), that is \[ \frac{\partial V(T,K)}{\partial K} \ = \ \phi_{S(T)}(K) \ \frac{N(0)}{N(T)} \text{.} \]

JShell:

				import net.finmath.functions.AnalyticFormulas;
				import net.finmath.plots.Plot2D;
				
				DoubleUnaryOperator value = strike -> AnalyticFormulas.blackScholesOptionValue(100.0, 0.05, 0.20, 2.0, strike);

				double h = 1E-2;
				DoubleUnaryOperator secondDerivative = strike -> (value.applyAsDouble(strike+h) - 2*value.applyAsDouble(strike) + value.applyAsDouble(strike-h))/(h*h);

				Plot2D plot = new Plot2D(0.0, 300.0, 100, secondDerivative);
				plot.setYAxisNumberFormat(new java.text.DecimalFormat("0.0E00"));
				plot.setXAxisLabel("strike").setYAxisLabel("frequency");
				plot.show();
			

Summary (Experiments 1-2)

We have created a plot of the value and the second derivative of the Black-Scholes formula. The second derivative of the value with respect to the price is (up to a scaling) the probability density of the underlying stock at maturity (under the terminal measure).

Where to continue

You may continue with