okay @ALGO_Developer so here the code--- nifty_ltp =(kite.ltp('NSE:NIFTY 50')).get('NSE:NIFTY 50').get('last_price') nifty_ltp Out: 15740.1 val = nifty_ltp val2 = math.fmod(val, 100) #print('val2', val2) x = val - val2 abs_val = "{:.0f}".format(x) # to remove .0 string. print('\n Identified CE ATM:',"{:.0f}".format(x)) Out: Identified CE ATM: 15700 but the current ATM should be 15750 https://web.sensibull.com/option-chain?expiry=2021-06-10&tradingsymbol=NIFTY
nifty_ltp =(kite.ltp('NSE:NIFTY 50')).get('NSE:NIFTY 50').get('last_price')
nifty_ltp
Out: 15740.1
val = nifty_ltp
val2 = math.fmod(val, 100)
#print('val2', val2)
x = val - val2
abs_val = "{:.0f}".format(x) # to remove .0 string.
print('\n Identified CE ATM:',"{:.0f}".format(x))
Out: Identified CE ATM: 15700
but the current ATM should be 15750
https://web.sensibull.com/option-chain?expiry=2021-06-10&tradingsymbol=NIFTY
val = nifty_ltp
val2 = math.fmod(val, 50)
val3 = 0
if val2 >= 25:
val3 = 50
else:
val3 = 0
#print('val2', val2)
x = val - val2 + val3
def calculate_atm_strik(last_price, strik_def):
val1 = math.floor(last_price / strik_def) * strik_def
val2 = math.ceil(last_price / strik_def) * strik_def
return val1 if abs(last_price - val1) < abs(last_price - val2) else val2
current_atm_strik = calculate_atm_strik(45958.45, 100)
print("Current ATM Strik is:", current_atm_strik)
-----------
OUTPUT IS# Current ATM Strik is: 46000