C++: Black Scholes Put Option Gamma

Bjarne-stroustrup
 

C++ Black Scholes put gamma code illustrates one sensitivity of a European option’s model price. The original function and helper fragments are retained below. Read the derivative with its units and assumptions before interpreting a numerical result as a quoted market Greek.

C++ Black Scholes put gamma: reading the example

The put function delegates to the call-gamma function. Matching European calls and puts have the same spot curvature under this non-dividend Black–Scholes setup.

Compare matching contracts and inputs when checking this equality. The wrapper also needs the called function declared before use; being displayed later on a web page does not itself create a C++ declaration.

Assumptions and limits of C++ Black Scholes put gamma

Use positive spot S, strike K, volatility v and time remaining T. The functions assume a non-dividend setup and a consistently annualised decimal rate. The missing d_j helper must supply d1 = [ln(S/K)+(r+v²/2)T]/(v√T) and d2 = d1−v√T. Supply declarations and math headers, and define shared constants only once when combining fragments. This is educational code, not a trading recommendation or a newly tested pricing library.

For the relevant definitions, consult the reference documentation. The explanation here does not claim that every preserved legacy fragment compiles unchanged.

Preserved original example

// Calculate the Black Scholes European put option Gamma
double BS_Put_Option_Gamma(double S, double K, double r, double v, double T) 
// Parameters: (S = Current Stock Price, K = Strike Price, r = Risk-Free Rate, v = Volatility of Stock Price, T = Time to Maturity)
{  return BS_Call_Option_Gamma(S, K, r, v, T); } // Identical to call via put-call parity

// Calculate the Black Scholes European call option Gamma
double BS_Call_Option_Gamma(double S, double K, double r, double v, double T) 
// Parameters: (S = Current Stock Price, K = Strike Price, r = Risk-Free Rate, v = Volatility of Stock Price, T = Time to Maturity)
{  return Normal_PDF(d_j(1, S, K, r, v, T))/(S * v * sqrt(T));  }

const double Pi = 3.14159265359;

// Standard Normal probability density function
double Normal_PDF(const double & x)
// Normal PDF(x) = exp(-x*x/2)/{sigma * sqrt(2 * Pi) }
{ return (1.0/(double)pow(2 * Pi, 0.5)) * exp(-0.5 * x * x); }