0% found this document useful (0 votes)
37 views1 page

Python Code For Checking FII and Delta Data

The document contains Python code that fetches Foreign Institutional Investor (FII) data from a specified URL and displays it in a DataFrame. It also retrieves Nifty Option Chain data, calculating implied volatility and attempting to extract Delta values, although the latter is noted as unavailable from the source. The code uses libraries such as requests, pandas, and BeautifulSoup for web scraping and data manipulation.

Uploaded by

Anshul Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views1 page

Python Code For Checking FII and Delta Data

The document contains Python code that fetches Foreign Institutional Investor (FII) data from a specified URL and displays it in a DataFrame. It also retrieves Nifty Option Chain data, calculating implied volatility and attempting to extract Delta values, although the latter is noted as unavailable from the source. The code uses libraries such as requests, pandas, and BeautifulSoup for web scraping and data manipulation.

Uploaded by

Anshul Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import requests

import pandas as pd
from bs4 import BeautifulSoup

# Function to fetch FII data (mock URL used, real sources may vary)
def get_fii_data():
url = 'https://www.moneycontrol.com/stocks/marketstats/fii_dii_activity/
index.php'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')

try:
tables = pd.read_html(str(soup))
fii_table = tables[0] # Assume first table has relevant data
print("FII Data:")
print(fii_table.head())
except Exception as e:
print(f"Error fetching FII data: {e}")

# Function to fetch Nifty Option Chain and calculate Delta (simplified)


def get_option_chain_and_delta(symbol='NIFTY', expiry='current'):
url = f"https://www.nseindia.com/api/option-chain-indices?symbol={symbol}"
headers = {
"User-Agent": "Mozilla/5.0",
"Accept-Language": "en-US,en;q=0.9",
}

session = requests.Session()
session.get("https://www.nseindia.com", headers=headers) # Set cookie
response = session.get(url, headers=headers)
data = response.json()

ce_data = []
for d in data['records']['data']:
if 'CE' in d:
ce_data.append({
'strikePrice': d['strikePrice'],
'IV': d['CE'].get('impliedVolatility'),
'Delta': d['CE'].get('delta', 'N/A') # NSE API doesn’t provide
delta directly
})

df = pd.DataFrame(ce_data)
print("\nOption Chain (CE) with Implied Volatility (Delta not available from
NSE):")
print(df.head())

# Run both functions


get_fii_data()
get_option_chain_and_delta()

You might also like