Hi, I want to know the nearest ATM of an Future Stock or Index when market starts, How do i get it using Python.
I am using Kite Connect to fetch Future Stock Price, I have created Pandas Dataframe which has all future stock price,
But i am not getting a way to find each Future Stocks ATM Strike Price. How do i do that.
Thanks
You need to calculate the distance between all strike prices and the futures price. The strike price which has a minimum distance from the future price is considered as ATM.
Can also check out this link.
Hope that helps.
Created Function to fetch ATM of the Given Symbol under KiteConnect.
instrument_dump = kite.instruments("NFO")
instrument_df = pd.DataFrame(instrument_dump)
def getATM(name):
tickerid=name+"21APRFUT"
ltp =round((kite.ltp('NFO:'+str(tickerid))).get('NFO:'+str(tickerid),{}).get('last_price'),0)
df= instrument_df
expiry=datetime.date(2021,4,29)
atmdf = df.loc[(df['name']==name) & (df['expiry']==expiry)]
lst=atmdf['strike'].tolist()
atmstk= closest(lst,ltp)
return(atmstk)
def closest(lst, K):
return lst[min(range(len(lst)), key = lambda i: abs(lst[i]-K))]
getATM("NTPC")
Output : 107.0 .
Created Function to fetch ATM of the Given Symbol under KiteConnect.
instrument_dump = kite.instruments("NFO")
instrument_df = pd.DataFrame(instrument_dump)
def getATM(name):
tickerid=name+"21APRFUT"
ltp =round((kite.ltp('NFO:'+str(tickerid))).get('NFO:'+str(tickerid),{}).get('last_price'),0)
df= instrument_df
expiry=datetime.date(2021,4,29)
atmdf = df.loc[(df['name']==name) & (df['expiry']==expiry)]
lst=atmdf['strike'].tolist()
atmstk= closest(lst,ltp)
return(atmstk)
def closest(lst, K):
return lst[min(range(len(lst)), key = lambda i: abs(lst[i]-K))]
getATM("NTPC")
Output : 107.0
Glad you solved that!