To get the at the money (ATM) strikes of Banknifty index we will use the NSEpython module in python.
Please make sure that you have the nsepython module installed, else:
Type this in the terminal:
$pip install nsepython
First we will have to get the LTP of Banknifty. The following code will print the LTP:
index = (nse_index())
j=index[index.indexName == 'NIFTY BANK']
y = j['last'].values[0]
y = y.replace(',', '')
y = int(float(y))
print("\nNifty bank LTP: " + str(y))
Now to get the ATM strike:
nifty_bank = round(y/100)*100
print("Nifty bank ATM strike: "+ str(nifty_bank))
The result will look like this:


Thanks for the nice tutorial. Sometimes it is difficult to guess the nearest ATM for a stock. Can the same code be used for strategy individual stocks too?
you’re welcome. I think for stocks this method won’t work as we have different strike prices that can sometimes be in decimals as well. I will post another article on how to get atm strikes for stocks.
I prefer two methods here.
For ATM,
Using Round(underlying, -2)
But i prefer to calculate delta on all strike and sell those strikes which are near to +/- 0.5 delta