forked from ANGELTALAVERA/Finance
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tickers.py
47 lines (42 loc) · 1.77 KB
/
tickers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import pandas as pd
import requests
def tickers_sp500():
url = 'https://en.wikipedia.org/wiki/List_of_S%26P_500_companies'
html = requests.get(url).text
df = pd.read_html(html, header=0)[0]
tickers = df['Symbol'].tolist()
return tickers
def tickers_nasdaq():
url = 'http://www.nasdaqtrader.com/dynamic/symdir/nasdaqlisted.txt'
data = requests.get(url).text
# The data is '|' separated and last two lines are not needed
lines = data.split('\n')
# Convert to DataFrame
df = pd.DataFrame([sub.split("|") for sub in lines[1:-2]], columns=lines[0].split("|"))
return df['Symbol'].tolist()
def tickers_nyse():
url = 'http://www.nasdaqtrader.com/dynamic/symdir/otherlisted.txt'
data = requests.get(url).text
# The data is '|' separated and the last two lines are not needed
lines = data.split('\n')
# Convert to DataFrame
df = pd.DataFrame([sub.split("|") for sub in lines[1:-2]], columns=lines[0].split("|"))
# Filter out only NYSE symbols
nyse_df = df[df['Exchange'] == 'N']
return nyse_df['ACT Symbol'].tolist()
def tickers_dow():
url = 'https://en.wikipedia.org/wiki/Dow_Jones_Industrial_Average'
html = requests.get(url).text
df = pd.read_html(html, header=0, attrs = {'id': 'constituents'})[0]
tickers = df['Symbol'].tolist()
return tickers
def tickers_amex():
url = 'http://www.nasdaqtrader.com/dynamic/symdir/otherlisted.txt'
data = requests.get(url).text
# The data is '|' separated and the last two lines are not needed
lines = data.split('\n')
# Convert to DataFrame
df = pd.DataFrame([sub.split("|") for sub in lines[1:-2]], columns=lines[0].split("|"))
# Filter out only AMEX symbols
amex_df = df[df['Exchange'] == 'A']
return amex_df['ACT Symbol'].tolist()