finMath.net

# Getting started

The experiments below use Java JShell started from a Maven project as a starting point (if you already started JShell from finmath-experiments you may continue in that shell, although it is safer to /exit that shell and restart a new one).
1. Open a command shell
2. Type mkdir git (to create a folder git, if you do not have one)
3. Type cd git (to enter your git folder)
4. Next, clone (i.e. download) the repository (git), change to the cloned directory (cd) and start jshell via Maven (mvn) by typing the following three commands:
Terminal Window

git clone https://github.com/finmath/finmath-experiments
cd finmath-experiments
mvn clean compile jshell:run


# Experiment 1-2: Risk neutral density/h1> 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))/(2*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