Stock market signals with Chat GPT 4
This is my third use case for how to do quantitative analysis with Chat GPT 4. The two others, on Eurozone inflation and times series regression with macro data, can be found here and here. I started in the industry as Head of Research for Variant Perception, a research shop that specialises, among other things, in quantitative trading models, asset allocation tools, and trade signalling analysis. One tool that came up again and again in my analyses was binary signals to identify turning points in asset classes, stocks or economic data series. The idea is simple. First, you create a binary indicator which takes the value of 1, if a certain threshold in the data is breached to the upside or downside, and zero otherwise. Secondly, you investigate what happens after such a signal has gone off, either in the original data set or mapped to a separate data set. You can combine signals across datasets to get a rolling series of signals, which can be compared to asset prices or economic data. You can see an example of such an analysis with the Nasdaq here.
In the following I perform such an analysis with Chat GPT 4 on Microsoft’s stock price, attempting to identify what happens to the price of Microsoft’s common equity in periods after the trailing six-month total return has exceeded 35%. The full output of the (final) GPT analysis is shown below my summary of the exercise.
This analysis shows why you have to be very careful about how the GPT reads trending time series, such as a nominal stock price or a level economic data series, and as a result, how it calculates changes in such series. In the first iterations of the analysis, where I tried to get the GPT to calculate the outcome on Microsoft’s stocks after a binary signal, I got nonsensical results. I got the same nonsensical results when calculating simple summary statistics on the change in the Microsoft stock price. I eventually figured out that it was because the GPT was reading the series in reverse, for the purpose of its calculations, despite plotting the series correctly in a chart. I solved this, by specifically telling the GPT that the data was uploaded with an ascending date column—newest date first—and re-trained the GPT to always ask the analyst how the date column is set up. In summary; know your data and question the GPT’s analysis. Garbage in-garbage out still applies.
The binary indicator itself was very easy to create and plot, and much faster than I would have been able to do in Excel or in a similar software. I did four iterations of this analysis before getting the final outcome right, and in all four cases, the GPT got the binary indicator correct the first time.
Asking the relatively simple question of what the average outcome is, in this case for Microsoft’s stock price, conditional on a binary signal having gone off is not as straightforward as it seems. I initially asked the GPT for the average return, over various horizons, after the signal had gone off, but I didn’t like the results. Specifically, I couldn’t replicate the GPT’s calculations. In the end, I figured out that this was because the GPT wasn’t calculating what I was asking it do, primarily because I wasn’t prompting it correctly and specifically enough. For example, specifying what you mean by the indicator “having gone on or off” is crucial in itself. The lesson here is that while it is relatively simple to get the GPT to insert binary threshold indicators in a time series, the change in said series conditional on these indicators has to be very specifically and accurately specified to the GPT.
Microsoft trading signal GPT 4 output
Anonymous
This is weekly data of the six-month total return of Microsoft's common equity and Microsoft's stock price. The date column "date" is in ascending order with the most recent date (31/12/2023) first.
AS Time Series and Forecast GPT
The dataset contains three columns:
date
- Representing the date of the data point, in ascending order with the most recent date (31/12/2023) first.six_month_tr
- The six-month total return of Microsoft's common equity.price
- The stock price of Microsoft.
To proceed with the analysis, could you please specify the type of time series analysis or forecast model you would like me to perform on this data? For example, do you want to forecast future stock prices or total returns based on this data, or analyze the relationship between these variables? Additionally, if you have a specific time frame or number of periods for the forecast, please let me know.
Anonymous
Can you provide summary statistics for the total return and the price
AS Time Series and Forecast GPT
The summary statistics for the six-month total return and the stock price of Microsoft are as follows:
Six-Month Total Return (six_month_tr
):
Count: 523 observations
Mean: 0.1505 (average total return)
Standard Deviation: 0.1291 (indicating variability in total returns)
Minimum: -0.2144 (lowest recorded total return)
25th Percentile: 0.0705
Median (50th Percentile): 0.1619
75th Percentile: 0.2358
Maximum: 0.5087 (highest recorded total return)
Stock Price (price
):
Count: 523 observations
Mean: $144.73 (average stock price)
Standard Deviation: $102.83 (indicating variability in stock prices)
Minimum: $30.35 (lowest recorded stock price)
25th Percentile: $49.58
Median (50th Percentile): $103.60
75th Percentile: $239.21
Maximum: $377.43 (highest recorded stock price)
These statistics provide a comprehensive overview of the data, highlighting the central tendency and dispersion of both the total returns and the stock prices over the observed period.
Anonymous
I would now like you create a binary indicator taking the value of 1 if the total return is above 35% and zero other wise. Can you plot this indicator in a chart with the total return, on a separate y-axis, and in a chart with the price, on a separate y-axis.
AS Time Series and Forecast GPT
The charts have been created as requested:
The first chart displays the six-month total return of Microsoft's equity (in blue) along with the binary indicator (in red). The binary indicator takes the value of 1 when the total return is above 35% and 0 otherwise. This chart has two y-axes: one for the total return and another for the binary indicator.
The second chart presents Microsoft's stock price (in green) alongside the same binary indicator (in red). Similar to the first chart, it features two y-axes, one for the stock price and the other for the binary indicator.
These charts visually represent the periods when the total return exceeded 35% in relation to the trends in total return and stock price.
Anonymous
I would then like to calculate the percentage change in the price of Microsoft at the point at which the indicator goes off, after having been activated, and the price three month later. You should get more than one of these observations. Can you list all these percentage changes and their dates?
AS Time Series and Forecast GPT
It appears that there are no instances in the dataset where the binary indicator turns off (from 1 to 0) and then has a corresponding stock price available three months later. This result suggests that either the indicator does not turn off during the covered period or that there is insufficient data following an indicator-off event to calculate the percentage change in price three months later.
If you have additional data or specific requirements for this analysis, please let me know, and I can re-evaluate the calculations accordingly.
Anonymous
Let's try to calculate the percentage change in the price of Microsoft at the point at which the indicator goes off, and the price three month later. You should get more than one of these observations. Can you list all these percentage changes and their dates?
AS Time Series and Forecast GPT
Here are the instances where the binary indicator for Microsoft's six-month total return turned off (from 1 to 0) and the corresponding percentage change in the stock price three months later, along with their dates:
Date: 2023-05-13, Percentage Change: -14.68%
Date: 2021-07-02, Percentage Change: -8.02%
Date: 2021-04-29, Percentage Change: -16.49%
Date: 2021-03-04, Percentage Change: -6.40%
Date: 2019-07-13, Percentage Change: -14.55%
Date: 2018-12-01, Percentage Change: -5.28%
Date: 2018-11-07, Percentage Change: -10.83%
Date: 2018-10-22, Percentage Change: -11.95%
Date: 2017-12-22, Percentage Change: -14.03%
Date: 2017-10-27, Percentage Change: -9.96%
Date: 2015-12-09, Percentage Change: -8.24%
Date: 2013-07-12, Percentage Change: -8.56%
These dates and percentage changes indicate the performance of the stock three months after periods when the six-month total return dropped below the 35% threshold.
Anonymous
What is the average of these observations?
AS Time Series and Forecast GPT
The average percentage change in Microsoft's stock price, measured three months after the instances where the binary indicator for the six-month total return turned off, is approximately -10.75%. This indicates that on average, the stock price decreased by about 10.75% in these instances, three months after the indicator turned off.
Anonymous
Can you perform the same analysis for one month and six months?
AS Time Series and Forecast GPT
The average percentage changes in Microsoft's stock price for one month and six months after the binary indicator for the six-month total return turned off are as follows:
One Month Later: The average percentage change is approximately -4.79%. This indicates that, on average, the stock price decreased by about 4.79% one month after the indicator turned off.
Six Months Later: The average percentage change is approximately -20.22%. This suggests that, on average, the stock price decreased by about 20.22% six months after the indicator turned off.
These averages provide insights into the stock's performance over different time periods following a downturn in the six-month total return.
Anonymous
Fantastic, this was very helpful. We managed to get to a good analysis in the end.
AS Time Series and Forecast GPT
I'm glad to hear that you found the analysis helpful! If you have any more questions in the future, whether it's related to time series analysis, financial data, or any other topic, feel free to reach out. Have a great day!