-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
136 lines (62 loc) · 2.85 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import requests
from bs4 import BeautifulSoup
import yfinance as yf
import matplotlib.pyplot as plt
class StockAnalyzer:
def __init__(self, ticker):
self.ticker = ticker
def get_google_finance_data(self):
url = f"https://www.google.com/finance/quote/{self.ticker}"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
price = soup.find_all("div", {"class": "YMlKec fxKbKc"})[0].find("span").text
change = soup.find_all("div", {"class": "YMlKec fxKbKc"})[1].find("span").text
return (price, change)
def get_yahoo_finance_data(self, start_date):
data = yf.download(self.ticker, start=start_date)
return data
def get_major_shareholders(self):
url = f"https://money.cnn.com/quote/shareholders/shareholders.html?symb={self.ticker}"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
shareholders = []
for row in soup.find_all("table", {"class": "wsod_dataTable wsod_dataTableBig"})[0].find_all("tr")[1:]:
name = row.find_all("td")[0].text
shares = row.find_all("td")[1].text
shareholders.append((name, shares))
return shareholders
def get_board_of_directors(self):
url = f"https://money.cnn.com/quote/profile/profile.html?symb={self.ticker}"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
directors = []
for row in soup.find_all("table", {"class": "wsod_dataTable"})[0].find_all("tr")[1:]:
name = row.find_all("td")[0].text
title = row.find_all("td")[1].text
age = row.find_all("td")[2].text
pay = row.find_all("td")[3].text
directors.append((name, title, age, pay))
return directors
def plot_stock_price(self, start_date):
data = self.get_yahoo_finance_data(start_date)
plt.plot(data["Adj Close"])
plt.title(f"{self.ticker} Stock Price")
plt.xlabel("Date")
plt.ylabel("Price")
plt.show()
stock = StockAnalyzer("AAPL") # Replace "AAPL" with the ticker symbol of your desired company
# Get the stock price and change from Google Finance
price, change = stock.get_google_finance_data()
print(f"Price: {price}")
print(f"Change: {change}")
# Get the major shareholders
shareholders = stock.get_major_shareholders()
for shareholder in shareholders:
print(f"{shareholder[0]}: {shareholder[1]}")
# Get the board of directors
directors = stock.get_board_of_directors()
for director in directors:
print(f"{director[0]} ({director[1]}) - Age: {director[2]}, Pay: {director[3]}")
# Plot the stock price from the input date using Yahoo Finance
start_date = "2020-01-01"
stock.plot_stock_price(start_date)