Using ChatGPT to analyze stock market trading strategies

Using ChatGPT to analyze stock market trading strategies

Duong Dat Thanh

Using ChatGPT to analyze stock market trading strategies

ChatGPT is one of the latest technological breakthroughs in the artificial intelligence space. It can potentially be used in trading. Its ability to process and analyze large amounts of data, and generate human-like responses can be applied to areas such as market analysis, trade execution, and risk management.

Using ChatGPT to analyze stock market trading strategies

Origin of ChatGPT

An artificial intelligence (AI) chatbot that can comprehend and reply to a discussion in a highly human-like manner is called ChatGPT, also known as Chat Generative Pre-trained Transformer. It is developed by a San Francisco-based start-up organization named OpenAI that specializes in artificial intelligence. It was introduced in late November 2022, and since then, everyone has been talking about it. It swept the internet with its thorough responses and ability to clearly express solutions across a wide range of subject areas. 

Similar to numerous other chatbots now in use, ChatGPT was trained using a substantial quantity of online material providing huge data, such as e-books, journals, and Wikipedia. When ChatGPT processes more user answers, it gets better and better at forecasting the next words because it is always learning. Therefore, as result, the output generated becomes more realistic, logical and natural.

"ChatGPT is terrifyingly excellent. Elon Musk, was one of the founders of OpenAI prior to his leave, remarked that the powerful AI was dangerously not far away. OpenAI's CEO, Sam Altman, announced on Twitter that ChatGPT had more than 1 million users in the first five days of its inception. Although Altman conceded that it will ultimately need to be monetized because of its "eye-watering" computing costs, Musk was told that the average cost per response was in the "single-digits cents". ChatGPT is the app with the fastest growth ever, according to studies from the Swiss bank UBS. Comparatively, TikTok reached 100 million users within nine months.

How does ChatGPT impact stock analysis?

By enhancing their exposure to AI-driven companies, investors can guarantee their portfolios are ready for this new unforeseen occurrence. Now, ChatGPT could have a significant impact on your equity securities. It's plausible that by 2030, a higher portion of the S&P 500's market capitalization will be formed by companies using AI.

For investors who are interested in the US IT business, 200–300 US-listed companies are available which specialize in AI or similar technologies, such as the Internet of Things (IoT), 5G, cyber security, Blockchain, Metaverse, etc. From this pool of stocks, you should choose a portfolio of 15–25 companies based on their financial health, growth potential, and price using a process analogous to a scientific investing methodology.

ChatGPT Stock Market Forecast

Although ChatGPT is disputed, it is the first wide range of applications using (and publicly accessible) technology that might aid the typical stock market investor in gathering information and developing a broad understanding of the stock markets. While there are AI stock predicting tools available, this app has much well beyond.


After all, a database of technical trading activities (data) is not the entirety of what the stock market (Dow Jones, S&P, and NASDAQ) is, rather it is an average appraisal of all investors in these markets.


The ChatGPT app may be a valuable resource of data for sophisticated investment decisions when used in conjunction with AI stock market analysis tools. Its capabilities for complete stock trading and emotion input will undoubtedly be improved, as developers no doubt have plans to enhance it. Microsoft might not view it as a top priority, thus private businesses are probably the ones who are presenting this chance. That may lead to the creation of brand-new, highly lucrative AI stock price predicting services.


One business that stands to gain from the hype surrounding ChatGPT is Experts aren't very enthusiastic about the firm, but in January, speculators bid it up. The detailed piece about AI stocks will be written in another blog.  

Source: Gord, Collins (2023)  

How to use ChatGPT for Trading - Build a Trading Algorithms


The model must first be accessed through an API or by using OpenAI's GPT-3 Playground before ChatGPT can be used to produce options trading scripts. Find that link here: 


To thoroughly automate your trading process and make the most of the trading algorithm, you'll need to become knowledgeable with a brokerage that accepts direct script plug-ins into their user interface.


You may test the script using historical market data and make any required tweaks before using it in actual trading after you have access to the model and are familiar with your preferred brokerage. To shed some insight on the procedure, let's examine a few sample scripts and trading algorithms that as follow:

This is the simple example that I wrote to get the signal code from Chatbot GPT. 

In this example, the program reads data from a CSV file and uses the rolling() method to generate and calculate the EMA20 and EMA50 values.Then, if an intersection between the 2 EMAs is discovered, it examines the signal and creates an alert. Ultimately, in order to show the junction visually, it plots the data with the EMAs overlay.  


Let's now discuss a more sophisticated strategy that ChatGPT is already used to assist traders, dealers or investors in obtaining important code.

QQQ Strategy: Bullish When the RSI is Oversold


When a security or stock is oversold or overbought, and by how much, the relative strength indicator, often known as RSI for short, tries to show this. According to a straightforward rule for interpreting RSI when RSI metric is less than 30, a security is oversold and more probable to bounce.  In light of this, let's create a rudimentary script that accomplishes this with at-the-money options as the instrument and QQQ as the objective.

A Python script that could be integrated right into a brokerage to automatically execute trades when the RSI matches the specified parameters. According to TrendSpider, when this approach was back tested on SPY utilizing the 15-minute period,  this strategy brought a 66% win rate.  

See the figure 1 below for strategy illustration.


Figure 1: RSI indicator computation to buy QQQ calls request applied for ChatGPT

Source: Justin, Nugent (2023)

SPY Strategy: MACD Crossover With Confirmation from Bollinger Band 

Whilst the strategy's headline may make it sound complicated, it is actually rather straightforward. Two separate moving averages are compared to one another to create the MACD indicator, which stands for moving average convergence divergence. The MACD looks like this:



Source: TradingView


In view of this, let's request that ChatGPT sketch out a nuanced MACD technique using Bollinger Bands, another indicator, as a confirmation.


Please see the figure 2 below.


It can be a bit of a challenge to look for these possibilities and seize them right away for those of us who comprehend and are willing to trade intricate techniques like this. This script could theoretically be set up on several high-liquidity tickets using ChatGPT, much like putting up hunting traps.


Importantly, certain strategies still necessitate a human touch. They are areas where ChatGPT hasn't yet achieved success.


For instance, ChatGPT may be requested to develop a strategy that searches for trend reversals with 100% average volume, but ChatGPT still doesn't grasp the subtleties of reversal candles and technical patterns (even if theoretically you could define such things).


Figure 2: MACD Strategy Request applied in ChatGPT

ChatGPT for backtesting a trading strategy


Simulating the performance of trading strategy using historical data play significantly to assess its potential profitability in the work of backtesting a trading strategy. Before risking actual money, this technique enables traders to assess a strategy's efficacy and make necessary modifications.


The methods taken to backtest a trading strategy are described in this high-level overview. It's essential to keep in mind that backtesting is an intricate process that calls for expertise in programming and financial data analysis.


Let's request that ChatGPT establish Python code so that we can backtest a mean reversion trading strategy for AAPL


Prompt: Write Python code to backtest an AAPL trading mean reversion strategy




Here is a simple illustration of how to backtest a mean reversion strategy in Python for trading Apple shares (AAPL):



Source: Varun, P. 2023




Source: Varun, P. 2023

Source: Varun, P. 2023


A fundamental mean reversion strategy is implemented by this code, which buys when the stock's price is under the lower Bollinger Band and sells when the stock price exceeds the higher Bollinger Band. The final return on investment is computed while keeping track of the investment balance and the number of shares owned.

The fact that this is only an example and not intended to be a fully working or optimized backtesting script should be emphasized. The difficult process of backtesting necessitates programming and financial data analytic abilities.

What are some of the most effective trading strategies implemented with ChatGPT?

Using ChatGPT for financial exchange trading offers a number of possible benefits, such as:


  • Enhanced efficiency: By offering automated responses for usual queries, ChatGPT can help traders avoid time-consuming. As a result, they may concentrate on duties that are more crucial, like scrutinizing market data and making decisions on its own.
  • Increased precision: ChatGPT has the ability to generate precise conversations that are tailored to each user's interests and preferences by applying deep learning algorithms. This aids traders in making decisions that are based on trustworthy information.
  • Intuitiveness: Using ChatGPT for trading helps remove emotion


Cons Of Using ChatGPT For Trading


ChatGPT has the potential to be a potent tool for deriving insights from unorganized financial market data, formulating forecasts, and coding technical methods, but it also carries the following risks:


  • Bugs may exist in codes: Even when ChatGPT generated programs do execute, they could do so incorrectly and provide erroneous signals because they contain bugs that prohibit them from executing. To correct them, you must be familiar with the coding language. If you can't code, fixing ChatGPT won't be simple.
  • Over-reliance on model predictions: The forecasts provided by ChatGPT shouldn't be your sole source of information. Biases in the training data can have an impact on models and cause errors. Constantly verify them against other sources and techniques. When executing the test on it, the code was frequently incorrect.
  • Data security concerns As with any technology that involves collecting and analyzing user data, there can be a heightened risk of data breaches or misuse when ChatGPT is used.
  • Lack of interpretability: It may be challenging to comprehend ChatGPT's reasoning behind a particular hypothesis in the case of sentiment analysis. The trader wouldn't be aware if a certain prediction was supported on erroneous presumptions..
  • Lack of market knowledge: ChatGPT is unable to comprehend the dynamics of the market or the intricate relationships between many market-affecting aspects. To use the insights and forecasts produced by ChatGPT successfully, traders must have a solid grasp of the market.



In general, ChatGPT is an innovative technology that could significantly assist users with their analysis and decision-making which is currently taking the world by storm. In this blog, we went through the use of AI ChatGPT which can support users to create technical indicators, trading strategies based on specified indicators, and even trading algos, as well as offer sentiment analysis and prediction models that can help investors make better trading decisions.   

The possible drawbacks of employing ChatGPT, such as data security issues or the dangers of relying too much on automated algorithms, should also be taken into account when selecting if to adopt this technology as the sole tool to aim at beating the stock market.


Thank you for reading. Despite there is remaining knowledge treasure that needs to be dug deep to get the benefit of leveraging ChatGPT to beat the market, hopefully, this insight provided would be a helpful reference for you to understand the potential benefit of this AI tool. Any recommendation or suggested discussion if needed, feel free to contact me: [email protected]. We can have a great discussion on this alluring topic.


Related articles

Introduction to Web 3.0


03 Apr 2023


13 mins read

Cost-Benefit Analysis Execution


21 Mar 2023


12 mins read


Ho Chi Minh (Headquater)


2nd & 3rd Floor, M.I.D Building, 02 Nguyen The Loc Street, Ward 12 Tan Binh District, Ho Chi Minh City, Vietnam Protection Status

Quick Links

Opening Jobs

About us

Life at saigontechnology


Contact Us


Follow Us


© Copyright 2022 by STS Software Technology JSC, Leading Software Outsourcing Company in Vietnam. All Rights Reserved.