The main.py script serves as the entry point for a stock analysis application, leveraging the functionality provided by the fetcher and plotter classes from the src package. The script provides a user-friendly, menu-driven interface for interacting with various stock analysis tools. Here's an overview of how the classes are utilized within this script:
-
Fetching and Displaying Stock Data: The script uses classes like
StockDataFetcher,StockSummaryFetcher,FinancialMetricsFetcher, andRevenueGrowthFetcherto fetch different types of stock data. It provides functions to display historical data, financial metrics, stock summaries, and revenue growth for specified stock tickers. -
Plotting Stock Data: For data visualization, the script incorporates
StockPricePlotter,FinancialMetricsPlotter,RevenueGrowthPlotter,StockVolatilityPlotter, andStockExchangePerformancePlotter. These plotters generate various plots, including closing prices, moving averages, financial metrics histograms, revenue growth bar charts, rolling volatility, and comparative performance of stock indices. -
Real-time Price Display: Using
CurrentPricesTickerDisplay, the script can show a dynamic, rolling display of current stock prices in a ticker-like format.
-
User Input: The script prompts users to enter stock tickers, date ranges, and other parameters as required by the different functionalities.
-
Functional Modularization: Each major functionality (fetching data, plotting, real-time display) is encapsulated in separate functions within
main.py, such asuse_stock_data_fetcher(),use_stock_price_plotter(), anduse_current_prices_ticker_display(). This modular approach enhances readability and maintainability. -
Loop-driven Menu: The script runs a loop that displays a menu of options. Users can select an option by entering the corresponding number. The loop continues until the user chooses to exit.
-
Error Handling: While the detailed implementation of error handling is not shown, it's essential for practical applications to include error handling, especially for user inputs and network requests (for fetching data).
- A user runs
main.pyand is presented with a menu of stock analysis options. - The user chooses an option by entering a number, for example,
5for usingStockPricePlotter. - The script then asks for further input, such as stock tickers and a date range.
- Based on the input,
StockPricePlotteris instantiated, and the requested plots are generated and displayed. - After completing the action, the menu is presented again, allowing the user to select another option or exit the application.
flowchart LR
A(Start Application) --> B{Main Menu}
B --> C[Exit Application]
B --> D[Data Fetching and Display]
B --> E[Data Plotting]
B --> F[Real-time Price Display]
D --> D1[Stock Data Fetcher]
D --> D2[Stock Summary Fetcher]
D --> D3[Financial Metrics Fetcher]
D --> D4[Revenue Growth Fetcher]
E --> E1[Stock Price Plotter]
E --> E2[Financial Metrics Plotter]
E --> E3[Revenue Growth Plotter]
E --> E4[Stock Volatility Plotter]
E --> E5[Stock Exchange Performance Plotter]
F --> F1[Current Prices Ticker Display]
D1 --> B
D2 --> B
D3 --> B
D4 --> B
E1 --> B
E2 --> B
E3 --> B
E4 --> B
E5 --> B
F1 --> B
The design allows for easy addition of new functionalities. Developers can introduce new fetchers or plotters as classes and integrate them into main.py by adding corresponding functions and menu options.
This structure not only facilitates ease of use for end-users but also provides a clear framework for developers to extend the application with more features or data sources.