Blogs

BIST Fundamentals - Calculate Total Market Cap

Here's how to get BIST 30 stock list, fundamental data and analyze it. 

import pandas as pd
import matplotlib.pyplot as plt
import bs4 as bs
import requests
import yfinance as yf

# Scape BIST 30 Stock Symbols
resp = requests.get('https://www.oyakyatirim.com.tr/piyasa-verileri/XU030')
soup = bs.BeautifulSoup(resp.text, 'lxml')
table = soup.find('table', {'class': 'table table-hover table-striped sort'})
tickers = [row.findAll('td')[0].text + '.IS' for row in table.findAll('tr')[1:]]

# Get Fundamental Stock Data
metrics = ['marketCap']
bist_dict = {}
for ticker in tickers:
    stock_dict = yf.Ticker(ticker).info
    vals = [stock_dict[_] for _ in metrics]
    bist_dict[ticker] = vals

bist = pd.DataFrame.from_dict(bist_dict).T
bist.columns = metrics
bist = bist[metrics].apply(pd.to_numeric)


print("Bist 30 total market cap (Billion TRY)", bist['marketCap'].sum()/10**9)
plt.subplots(figsize=(10,6))
(bist['marketCap'].sort_values(ascending=False)/10**9).plot(kind='bar')
plt.ylabel('Market Cap (in Billions TRY)')
plt.title('Bist 30 Stocks Market Caps')
plt.show()

Bist 30 total market cap (Billion TRY) 1229.3