-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
266 lines (222 loc) · 9.48 KB
/
main.py
File metadata and controls
266 lines (222 loc) · 9.48 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
""" main.py
This script provides a user interface to interact with various stock analysis
functionalities. It includes options to fetch and plot stock data, summarize
financial metrics, and visualize stock performance.
The script uses a menu-driven approach to allow users to choose from different
stock analysis options, including data fetching, summary retrieval, and various
plotting capabilities for stocks and financial indices.
"""
from src.stock_analysis_program import (
StockDataFetcher,
StockSummaryFetcher,
FinancialMetricsFetcher,
RevenueGrowthFetcher,
StockPricePlotter,
FinancialMetricsPlotter,
RevenueGrowthPlotter,
StockVolatilityPlotter,
StockExchangePerformancePlotter,
CurrentPricesTickerDisplay,
)
def use_stock_data_fetcher():
"""
Interacts with StockDataFetcher to fetch historical data, moving averages,
average volume, and financial metrics for a specific stock ticker.
Users are prompted to enter a stock ticker. The function then displays
historical data, moving averages, average trading volume, and key financial
metrics for the entered ticker.
"""
ticker = input("Enter a stock ticker (e.g., AAPL, GOOGL): ")
fetcher = StockDataFetcher(ticker)
historical_data = fetcher.fetch_historical_data()
moving_averages = fetcher.calculate_moving_averages(historical_data)
average_volume = fetcher.get_average_volume(historical_data)
financial_metrics = fetcher.get_financial_metrics()
print(f"Moving Averages for {ticker}: {moving_averages}")
print(f"Average Volume for {ticker}: {average_volume}")
print(f"Financial Metrics for {ticker}: {financial_metrics}")
def use_stock_summary_fetcher():
"""
Utilizes StockSummaryFetcher to retrieve and display summary information
for a list of stock tickers.
Users can enter multiple stock tickers separated by commas. The function
fetches and displays a summary for each ticker, including name, sector,
industry, and other key details.
"""
tickers = input(
"Enter stock ticker(s) separated by commas (e.g., GOOGL, AAPL): "
).split(",")
fetcher = StockSummaryFetcher([ticker.strip() for ticker in tickers])
summaries = fetcher.get_summaries()
for summary in summaries:
print(f"\nSummary for {summary['Ticker']}:\n")
for key, value in summary.items():
print(f"{key}: {value if value is not None else 'N/A'}")
def use_financial_metrics_fetcher():
"""
Uses FinancialMetricsFetcher to fetch and display financial metrics for a
list of stock tickers.
This function allows users to enter multiple tickers and displays financial
metrics such as market cap, PE ratio, forward PE, and profit margins for
each ticker.
"""
tickers = input(
"Enter stock ticker(s) separated by commas for financial metrics (e.g., AAPL, MSFT): "
).split(",")
fetcher = FinancialMetricsFetcher([ticker.strip() for ticker in tickers])
financial_metrics = fetcher.fetch_financial_metrics()
print("\nFinancial Metrics:")
print(financial_metrics)
def use_revenue_growth_fetcher():
"""
Interacts with RevenueGrowthFetcher to fetch and display year-over-year
revenue growth for a list of stock tickers.
After users input stock tickers, the function calculates and displays the
year-over-year revenue growth percentage for each ticker.
"""
tickers = input(
"Enter stock ticker(s) separated by commas for revenue growth (e.g., AAPL, MSFT): "
).split(",")
fetcher = RevenueGrowthFetcher([ticker.strip() for ticker in tickers])
revenue_growth = fetcher.fetch_revenue_growth()
print("\nYear-over-Year Revenue Growth:")
for ticker, growth in revenue_growth.items():
print(
f"{ticker}: {growth:.2%}"
if growth is not None
else f"{ticker}: Data not available"
)
def use_stock_price_plotter():
"""
Uses StockPricePlotter to plot closing prices and moving averages for a
list of stock tickers.
Users input stock tickers and a date range. The function then plots the
closing prices and moving averages for the selected period for each ticker.
"""
tickers = input(
"Enter stock ticker(s) separated by commas for price plotting (e.g., AAPL, MSFT): "
).split(",")
start_date = input("Enter start date (YYYY-MM-DD): ")
end_date = input("Enter end date (YYYY-MM-DD): ")
plotter = StockPricePlotter([ticker.strip() for ticker in tickers])
plotter.plot_closing_prices(start_date, end_date)
plotter.plot_moving_averages(start_date, end_date)
def use_financial_metrics_plotter():
"""
Utilizes FinancialMetricsPlotter to create histograms of financial metrics
for a list of stock tickers.
After receiving a list of tickers from the user, this function plots
histograms for key financial metrics like market cap and PE ratio for each
ticker.
"""
tickers = input(
"Enter stock ticker(s) separated by commas for financial metrics plotting (e.g., AAPL, MSFT): "
).split(",")
plotter = FinancialMetricsPlotter([ticker.strip() for ticker in tickers])
plotter.plot_metrics()
def use_revenue_growth_plotter():
"""
Leverages RevenueGrowthPlotter to plot the revenue growth of a list of
stock tickers.
Users provide stock tickers, and the function visualizes the year-over-year
revenue growth for each ticker in a bar chart format.
"""
tickers = input(
"Enter stock ticker(s) separated by commas for revenue growth plotting (e.g., AAPL, MSFT): "
).split(",")
plotter = RevenueGrowthPlotter([ticker.strip() for ticker in tickers])
plotter.plot_revenue_growth()
def use_stock_volatility_plotter():
"""
Interacts with StockVolatilityPlotter to plot the rolling volatility of a
list of stock tickers.
Users enter stock tickers and a date range, and the function plots the
calculated rolling volatility for each ticker over the specified period.
"""
tickers = input(
"Enter stock ticker(s) separated by commas for volatility plotting (e.g., AAPL, MSFT): "
).split(",")
start_date = input("Enter start date (YYYY-MM-DD): ")
end_date = input("Enter end date (YYYY-MM-DD): ")
plotter = StockVolatilityPlotter([ticker.strip() for ticker in tickers])
plotter.plot_volatility(start_date, end_date)
def use_stock_exchange_performance_plotter():
"""
Uses StockExchangePerformancePlotter to compare and visualize the
performance of different stock indices.
Users input symbols of stock indices and a date range, and the function
plots the normalized closing prices of these indices for comparative
analysis.
"""
indices = input(
"Enter stock index symbols separated by commas (e.g., ^GSPC, ^DJI): "
).split(",")
start_date = input("Enter start date (YYYY-MM-DD): ")
end_date = input("Enter end date (YYYY-MM-DD): ")
plotter = StockExchangePerformancePlotter([index.strip() for index in indices])
plotter.plot_performance(start_date, end_date)
def use_current_prices_ticker_display():
"""
Utilizes CurrentPricesTickerDisplay to show a rolling display of current
stock prices for a list of tickers.
Users input stock tickers and a display interval, and the function
continuously displays the current prices of these stocks in a ticker-like
format.
"""
tickers = input(
"Enter stock ticker(s) separated by commas for current price display (e.g., AAPL, MSFT): "
).split(",")
interval = int(input("Enter display interval in seconds: "))
ticker_display = CurrentPricesTickerDisplay(
[ticker.strip() for ticker in tickers], interval
)
ticker_display.display_ticker()
def main():
"""
Main function to run the stock analysis application.
Presents a menu-driven interface for users to select various stock analysis
functionalities, including data fetching, plotting, and performance
visualization. The script runs in a loop until the user chooses to exit.
"""
while True:
print(
"\nStock Data Analysis Menu\n",
"1. Use Stock Data Fetcher\n",
"2. Use Stock Summary Fetcher\n",
"3. Use Financial Metrics Fetcher\n",
"4. Use Revenue Growth Fetcher\n",
"5. Use Stock Price Plotter\n",
"6. Use Financial Metrics Plotter\n",
"7. Use Revenue Growth Plotter\n",
"8. Use Stock Volatility Plotter\n",
"9. Use Stock Exchange Performance Plotter\n",
"10. Use Current Prices Ticker Display\n",
"0. Exit\n"
)
choice = input("Enter your choice: ")
if choice == "1":
use_stock_data_fetcher()
elif choice == "2":
use_stock_summary_fetcher()
elif choice == "3":
use_financial_metrics_fetcher()
elif choice == "4":
use_revenue_growth_fetcher()
elif choice == "5":
use_stock_price_plotter()
elif choice == "6":
use_financial_metrics_plotter()
elif choice == "7":
use_revenue_growth_plotter()
elif choice == "8":
use_stock_volatility_plotter()
elif choice == "9":
use_stock_exchange_performance_plotter()
elif choice == "10":
use_current_prices_ticker_display()
elif choice == "0":
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()