Skip to content

This repository implements a Hidden Markov Model (HMM) to model stock price movements

License

Notifications You must be signed in to change notification settings

Bratet/Stock-Prediction-Using-Hidden-Markov-Chains

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hidden Markov Model for Stock Price Movements

This project implements a Hidden Markov Model (HMM) to model stock price movements. The model is trained using the Baum-Welch algorithm and makes predictions using the Viterbi algorithm. The model predicts whether the stock price will rise or fall in the following trading day.

Overview

This project uses the Yahoo Finance API to retrieve historical stock prices for a given company. The prices are transformed into a binary format where a 1 represents an increase in price from the previous day, and a 0 represents a decrease.

The Hidden Markov Model is then trained on this sequence of binary values. Once the model is trained, it can be used to predict future price movements.

Dataset

The project retrieves stock price data from the Yahoo Finance API. The user can specify the company symbol (for example, "AAPL" for Apple Inc.), and the date range for the historical data.

Libraries Used

  • numpy
  • tqdm
  • yfinance
  • matplotlib

Usage

To train the model, run the following command:

python main.py

After training the model, you can use it to predict future price movements:

python predict.py

Results

The model's accuracy is evaluated by comparing the predicted price movements with the actual price movements in a test dataset.

About

This repository implements a Hidden Markov Model (HMM) to model stock price movements

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published