Predicting the Future: A Machine Learning Approach to BIST 30 Stock Prices
WHAT IS STOCK PRICE?
A stock price is the current price at which a share of a particular stock can be bought or sold in the market. It is determined by the supply and demand for that stock, which is influenced by various factors including the company’s financial health, investor sentiment, economic conditions, and market trends. Stock prices fluctuate throughout the trading day as investors buy and sell shares.
Introduction
The goal of this project is to build a web application that enables users to perform various types of financial data analysis and forecasting. The application is designed to handle stock market data, generate forecasts using linear regression and ARIMA models, and provide visual and sentiment analysis of news articles. This project integrates data analysis, machine learning, and data visualization to offer a robust tool for financial decision-making.
METHODOLOGY
- Streamlit: I used
Streamlit
to build the interactive web application. This tool enabled us to create a user-friendly interface for data analysis, visualization, and forecasting, allowing users to interact with the application effortlessly. - NumPy:
NumPy
was used for numerical computations and handling large arrays. It supported various mathematical operations and data transformations required for our analysis and forecasting models. - Pandas:
Pandas
was essential for data manipulation and analysis. It allowed us to clean, filter, and process financial data efficiently, as well as handle large datasets with ease. - Matplotlib: This library was used for creating static, interactive, and animated visualizations in Python. It helped me generate detailed charts and plots to visualize stock data, technical indicators, and forecast results.
- yfinance: I used
yfinance
to fetch historical stock price data directly from Yahoo Finance. This library simplified the process of obtaining and updating stock market data for analysis. - Statsmodels: This library was employed for statistical modeling and time series analysis. It provided the tools necessary for implementing ARIMA models for forecasting future stock prices based on historical data.
- OpenAI: I integrated OpenAI’s GPT-3 to enhance the application’s capabilities with advanced text generation and automated analysis. GPT-3 helped generate investment recommendations and interpret statistical data.
- Python-dotenv: This tool was used for managing environment variables and configuration settings securely, ensuring that sensitive information such as API keys and credentials remained protected.
Key Features of the Application
- Data Analysis:
- Data Loading and Display: The application allows users to load and view historical stock data. Users can apply filters to explore the data, such as highlighting maximum values and analyzing price statistics.
- Technical Indicators: Users can calculate and visualize various technical indicators like Moving Averages, MACD, RSI, and Bollinger Bands. These indicators provide insights into market trends and potential trading signals.
2. Forecasting Models:
- Linear Regression: The app provides a linear regression model to predict future stock prices based on historical data. Users can specify the number of days for forecasting and visualize predictions alongside actual historical prices.
- ARIMA Model: In this financial project, I used the ARIMA model to predict future stock prices. ARIMA is good for analyzing time series data like stock prices because it looks at past trends to make future predictions. It helps in understanding and forecasting stock price changes, making it a useful tool for investment decisions.
3. Reporting:
- Basic Reporting: The application generates key statistical reports such as average, median, and standard deviation of stock prices. It also includes visualizations like time series plots, histograms, and box plots to help users understand the data distribution and trends.
- GPT-3 Enhanced Analysis: By integrating OpenAI’s GPT-3, the application provides automated textual analysis and investment recommendations based on the statistical data. This feature offers users a concise, AI-driven perspective on their financial data.
Implementation Details
Streamlit Setup: The Streamlit app is set up with a wide layout for a better visual experience. Custom CSS is used to style both the sidebar and main content, aligning them with the financial theme of the application.
Data Analysis Component: This part of the app utilizes Plotly for creating interactive charts and pandas for managing data. It allows users to select stocks, view historical data, and apply various technical indicators for a thorough analysis.
Forecasting Models: Linear regression and ARIMA models are implemented using Scikit-learn and Statsmodels, respectively. The app enables users to choose a stock, set forecast parameters, and visualize future price predictions.
Reporting: In the project, ChatGPT helps make detailed reports about stock prices by looking at past data. When users choose a stock, the app calculates key numbers like the average price and how much prices go up and down. ChatGPT then uses this info to give advice on whether to buy, hold, or sell the stock. This helps users make smart investment choices using AI.
Conclusion
This web app combines modern tools and techniques to provide a powerful and interactive platform for financial analysis. By integrating data visualization, machine learning, and reporting, it offers valuable insights into stock market trends and investment opportunities.
Whether you’re a financial analyst, investor, or simply interested in stock trends, this app serves as a useful resource for understanding and predicting market behavior. The user-friendly design of Streamlit ensures that advanced financial analysis tools are readily accessible.
Explore the app, experiment with different stocks, and use the various features to enhance your financial decision-making process. Enjoy analyzing!
You can find the code for this project on GitHub
Thank you for reading..
ESRA KORKMAZ