A model of a price process
The geometric Brownian motion specification in the original Library starter is a useful mathematical example:
Here W is Brownian motion, μ is the drift and σ is the diffusion scale. Constant coefficients imply strong restrictions. The model does not itself capture stochastic volatility, order-book dynamics or discontinuous jumps.
Itô's correction matters
Applying Itô's formula to log S gives a drift correction of −σ²/2. For constant coefficients:
The expected level and the expected log change differ. This is one reason to keep arithmetic returns, log returns and compounded wealth separate in a research implementation.
Physical and pricing measures
A model for observed returns and a risk-neutral model for derivative pricing answer different questions. Under the standard no-dividend Black–Scholes assumptions, risk-neutral dynamics use the risk-free rate in the drift. A fitted historical drift should not simply replace it in the pricing formula.
The original code example
The starter's d₁ expression can be retained as a small, guarded C++ function for positive volatility and time to maturity:
#include <cmath>
#include <stdexcept>
double d1(double S, double K, double r, double sigma, double T) {
if (S <= 0 || K <= 0 || sigma <= 0 || T <= 0)
throw std::invalid_argument("Positive S, K, sigma and T required");
return (std::log(S / K) + (r + 0.5 * sigma * sigma) * T)
/ (sigma * std::sqrt(T));
}
Expiry and zero-volatility cases need their own limiting treatment. An options-pricing project should also test units, discounting, put-call relationships, numerical stability and the difference between implied and realised volatility.