Black Scholes Options Model

I would like to add a Black Scholes model to calculate the premium of 0DTE options. 1 day options.

  • Need a countdown clock from AM until closing time.
  • Use proprietary Gamma Capture for volatility
  • Define Math.Ncdf

Thanks

//Example of a simple Black-Scholes calculation in NinjaScript
def S = Price; //Current asset price
def K = StrikePrice; //Strike price
def T = (MaturityDate - DateTime) / 365.0; //Time to expiration in years. count down
def r = RiskFreeRate; //Risk-free interest rate
def sigma = ImpliedVolatility; //Implied volatility from Gamma Capture

def d1 = (Math.Log(S / K) + (r + 0.5 * sigma * sigma) * T) / (sigma * Math.Sqrt(T));
def d2 = d1 - sigma * Math.Sqrt(T);

def N_d1 = Math.Ncdf(d1); //Cumulative normal distribution for d1
def N_d2 = Math.Ncdf(d2); //Cumulative normal distribution for d2

def CallPrice = S * N_d1 - K * Math.Exp(-r * T) * N_d2; //Black-Scholes call option price

It looks like you are using Python and not C#… The standard System.Math does not have a ncdf function. I’m assuming you have zero clue and just copying this from somewhere since it seems that you are trying to mix two different languages because your example is in Python while you mentioned Math.Ncdf assuming you mean the standard System.Math for C#. If you don’t know how to program, you can start with asking AI. They can produce some good Black-Sholes functions for you. I’m not sure about NinjaTrader, but I would think the data feed for the options chain will have access to pre-calculated Greeks like Gamma.

On a side note, if you are trying to figure out the Gamma Exposure, which has become more popular nowadays… GexBot does give you API access to calculated GEX in real time. The classic (naive) access is currently only $50 a month.

I think I’ve seen free GEX on Github.

EDIT: nevermind - it’s for TOS. AFAIK, Ninjatrader does not offer enough information to calculate it.

Some did create an app for it and put it on GitHub. It uses 15 minute delayed data. Note that it is naive (assuming calls are bought and puts are sold). GitHub - aaguiar10/gflows: View the exposures of four option greeks—delta, gamma, vanna, and charm—for stocks & indexes