This project uses machine learning and financial modeling to analyze BMW stock data, predict future prices, and simulate investment strategies. It helps understand stock trends, optimize trading decisions, and evaluate how a portfolio would perform over time. π View the Project Here:GitHub Link
Why Does This Project Matter?
This project helps investors and traders make smarter decisions by: β Using AI to predict stock trends instead of guessing. β Testing different investment strategies before putting in real money. β Finding the best stock allocations to maximize profits while reducing risk.
How It Works
Understanding the Data
The program starts by loading historical stock price data for BMW and preparing it for analysis:
Rolling Averages: Calculates the 50-day and 200-day moving averages, which smooth out price fluctuations and show trends.
A moving average (MA) is a way to track stock prices over time by calculating the average price over a set number of days. It helps investors see if a stock is going up or down without getting distracted by daily price changes.
50-Day Moving Average: Shows the average price of BMW stock over the last 50 days.
Short-Term Trend: Reacts quickly to price changes.
Helps traders decide when to buy or sell in the short term.
200-Day Moving Average: Shows the average price over the last 200 days.
Long-Term Trend: Moves slower but gives a bigger picture of the stockβs long-term trend.
Helps investors understand if BMWβs stock is growing or falling over time.
Lag Features: Introduces a time delay in the dataset, allowing the model to learn from previous price movements.
The model can understand how stock prices change over time and use that knowledge for predictions.
Scaling: Uses MinMaxScaler (tool used in machine learning) to normalize data, ensuring better performance by keeping all values in the same range.
BMW stock might be $100, but another stock might be $1,500. A machine learning model might get confused by these big numbers, so Min-Max Scaler shrinks all numbers to a small, fixed range (0 to 1), so the model can understand them better.
Predicting Stock Prices
To forecast BMWβs future stock prices, the program uses three types of models, each with a unique approach:
Linear Regression
A model that finds patterns in past prices and predicts future values.
It assumes that price changes follow a straight-line trend.
ARIMA (AutoRegressive Integrated Moving Average)
A statistical method that analyzes patterns in time series data (BMW stock prices over time).
It learns from past trends, cycles, and seasonality to make predictions.
Uses Statsmodels (Python library used for statistics and data analysis) for implementation.
LSTM (Long Short-Term Memory)
A neural network-based model that excels at time series forecasting.
Unlike traditional models, LSTM can remember past stock price trends and patterns to make smarter predictions.
Implemented using TensorFlow/Keras.
Both are models that can recognize patterns, make predictions, and learn from data. Keras is a simpler tool built inside TensorFlow. For example, TensorFlow is the car engine and Keras is the steering wheel that makes it easy to drive.
These models provide different insights into future price movements, allowing us to compare their accuracy and reliability.
Simulating Stock Trading
Once stock price predictions are generated, the program simulates real-world trading:
It buys stocks when prices are expected to rise and sells when prices are expected to fall.
The program starts with an initial cash investment and tracks how the portfolio grows over time.
It evaluates different buy-and-sell strategies to determine which would have been the most profitable.