public static double blackScholesOptionGamma(
			double initialStockValue,
			double riskFreeRate,
			double volatility,
			double optionMaturity,
			double optionStrike)
	{
		if(optionStrike <= 0.0 || optionMaturity <= 0.0)
		{
			// The Black-Scholes model does not consider it being an option
			return 0.0;
		}
		else
		{
			// Calculate gamma
			double dPlus = (Math.log(initialStockValue / optionStrike) + (riskFreeRate + 0.5 * volatility * volatility) * optionMaturity) / (volatility * Math.sqrt(optionMaturity));

			double gamma = Math.exp(-0.5*dPlus*dPlus) / (Math.sqrt(2.0 * Math.PI * optionMaturity) * initialStockValue * volatility);

			return gamma;
		}
	}
public static double blackScholesOptionGamma ( double initialStockValue , double riskFreeRate , double volatility , double optionMaturity , double optionStrike ) { if ( optionStrike <= 0.0 || optionMaturity <= 0.0 ) { return 0.0 ; } else { double dPlus = ( Math . log ( initialStockValue / optionStrike ) + ( riskFreeRate + 0.5 * volatility * volatility ) * optionMaturity ) / ( volatility * Math . sqrt ( optionMaturity ) ) ; double gamma = Math . exp ( - 0.5 * dPlus * dPlus ) / ( Math . sqrt ( 2.0 * Math . PI * optionMaturity ) * initialStockValue * volatility ) ; return gamma ; } }
This static method calculated the gamma of a call option under a Black-Scholes model

@param initialStockValue The initial value of the underlying, i.e., the spot.
@param riskFreeRate The risk free rate of the bank account numerarie.
@param volatility The Black-Scholes volatility.
@param optionMaturity The option maturity T.
@param optionStrike The option strike.
@return The gamma of the option