Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stock Price Trend Prediction using Linear Regression

This project is a simple demonstration of using a linear regression model to predict the general trend of a stock's price over time. It fetches daily stock data from Alpha Vantage, trains a model on the historical prices, and plots the resulting trendline against the actual prices.

This is an educational tool to visualize how a simple statistical model can capture the long-term trend in a time series dataset.

How It Works

  1. Data Fetching: The script connects to the Alpha Vantage API to retrieve daily historical stock data for a specific ticker (default is 'AAPL').
  2. Data Processing: It cleans and formats the data, keeping only the 'Close' price and ensuring the data is in chronological order.
  3. Feature Engineering: A simple 'TimeIndex' is created, which is a sequence of integers (0, 1, 2, ...). This index serves as the single feature (X) to predict the stock price (y). The model essentially learns the relationship Price = m * Day + c.
  4. Model Training: A LinearRegression model from scikit-learn is trained on the TimeIndex and Close price data.
  5. Visualization: The script uses matplotlib to plot both the actual closing prices and the predicted trendline from the linear regression model, providing a clear visual comparison.

Setup and Usage

Prerequisites

  • Python 3.x
  • An Alpha Vantage API Key

1. Clone the Repository

2. put in your api keys

3 run the python program

About

This project implements a basic trading strategy using Python and linear regression to predict stock price trends.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages