Vega plays a vital role for trades. It measures how much the price of an option changes with respect to changes in volatility. In this article, we’ll break down the concept of Vega, explore its importance in options trading, and walk through a clean and efficient implementation in C++, the language of choice for many high-performance financial systems. Whether you’re building a derivatives pricing engine or just deepening your understanding of options, this guide will provide both the theory and the code to get you started. Let’s work on this Vega calculation in C++!
1. What’s Vega?
Let’s derive Vega from the Black-Scholes formula for a European call option.
This is Black-Scholes for a European call option:
[math] \Large C = S \cdot N(d_1) – K e^{-rT} \cdot N(d_2) [/math]
Where:
- [math] S [/math]: spot price
- [math] K [/math]: strike price
- [math] r [/math]: risk-free rate
- [math] T [/math]: time to maturity (in years)
- [math] \sigma [/math]: volatility
- [math] N(\cdot) [/math]: cumulative distribution function of the standard normal distribution
With:
[math] \Large d_1 = \frac{\ln(S/K) + (r + \frac{1}{2}\sigma^2)T}{\sigma \sqrt{T}} [/math]
And:
[math] \Large d_2 = d_1 – \sigma \sqrt{T} [/math]
To compute Vega, we differentiate the Black-Scholes price with respect to [math] \sigma [/math], valid for both call and put optiions:
[math] \Large \text{Vega} = \frac{\partial C}{\partial \sigma} [/math]
After applying calculus and simplifying:
[math] \Large \text{Vega} = S \cdot \phi(d_1) \cdot \sqrt{T} [/math]
Where [math] \phi(d) [/math] is the standard normal probability density function:
[math] \Large \phi(d) = \frac{1}{\sqrt{2\pi}} e^{-d^2 / 2} [/math]
All the terms are positive (spot price, density function and square root of time to maturity).
✅ Summary:
- Vega is positive for both call and put options as all the terms of the formula are positive.
- It reaches its maximum at-the-money, where [math] S \approx K [/math].
- Vega declines as expiration approaches.
- It is essential for volatility trading strategies.
2. Implementation in C++: A Vanilla Snippet
Important assumptions of the following implementation of the vega calculation in C++:
- The option is European (no early exercise).
- We use the Black-Scholes model.
Let’s simply implement the formula defined in the previous section in a vega.cpp
file:
#include <iostream>
#include <cmath>
// Compute standard normal PDF without hardcoding pi
double normal_pdf(double x) {
static const double inv_sqrt_2pi = 1.0 / std::sqrt(2.0 * std::acos(-1.0));
return inv_sqrt_2pi * std::exp(-0.5 * x * x);
}
// Compute d1 for Black-Scholes formula
double d1(double S, double K, double r, double T, double sigma) {
return (std::log(S / K) + (r + 0.5 * sigma * sigma) * T) / (sigma * std::sqrt(T));
}
// Compute Vega
double vega(double S, double K, double r, double T, double sigma) {
double d1_val = d1(S, K, r, T, sigma);
return S * normal_pdf(d1_val) * std::sqrt(T);
}
// Example usage
int main() {
double S = 100.0; // Spot price
double K = 100.0; // Strike price
double r = 0.05; // Risk-free rate
double T = 1.0; // Time to maturity (years)
double sigma = 0.2; // Volatility
double v = vega(S, K, r, T, sigma);
std::cout << "Vega: " << v << std::endl;
return 0;
}
Let’s use a reasonable CMakeLists.txt
to be able to compile the file above:
cmake_minimum_required(VERSION 3.10)
project(vega)
set(CMAKE_CXX_STANDARD 17)
add_executable(vega ../vega.cpp)
Let’s create a build directory and compile:
mkdir build
cd build
comake ..
make
Then run the executable:
➜ build make
[ 50%] Building CXX object CMakeFiles/vega.dir/vega.cpp.o
[100%] Linking CXX executable vega
[100%] Built target vega
➜ build ./vega
Vega: 37.524
Interpretation:
Vega = 37.52 means that if the implied volatility increases by 1 percentage point (0.01), the option’s price increases by approximately 0.3752 units.
So for a 5-point move in volatility (e.g. from 20% to 25%), the option price would rise by ~1.88 units.
Why is it so “high”?
Because:
- The option is at-the-money.
- The time to expiry is 1 year.
- Vega is proportional to [math]S \cdot \sqrt{T}[/math].
- The PDF value [math]\phi(d_1)[/math] is near its peak at [math]d_1 \approx 0[/math].
If you changed any of the following:
- Time to maturity ↓ → Vega ↓
- Move far in- or out-of-the-money → Vega ↓
- Lower spot price → Vega ↓
3. How would you calculate it for an American-Style option?
Since there’s no closed-form solution for American-style options, we would estimate Vega using a numerical approach:
General Steps
- Choose a pricing model that supports American options:
- Most common: binomial tree
- Define base parameters:
Spot price [math]S[/math], strike [math]K[/math], rate [math]r[/math], time [math]T[/math], and volatility [math]\sigma[/math] - Pick a small increment for volatility (e.g., [math]\epsilon = 0.01[/math])
- Compute option prices at [math]\sigma + \epsilon[/math] and [math]\sigma – \epsilon[/math]
using your American option pricing model (e.g., binomial tree):
[math] \Large V_+ = \text{Price}(\sigma + \epsilon) [/math]
[math] \Large V_- = \text{Price}(\sigma – \epsilon) [/math]
Estimate Vega using central difference:
[math] \Large \text{Vega} \approx \frac{V_+ – V_-}{2 \epsilon} [/math]
This is just to give you a taste of it, we will do a vega calculation in C++ for American-style options in another article.