Python Code For Checking FII and Delta Data
Python Code For Checking FII and Delta Data
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}")
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())