Using ChatGPT to create an AI model to predict share price

We asked ChatGPT to make us rich by giving us a script that can predict the market stock price, and this is how it went.

Rich Stock Market Prediction GPT

Many attempts have been made in the past by researchers attempting to predict the stock market prices using Machine Learning.


A notable success story is the use of the Long Short-Term Memory (LSTM) model by researchers at Stanford University. They trained the model on 20 years of data from the S&P 500. The LSTM model was able to predict the direction of the price movement with an accuracy of about 62%, which is significantly higher than the 50% expected from random guessing. This demonstrated that LSTM models could potentially be used to gain an edge in the stock market.

However, in recent years Transformer models can outperform LSTM. So, what will happen if we just ask ChatGPT to develop a python script that uses Transformers to predicts the stock market.

Well, we did exactly that.

VPN

Prompt: "Use Python and Tensorflow to write an ai model that can predict stock market prices using High, Low, open, close and volume. Close is the feature that will be predicted. The price data will be collected using yfinance python library. The model must use Transformers with attention Layers.” 

 ChatGPT Response: https://github.com/IICEL/transformers-spp/blob/main/model_attention.py

Let’s analyze the Model.

ChatGPT Model Generation Python code

As we see from the code ChatGPT tries to use Encoder/Decoder model with MultiHeadAttention layers.
It has also a look_back parameter which allows the model to look back X number of entries. However, the model doesn’t have any positional embeddings, which makes the MultiHeadAttention layers not very effective.
We choose “Citigroup” ticker (C) to predict the price. The reason for this choice is because Citi is one of the oldest companies and has a lot of historical Data. The model Achieves 1.8-2.2 Mean Square Error for predicting C close price.

VPN


This model is an "OK" model, but it is not going to make anyone rich. However, there are many areas for improvements. 
In general, it is much easier to predict the direction of the price movement rather than the exact price. Changing the problem from a regression problem to a binary classification problem should result in better accuracy.


Challenges For Stock market price predictions. 

Some of the challenges for predicting stock market prices are: 

  • High, Low, Open, Close and Volume might not be sufficient enough to predict accurately the stock market prices. 
  • Historical Data might not be sufficient to train a model. Citigroup has approximately 75000 data points.
  • Studies have shown that market sentiment plays a significant role in stock mark price movements. This makes sentiment analysis an important factor in predicting stock market prices.

VPN

Conclusion 

ChatGPT can be used to create AI models for stock market prediction. Even though ChatGPT models are not high accuracy, other LLMs that will be trained specifically develop such models would be able to design new state of the art ai models.

In our future posts we will explore using time2vec for positional embedding to improve performance of this model. We will implement Hyperparameter auto tuning. We will test Hugging Face Encoder/Decoder models.

Signup Now for our news letter to stay up to date with our future posts.

 


Comments

Post a Comment

Popular Posts