This example derives, deploys, and validates exact analytical Greeks for European options using the Black-Scholes model for options pricing.
The Black-Scholes PDE has an exact closed-form solution, which means every Greek (Delta, Gamma, Vega, Theta, Rho, Vanna, Volga, Charm, Speed) comes out as a symbolic partial derivative. That parametric form gives you the full sensitivity surface in one expression, versus a bump-and-revalue approach.
The same workflow applies to any pricing PDE with a known functional form: put-call parity Greeks, digital/barrier options via limits, near-ATM polynomial approximations via Taylor expansion, or multi-asset cross-Greeks via the Jacobian.
Symbolic declaration of the Black-Scholes PDE from first principles: GBM dynamics, Ito's lemma on a twice-differentiable option value
States the known European call formula
diff— partial derivatives forming the PDE operatorsimplify— verify residual is identically zero
Each Greek is a symbolic partial derivative of the option price. First-order (Delta, Vega, Theta, Rho) and second-order (Gamma, Vanna, Volga, Charm, Speed) Greeks are computed in closed form.
diff— first and higher partial derivativessimplify— canonical form for each Greek expression
Put-call parity
diff,simplify— derive and verify parity relations
Taylor expansion of Delta and Gamma around
taylor— systematic expansion in moneyness and volatilitysubs— substitute ATM condition before expanding
Digital (binary) call pricing as the limit of a call spread whose width goes to zero. The result
limit— exact evaluation of the call-spread limitsubs— construct shifted strikes symbolically
A two-asset portfolio's full cross-Greek matrix (4×4: sensitivities of Delta and Vega for each asset with respect to both spots and both vols) computed in one jacobian call.
-
jacobian— matrix of all partial derivatives simultaneously -
assume— correlation bounds$-1 < \rho < 1$
Convert symbolic Greek expressions into optimized MATLAB® functions via matlabFunction. Three function files are generated: first-order Greeks, second-order Greeks, and near-ATM Taylor approximations.
matlabFunction— generatesbsGreeks.m,bsGreeksSecondOrder.m,bsGreeksATM.m
Evaluate the exact Greeks across the full
Compare exact Delta against the near-ATM Taylor approximation across moneyness. The polynomial is extremely accurate within
All symbolic Greeks validated against blsprice, blsdelta, blsgamma, blsvega, blstheta, blsrho to confirm the derivation is correct end-to-end.
50,000-path GBM simulation with exact Greeks evaluated at every weekly rebalancing point. Delta-hedge P&L distribution shows that discrete rebalancing error (not Greek noise) is the dominant residual. Performance benchmark: exact evaluation vs. bump-and-revalue timing and accuracy.
randn— GBM path generation- Vectorized Greek evaluation along all paths — no inner bump loop
Running the example produces deployable MATLAB functions:
| Generated file | Signature | Use case |
|---|---|---|
bsGreeks.m |
[Price, Delta, Gamma, Vega, Theta, Rho] = bsGreeks(S, K, r, sigma, tau) |
First-order Greeks for pricing engines and risk aggregation |
bsGreeksSecondOrder.m |
[Vanna, Volga, Charm, Speed] = bsGreeksSecondOrder(S, K, r, sigma, tau) |
Second-order Greeks for volatility risk and gamma scalping |
bsGreeksATM.m |
[DeltaATM, GammaATM] = bsGreeksATM(S, K, r, sigma, tau) |
Near-ATM Taylor approximations for real-time dashboards |
All functions accept vectorized inputs. C code equivalents are available via ccode() for integration with low-latency pricing engines.
- MATLAB R2024b or later
- Symbolic Math Toolbox™
- Financial Toolbox™ (for validation in Section 11 only)
- Open MATLAB and navigate to this directory
- Open
BlackScholesGreeks.mas a Live Script - Run section by section, or run all — the example is self-contained
The generated functions (bsGreeks.m, bsGreeksSecondOrder.m, bsGreeksATM.m) are written to the working directory at runtime.
| File | Description |
|---|---|
BlackScholesGreeks.m |
Main example (Live Script). Full workflow from PDE derivation through Monte Carlo deployment. |
bsGreeks.m |
Generated at runtime. First-order Greeks (Price, Delta, Gamma, Vega, Theta, Rho). |
bsGreeksSecondOrder.m |
Generated at runtime. Second-order Greeks (Vanna, Volga, Charm, Speed). |
bsGreeksATM.m |
Generated at runtime. Near-ATM Taylor approximations. |