AI Stock Researcher Powered by GPT-3

Auto-generate stock fundamental analysis from simple natural language inputs by leveraging the world’s most advanced language model.

Shubham Saboo
Analytics Vidhya
6 min readMar 31, 2021

--

“The most difficult thing is the decision to act, the rest is merely tenacity.” → Amelia Earhart

Pre-Requisites

I have collected the dots in the form of articles, please go through the below articles in the same order to connect the dots and understand the key tech stack behind AI-Stock Researcher- an application powered by GPT-3:

  1. FastAPI — The Spiffy Way Beyond Flask!
  2. Streamlit — Revolutionizing Data App Creation
  3. A Brief Introduction to GPT-3

Fundamental Stock Analysis

Fundamental analysis attempts to assess a stock’s intrinsic value by considering a broad range of factors from the overall economy in relation to industry performance and a company’s financial factors such as earnings, profit margin, assets, and liabilities. Price movement history and volume are rather insignificant to fundamental analysts.

The basic principle behind the design for all sorts of stock analysis is to determine whether a security is correctly valued within the broader market. Fundamental analysis is typically done from a macro to micro perspective keeping in mind the very fundamental values on which the company is built to identify long-term opportunities and returns.

Technical Analysis at its best... [Image credit: Scoopnest]

The end goal of any fundamental stock analysis is to reach a conclusion with clearly-stated key points outlining the gap between the “company’s true value” and the perception of “its value” by the investors. This will help the potential investors to identify if the security is undervalued or overvalued with regards to its fundamentals.

Why GPT-3 is good Candidate?

Fundamental analysis of publicly listed companies that goes through millions and millions of transactions through stock exchanges is a really tough task, it is not a structured number of steps that need to be taken to come up with a conclusive study. Every company is unique in terms of its fundamental values and culture, every chart its own mission and vision and try sticking to that.

Now, according to the very popular Efficient Market Hypothesis (EHA), the market value of any company at a given time is reflective of all the information that’s out there in the universe. Considering that is the case, then it will impossible for both the individual and the institutional investors to consistently generate alpha (α).

`Efficient Markets Hypothesis states that the prices of traded assets take into account all available information. Certainly, that’s the case here…

How do all these dots connect to GPT-3?

The financial markets have never been easy to analyze, there is always an element of surprise that you fail to anticipate. There has been a lot of research going on for years in the area of Artificial Intelligence and Machine Learning to predict market movements. But to date, we don't have any sophisticated technology to analyze and predict the market future because of the sheer number of attributes involved and their respective heterogeneity. Anything ranging from a company’s financials, market performance, brand image to some small news leak can lead to a drastic shift in the company’s value as perceived by the market.

“To understand the market’s deception, go to the fundamentals.” → Fundamental Stock Analysis

Traditional machine learning and deep learning algorithms have been proven inefficient for this task due to the universe of unexpected data that can influence the results. The knowledge of conventional machine learning models is limited to the training corpus, anything that’s out of it will be considered as outliers and will severely hinder the model performance.

GPT-3 on the other is trained on the universe of data called → “the internet”, with a great tendency to precisely recall the patterns in the data (thanks to 175 billions+ parameters). Whatever the source and type of data are, GPT-3 as a language model is well adapted to that level of generalization to come up with nearly accurate results because of its eccentric and unique training.

Application walkthrough

Now I will walk you through the AI-Stock Researcher application step by step:

While creating any GPT-3 application the first and foremost thing to consider is the design and content of the training prompt. Prompt design is the most significant process in priming the GPT-3 model to give a favorable and contextual response.

As a rule of thumb while designing the training prompt you should aim towards getting a zero shot response from the model, if that isn’t possible move forward with few examples rather than providing it with an entire corpus. The standard flow for training prompt design should look like: Zero Shot → Few Shots →Corpus based Priming.

In order to design the training prompt for the AI-Stock Researchers application, I have used the following training prompt structure:

  • Description: An initial description of the context about what the stock researcher is supposed to do by adding a line or two about its functionality.
  • Input (Company Name): This component includes the name of the company which will be provided as input by the user. It helps GPT-3 to set up the context for fetching the right information.
  • Output: This component includes the fundamental analysis report corresponding to the company name provided as an input to the GPT-3 model.

I/p→ Company Name; O/p→ Fundamental Analysis Report

Streamlit powered UI → All in Python!
The magic of FastAPI → On-the-fly API documentation

Let’s see an example in action, to truly understand the power of GPT-3 in acting as an intelligent fundamental stock researcher. In the below example, we will generate the stock fundamental analysis by providing just the company name to our AI Stock Researcher.

Conclusion

GPT-3 is designed by keeping the tech as well as the non-tech audience in mind, it doesn’t require complex gradient fine-tuning or updates, and the interface design is straightforward and intuitive that can be easily used by anyone with little to no prerequisites. It is highly flexible in terms of performing a number of NLP tasks, providing you with the ability to just do anything that you can imagine with natural language. This unique characteristic of GPT-3 is what makes it stand out from other NLP models. Many startups and enterprises around the world are experimenting with GPT-3 to come up with a new generation of products to cater to the audience of the 21'st century.

References

  1. https://en.wikipedia.org/wiki/GPT-3
  2. https://openai.com/blog/openai-api
  3. https://ir.lib.uwo.ca/cgi/viewcontent.cgi?article=8423&context=etd
  4. https://upcommons.upc.edu/bitstream/handle/2117/133070/138115.pdf

If you would like to learn more or want to me write more on this subject, feel free to reach out.

My social links: LinkedIn| Twitter | Github

If you liked this post or found it helpful, please take a minute to press the clap button, it increases the post visibility for other medium users.

--

--