FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
black76.hpp File Reference

Black-76 option pricing, greeks and implied volatility (options on a forward / futures price). More...

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <numbers>

Go to the source code of this file.

Classes

struct  fastmm::options::Greeks
 
struct  fastmm::options::IvResult
 

Namespaces

namespace  fastmm
 
namespace  fastmm::options
 

Enumerations

enum class  fastmm::options::CallPut : std::uint8_t { fastmm::options::Call = 0 , fastmm::options::Put = 1 }
 
enum class  fastmm::options::IvStatus : std::uint8_t {
  fastmm::options::Ok = 0 , fastmm::options::AtIntrinsic = 1 , fastmm::options::OutOfBounds = 2 , fastmm::options::BadInput = 3 ,
  fastmm::options::NoConvergence = 4
}
 

Functions

double fastmm::options::norm_pdf (double x) noexcept
 Standard normal density and distribution. erfc keeps the far tail accurate (no 1 - N(x)).
 
double fastmm::options::norm_cdf (double x) noexcept
 
constexpr double fastmm::options::year_fraction (std::int64_t expiry_ns, std::int64_t now_ns) noexcept
 Year fraction between two epoch-ns timestamps (ACT/365); negative once expired.
 
Greeks fastmm::options::black76 (CallPut cp, double forward, double strike, double t_years, double sigma, double rate=0.0) noexcept
 Price and greeks.
 
double fastmm::options::black76_price (CallPut cp, double forward, double strike, double t_years, double sigma, double rate=0.0) noexcept
 
IvResult fastmm::options::implied_vol (CallPut cp, double price, double forward, double strike, double t_years, double rate=0.0, double price_tol=1e-12, int max_iterations=100) noexcept
 Implied volatility of a Black-76 price.
 
double fastmm::options::to_coin_price (double quote_value, double forward) noexcept
 Quote-currency value -> price in the base coin (Deribit BTC options: USD / underlying price).
 
constexpr double fastmm::options::coin_delta (double delta, double coin_price) noexcept
 Delta of a coin-quoted option in coin units.
 

Variables

constexpr double fastmm::options::kSecondsPerYear = 365.0 * 86400.0
 ACT/365, as Deribit's theta.
 
constexpr double fastmm::options::kMinVol = 1e-4
 0.01 % annualised
 
constexpr double fastmm::options::kMaxVol = 10.0
 1000 % annualised
 

Detailed Description

Black-76 option pricing, greeks and implied volatility (options on a forward / futures price).

d1 = (ln(F / K) + sigma^2 T / 2) / (sigma sqrt(T)), d2 = d1 - sigma sqrt(T), D = e^{-rT} call = D (F N(d1) - K N(d2)), put = D (K N(-d2) - F N(-d1))

Conventions (per unit of the underlying; multiply by position size and contract multiplier): delta = dV/dF call D N(d1), put -D N(-d1) gamma = d2V/dF2 D n(d1) / (F sigma sqrt(T)) vega = dV/dsigma D F n(d1) sqrt(T) (per 1.00 of vol: /100 for a vol point) theta = dV/dt -D F n(d1) sigma / (2 sqrt(T)) + r V (per year of calendar time) rho = dV/dr -T V (Black-76: the forward does not move) Reference: F. Black, "The pricing of commodity contracts", J. Financial Economics 3 (1976); E. G. Haug, "The Complete Guide to Option Pricing Formulas" (2nd ed.), Black-76 example F = K = 19, T = 0.75, r = 0.10, sigma = 0.28 -> call = put = 1.7011 (tests/core/black76_test.cpp).

Deribit (ticker channel, verified against a recorded testnet ticker) reports the same model with r = interest_rate (0): delta = D N(d1), gamma per USD, vega / 100 (per vol point), theta / 365 (per day) in USD, and rho as the spot-model K T N(d2) / 100 rather than Black-76 rho. Inverse (coin-margined) options are quoted in the base coin: price_coin = V / F, and their delta in coin terms is delta - price_coin (the premium itself moves with F).

Everything is noexcept, allocation-free and uses only <cmath>; the implied-volatility solver is a bracketed Newton iteration with bisection fallback and a hard iteration bound.