Options Terrain: learn derivatives pricing and C++ from zero

Options Terrain is a free educational website that teaches quantitative finance, the mathematics of pricing financial derivatives, together with the C++ programming used to implement it. It is written for students with no prior background in mathematics or programming, and follows a university course on derivatives pricing and C++.

The course has 83 short lessons (about 710 minutes in total). Each lesson has interactive charts, a quiz and, for most, a C++ programming exercise that is compiled and checked on the site's server. Each lesson also has an audio explanation with a transcript. A glossary explains the terms used, and a lab lets learners edit C++ option pricers and see how the price and its sensitivities (the greeks) respond.

Topics include percentages, logarithms, probability and the normal distribution; C++ from first programs to classes, templates and design patterns; forwards, futures, swaps and options; the greeks; binomial trees, Monte Carlo simulation and finite-difference (PDE) methods; mean-reverting models; and interest-rate models including Vasicek, Hull–White and the LIBOR market model. No account is needed and the course is free. Nothing on the site is investment advice.

Course outline

Start here

Maths from zero

Percentages, e and logs, probability, the normal curve, random walks and slopes. Everything the rest of the course leans on.

  1. Percentages, returns and interest: Growth as multiplication, and why compounding leads to e.
  2. e, exponentials and logarithms: Growth, discounting, and turning multiplication into addition.
  3. Probability and expected value: Averages weighted by chance, spread, and counting paths.
  4. The normal distribution: The bell curve, N(x), and lognormal prices.
  5. Random walks and Brownian motion: Coin-flip paths, the √t rule, and how stock prices are modelled.
  6. Slopes and areas: Derivatives as slopes (the greeks), and integrals as areas.

All the C++ you need

C++ basics

From printing a line to functions, references, arrays and pointers, with a program to write in every lesson.

  1. Your first C++ program: Compiling, main(), printing with cout, and comments.
  2. Variables, types and arithmetic: double, int, maths functions, and printing numbers neatly.
  3. Reading input and making decisions: cin, if/else, and the model's no-arbitrage check.
  4. Loops: Repeating work with for and while.
  5. Functions: Packaging a calculation so you can reuse it.
  6. References: functions that change their inputs: Passing by value versus passing by reference.
  7. Arrays, vectors and sorting: Holding many values, indexing from 0, and bubble sort.
  8. Header files and separate compilation: Declarations versus definitions, include guards, and the linker.
  9. Pointers and pointers to functions: Addresses, new and delete, and passing a payoff into a pricer.

Classes and templates

Turning the pricer into classes: models, options, inheritance, virtual functions and templates.

  1. Classes: bundling data with its functions: Why long parameter lists hurt, and the BinModel class.
  2. Inheritance: calls and puts are options: A base class EurOption, derived Call and Put, and pure virtual Payoff.
  3. New options without touching the pricer: Digitals, double digitals and strangles as new subclasses.
  4. Templates: storing the whole tree: BinLattice<double> and BinLattice<bool>, and the exercise boundary.

Monte Carlo in C++

Random numbers, sample paths and the PayOff class hierarchy up to the Bridge pattern.

  1. Random numbers in C++: rand(), uniforms, and the Box–Muller trick for normals.
  2. Simulating stock paths: BSModel, GenerateSamplePath, and a first Monte Carlo price.
  3. Pricing error and Monte Carlo greeks: The standard error formula, and bumping with the same random numbers.
  4. The PayOff class: from enum to polymorphism: Why a switch statement doesn't scale, and an abstract PayOff.
  5. VanillaOption, virtual copying and the Bridge: Who owns the payoff? clone(), the rule of three, and PayOffBridge.
  6. Path-dependent options in C++: PathDepOption, the Asian call, and a control variate in code.

Design patterns

The patterns quant libraries are built from, each on a real pricing problem: factory, singleton, bridge, adapter, decorator, strategy, template method, and modern C++.

  1. A map of the design patterns: What design patterns are, a map of them all, and keeping a large code base manageable (book ch. 11, 12, 15, 16).
  2. Factory and Singleton: creating payoffs by name: Creating payoffs from their names, with automatic registration (book ch. 10).
  3. CRTP: clone() for free, and a generic factory: Removing boilerplate with the curiously recurring template pattern (book ch. 14).
  4. Bridge: time-dependent parameters: A Parameters class so volatility and rates can change over time (book §4.7).
  5. Adapter: a random-number class: RandomBase, the Park–Miller generator, and turning integers into normals (book §6.1–6.4).
  6. Decorator: the convergence table: Wrapping a gatherer to add behaviour, and a generic Wrapper template (book §5.4–5.6).
  7. Decorator: antithetic sampling: Pairing each path with its mirror image, as a generator decorator (book §6.5–6.6).
  8. Strategy: statistics gatherers: Let the caller decide what to measure about a simulation (book §5.1–5.3).
  9. Template method: an exotics engine: Separating products, models and the simulation loop, with cash flows at many dates (book ch. 7).
  10. Strategy: products and tree engines: One tree, many products: TreeProduct and a reusable binomial tree (book ch. 8).
  11. Function objects and template solvers: Function objects, template bisection and Newton–Raphson (book ch. 9).
  12. Smart pointers, exceptions and the rule of almost zero: Exception safety and letting the library manage memory (book ch. 13).

Derivatives

Derivatives: the basics

What a derivative is, and the three big product families: forwards and futures, swaps, and options.

  1. What is a derivative?: Contracts whose value comes from something else, and the three big families.
  2. Forwards and futures: The fair forward price from a cash-and-carry argument, and how futures differ.
  3. Swaps: Exchanging fixed for floating payments, and what a swap is worth.

Options

Calls and puts, their greeks, where the Black–Scholes formula comes from, hedging in practice and the volatility smile, then spreads, digitals, American, Asian, barrier and other exotic options.

  1. What is an option?: Calls, puts, strikes and the hockey-stick payoff.
  2. From payoff to price: Time value, and what the Black–Scholes formula is doing.
  3. Delta: The slope of the price, and the hedge ratio.
  4. Gamma: Curvature, and why it spikes near expiry.
  5. Vega: Sensitivity to volatility, the input nobody can observe.
  6. Theta: Time decay, and the bill for owning gamma.
  7. Rho: Interest rates, and why they matter for long-dated options.
  8. Where the Black–Scholes formula comes from: Itô's lemma, the hedging argument, the PDE, and the formula as a risk-neutral average.
  9. Delta hedging in practice: Rebalancing at discrete times, the hedging error, and realised against implied volatility.
  10. The volatility smile: Implied volatility across strikes, why it isn't flat, and the models that explain it.
  11. Spreads and strategies: Combining calls and puts: spreads, straddles, strangles and butterflies.
  12. Digital options: All-or-nothing payoffs, what they say about Black–Scholes, and why they're hard to hedge.
  13. Double digital options: A bet that the price finishes inside a range: two digitals, and a vega that changes sign.
  14. The dice game: the value of choice: Stop or continue? The idea behind every early-exercise price.
  15. American options on the tree: Comparing exercise with continuation at every node.
  16. Arithmetic averages: where formulas run out: Arithmetic versus geometric Asians, and when to simulate.
  17. The geometric average as one stock: Thirty observations, one lognormal: matching paths pair by pair.
  18. Barrier options: Options that switch on or off when the price touches a level.
  19. Beyond vanilla options: Digitals, spreads, early exercise and averaging.

Pricing methods

The binomial model

Hedging, risk-neutral probabilities and pricing on a tree, then the same pricer in C++.

  1. One step: hedging and replication: Why the option is worth 2.5, not 3, and what delta really is.
  2. The risk-neutral probability: Pricing with q = (R − D)/(U − D) and discounting.
  3. Many steps: the tree and backward induction: Stepping back from the payoff, node by node, and the CRR pricer in C++.
  4. The CRR formula: The tree price written as one sum, and computing it without overflow.
  5. From U and D to volatility: Continuous time, u = e^(σ√Δt), and convergence to Black–Scholes.
  6. Digitals and greeks on a tree: All-or-nothing payoffs, bumping for delta and vega, and why trees struggle.

Monte Carlo

Pricing by simulation, how big its error is, and control variates.

  1. Pricing by simulation: Monte Carlo against the closed form, and why error falls like 1/√N.
  2. Control variates: Use the geometric formula to fix the arithmetic simulation.

Trees and PDEs

Log-price and trinomial trees, then explicit and implicit finite-difference grids.

  1. Trees in log-price: Building the tree on x = ln S, and matching mean and variance.
  2. Trinomial trees: Up, middle or down, with Δx = σ√(3Δt).
  3. From tree to grid: the explicit scheme: The Black–Scholes PDE, finite differences, and boundary conditions.
  4. The implicit scheme and American puts: A tridiagonal system per time step, solved in two sweeps.

Models

Mean reversion

The Ornstein–Uhlenbeck price model, its Asian formula and its greeks.

  1. A mean-reverting price: The OU model, its exact step, and an Asian with a formula.
  2. Greeks under mean reversion: All five greeks, and how gamma and theta compare.

Interest rates

Discounting, bonds, swaps and curves, then the Merton, Vasicek and Hull–White short-rate models.

  1. Interest rates and discounting: Zero-coupon bonds, and simple, annual and continuous compounding.
  2. Yield curves and forward rates: Zero yields, forward rates, and locking in a future rate today.
  3. Bonds, swaps and building the curve: Coupon bonds, the par swap rate, and bootstrapping discount factors.
  4. Short rates and the Merton model: Random rates, B = E[e^(−∫r)], and the first model from the whiteboard.
  5. The Vasicek model: Mean-reverting rates, the bond formula, and curve shapes.
  6. Hull–White: fitting today's curve: A time-dependent drift, bonds that behave like stocks, and bond options.
  7. Caps, floors and LIBOR options: Caplet payoffs, Black's formula, and the Hull–White caplet from the notes.

The LIBOR market model

Caplets, forward LIBORs, correlation and simulating several rates at once.

  1. The LIBOR market model: Modelling forward rates directly, their drifts, and correlation.
  2. Simulating the LMM: Log-Euler steps, predictor–corrector drifts, and a caplet check.

Practice

Write your own pricer

How the lab works, its Monte Carlo class project, and exercises to try in it.

  1. Write your own pricer: How the lab works, and exercises to try in it.