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()