Silicon Valley Bank failed: Use ChatGPT to help us do some comparable analysis
"A Person Looking at a Stock News and Plotting a Stock Chart in Deep Thought". The "art" work is generated by the OpenAI Dall-e program (https://openai.com/product/dall-e-2) and later on re-configured with Power Point auto style. So, really from one A.I. to another A.I.
This blog is a bit longer and a bit more "technical" than the usual ones. That is because I do want to use this as an example in one of the classes I am teaching ("A.I. for FinTech"). So, there will be a bit of programming. But for those who just want a quick summary. Here is what we are about to show.
Some big financial news happened. We want to know if the company in the news has any comparable in terms of business model. So we use ChatGPT to help us find the comparable. Remember ChatGPT is quite good but it has only data up to 2020. But that is sufficient for what we want to do.
Then we want to ask ChatGPT again for help to see if we can ask it to write some simple programming code which can be used in a popular stock analysis platform to just to plot of some correlation. (We can actually do more than that in the stock analysis program like doing back testing.). (The stock analysis platform we use is called Trading View.)
Our objective is really just to see how much help we can get.
Our findings are that ChatGPT is really good in helping us with some specific discovery and quite useful in programming, especially on a programming language we don't use often.
Last week, the big news in the financial world is sudden collapse of the Silicon Valley Bank. Some good friends ask a number of questions. Obviously, we don’t have all the answers. But, one question from a friend really piqued our interests.
He said, “well what should we buy or sell on Monday?” Of course, that is an impossible question to ask. But, the underlying question is more interesting. So, we tried to work out a methodology, a simple one to just for fun. No trading, of course, is recommended. This is just a dumb engineer doing a dumb exercise.
Given that my friend is not familiar with the Silicon Valley Bank being in Asia most of his life and not in the tech space, the first question he asked would be:
“What other banks are like the Silicon Valley Banks?” Valid question indeed.
So, guess what we do, we go ahead and ask ChatGPT.
Here is the response from ChatGPT, clever as ever.
Hmm, the second question our friend ask was “how are those banks doing?”
Well, that is not an A.I. kind of question. We just go to the venerable Yahoo Finance page and show all the banks in the chart.
Yup, that is the one. Then, how are the other ones mentioned by ChatGPT?
Let’s take a look of some of these stock prices historically, last 5 days, last 3 months, and last 5 years.
Thoughts after seeing the chart:
Indeed, from a human visual perspectives, there are quite some trends amongst the few institutions.
What is of curiosity then is what are really their correlation?
There are a number of ways we can do this. One possibility is to use TradingView’s Pine script to do certain correlation analysis. (https://www.tradingview.com/)
Similar to what you can do at Yahoo Finance page, you can do a similar chart on Trading View.
We now want to do 2 things. (a) We will like do a Correlation Matrix (“heat map”), of the stocks above as a trial, and (b) We will like to use the Trading View Strategy function to “play” with, and check out through Backtesting.
Many of us would be a bit stuck by now. Trading View allows you to use a scripting language called Pine to call the stock prices and do analysis. But, the problem is that most of us may not have used Pine Script daily and may not be fully aware of the syntax and possibility.
So, again, let’s ask ChatGPT for help and see what can be done and what still need to be done.
Very politely, ChatGPT came back with the above response.
The code would be:
//@version=5 study(title=”Stock Correlation Plot”, shorttitle=”Corr Plot”, overlay=false)
// Define stocks s1 = input(title=”Stock 1", type=input.symbol, defval=”AAPL”) s2 = input(title=”Stock 2", type=input.symbol, defval=”GOOG”) s3 = input(title=”Stock 3", type=input.symbol, defval=”MSFT”) s4 = input(title=”Stock 4", type=input.symbol, defval=”AMZN”)
// Calculate correlations corr1 = correlation(close, security(s1, timeframe.period, close)) corr2 = correlation(close, security(s2, timeframe.period, close)) corr3 = correlation(close, security(s3, timeframe.period, close)) corr4 = correlation(close, security(s4, timeframe.period, close))
// Plot correlations plot(corr1, color=color.green, linewidth=2, title=symbol(s1) + “ Correlation”) plot(corr2, color=color.blue, linewidth=2, title=symbol(s2) + “ Correlation”) plot(corr3, color=color.orange, linewidth=2, title=symbol(s3) + “ Correlation”) plot(corr4, color=color.purple, linewidth=2, title=symbol(s4) + “ Correlation”)
We followed the above suggestions but have to make some changes:
a. In Version 5 of the Pine Script, there is no function called “Study”. Instead, we use the “Indicator” function.
b. In Pine Script, you cannot just get the correlation of a stock after defining it. You need to get the stock price in floating point. So, what you need is to add a line after defining the stock name:
symbolClose1 = request.security(s1, timeframe.period, close)
The final code is like this:
You can copy and paste from here:
indicator(title = “Stock Correleation Plot”, shorttitle = “Corr Plot”, overlay = false)
s1 = input.symbol(title = “Stock 1”, defval = “SVB”)
s2 = input.symbol(title = “Stock 2”, defval = “FRC”)
s3 = input.symbol(title = “Stock 3”, defval = “PACW”)
s4 = input.symbol(title = “Stock 4”, defval = “EWBC”)
symbolClose1 = request.security(s1, timeframe.period, close)
symbolClose2 = request.security(s2, timeframe.period, close)
corr1 = ta.correlation(symbolClose1,symbolClose2,15)
symbolClose3 = request.security(s3, timeframe.period, close)
symbolClose4 = request.security(s4, timeframe.period, close)
corr2 = ta.correlation(symbolClose1,symbolClose3,15)
corr3 = ta.correlation(symbolClose1,symbolClose4,15)
The bottom chart is the correlation between Silicon Valley Bank and the 3 other banks one by one.
We have used ChatGPT to help us gain some insights of what are the comparable.
We can use ChatGPT as a first pass to help us with the coding, but a bit of tweaking is required.
Disclaimer: this is really just an engineering example. We do not know for sure how those names as shown by ChatGPT are valid or not. Our correlation analysis is just a mathematical computation.