Bank Nifty Analysis : Straddle Strategy : NSE : Straddle and Strangle Strategy

import requests
import pandas as pd
import numpy
url = 'https://www.nseindia.com/api/option-chain-indices?symbol=BANKNIFTY'
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Apple'
                              'WebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
                              'accept-language': 'en,gu;q=0.9,hi;q=0.8',
                              'accept-encoding': 'gzip, deflate, br'}
session = requests.Session()
requests = session.get(url, headers=headers)
cookies = dict(requests.cookies)
requests = session.get(url, headers=headers,cookies=cookies).json()

# print(requests)
df = pd.DataFrame(requests)
df1 = pd.DataFrame(df['filtered']['data']).fillna(0)
# print(df1)

def dataframe(df1):
    data = []
    for i in range(0,len(df1)):
        calloi = callcoi = cltp = putoi = putcoi = pltp = 0
        stp = df1['strikePrice'][i]

        if(df1['CE'][i]==0):
            calloi = callcoi = 0
        else:
            calloi = df1['CE'][i]['openInterest']
            callcoi = df1['CE'][i]['changeinOpenInterest']
            cltp = df1['CE'][i]['lastPrice']
            expdate = df1['CE'][i]["expiryDate"]
            underlying = df1['CE'][i]["underlyingValue"]
            diff = (stp - df1['CE'][i]["underlyingValue"])*(stp - df1['CE'][i]["underlyingValue"])
        if (df1['PE'][i] == 0):
            putoi = putcoi = 0
        else:
            putoi = df1['PE'][i]['openInterest']
            putcoi = df1['PE'][i]['changeinOpenInterest']
            pltp = df1['PE'][i]['lastPrice']

        opdata = {
            'CALLOI' : calloi, 'CALLCOI' : callcoi, 'CALL LTP' : cltp, 'STRIKE PRICE' : stp,
            'PUTOI': putoi, 'PUTCOI': putcoi, 'PUT LTP': pltp, 'EXP DATE' : expdate, 'UNDERLYING': underlying, 'diff': diff
        }
        data.append(opdata)
    optionchain = pd.DataFrame(data)
    return optionchain

optionchain = dataframe(df1)

for j in range(0, len(optionchain["CALL LTP"])):


    if optionchain["diff"][j] == optionchain["diff"].min():

        print("\nATM: (For Straddle)")
        print("CALL:", optionchain["CALL LTP"][j], "_________BANKNIFTY", optionchain["EXP DATE"][j][:-5],
              optionchain["STRIKE PRICE"][j], "CE", "__________Tot Val", 25 * optionchain["CALL LTP"][j])

        print("PUT:", optionchain["PUT LTP"][j], "_________BANKNIFTY", optionchain["EXP DATE"][j][:-5],
              optionchain["STRIKE PRICE"][j], "PE", "__________Tot Val", 25 * optionchain["PUT LTP"][j])
        print("Total:", 25 * optionchain["CALL LTP"][j]+25 * optionchain["PUT LTP"][j])

    if optionchain["CALL LTP"][j] > 80 and optionchain["CALL LTP"][j] < 120 :
        print("\nCALL OPTION")
        print("CALL(Premium 80 to 100):",optionchain["CALL LTP"][j],"_________BANKNIFTY",optionchain["EXP DATE"][j][:-5],optionchain["STRIKE PRICE"][j],"CE","__________Tot Val",25*optionchain["CALL LTP"][j])

    if optionchain["PUT LTP"][j] > 80 and optionchain["PUT LTP"][j] < 120 :
        print("\nPUT OPTION")
        print("PUT (Premium 80 to 100):",optionchain["PUT LTP"][j],"_________BANKNIFTY",optionchain["EXP DATE"][j][:-5],optionchain["STRIKE PRICE"][j],"PE","__________Tot Val",25*optionchain["PUT LTP"][j])

    if optionchain["PUTOI"][j] == optionchain["PUTOI"].max() :
        print("\nlARGEST OI - PUT OPTION :")
        print("PUT:",optionchain["PUT LTP"][j],"_________BANKNIFTY",optionchain["EXP DATE"][j][:-5],optionchain["STRIKE PRICE"][j],"PE","__________Tot Val",25*optionchain["PUT LTP"][j])

    if optionchain["CALLOI"][j] == optionchain["CALLOI"].max() :
        print("\nlARGEST OI - CALL OPTION :")
        print("CALL:", optionchain["CALL LTP"][j], "_________BANKNIFTY", optionchain["EXP DATE"][j][:-5],
              optionchain["STRIKE PRICE"][j], "CE", "__________Tot Val", 25 * optionchain["CALL LTP"][j])


 Output:

C:\Users\mahen\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/mahen/PycharmProjects/pythonProject/venv/Optionchain.py

PUT OPTION
PUT (Premium 80 to 100): 83.25 _________BANKNIFTY 11-Aug 36900 PE __________Tot Val 2081.25

PUT OPTION
PUT (Premium 80 to 100): 95.75 _________BANKNIFTY 11-Aug 37000 PE __________Tot Val 2393.75

lARGEST OI – PUT OPTION :
PUT: 95.75 _________BANKNIFTY 11-Aug 37000 PE __________Tot Val 2393.75

PUT OPTION
PUT (Premium 80 to 100): 113.8 _________BANKNIFTY 11-Aug 37100 PE __________Tot Val 2845.0

ATM: (For Straddle)
CALL: 372.4 _________BANKNIFTY 11-Aug 37900 CE __________Tot Val 9310.0
PUT: 333.55 _________BANKNIFTY 11-Aug 37900 PE __________Tot Val 8338.75
Total: 17648.75

lARGEST OI – CALL OPTION :
CALL: 126.2 _________BANKNIFTY 11-Aug 38500 CE __________Tot Val 3155.0

CALL OPTION
CALL(Premium 80 to 100): 104.95 _________BANKNIFTY 11-Aug 38600 CE __________Tot Val 2623.75

CALL OPTION
CALL(Premium 80 to 100): 82.6 _________BANKNIFTY 11-Aug 38700 CE __________Tot Val 2065.0

 

By AskMahe.com

Hi, AskMahe.com is the Brainchild of Mahendran Paramasivan who is interested in bringing the latest technology to the common people and corporates. We are a team and we are providing supports on Technology and innovation as per industrial standard. We are supporting with the help of analysis we made on Technology and innovation to help corporate companies and individuals. We bring the latest updates of technology and innovation in front of the eyes of our readers, clients, and people. We have resources in Cloud computing, IoT, Edge Computing, Dew Computing, 5G, SAP, Web Designing, UI/ UX Design. Regards AskMahe Team askmahe.com