How to Build a Custom AI Assistant to Analyze Stock Market Data
The Assistants feature in OpenAI simplifies the process of building your own custom AI agent. Your AI assistant will have access to the latest GPT models, a code interpreter, and any additional instructions or knowledge you provide.
In this article, we will guide you through creating a simple custom AI assistant that can analyze and calculate data from stock market reports in PDF form, sourced from Yahoo Finance. You’ll learn how to pose any question and receive detailed analyses and calculations directly from your custom assistant.
Let’s begin.
First, ensure you have an OpenAI account. This is necessary to access the assistant creation tools. Once ready, go to platform.openai.com/assistants and click on the “Create” button.
Next, provide a name for your assistant and enter the instructions you want it to follow.
In this tutorial, we will build an assistant that helps us answer questions about Apple’s stock price.
Next, you can choose the Language Learning Model (LLM) that suits your needs. These models are available on a pay-as-you-go basis, allowing you to select the best fit for your budget and requirements. I will be using gpt-4-turbo for this example.
After setting everything up, you can test your assistant. Go to the right-hand panel, enter any question or message for your assistant, and then click “Run“.
For instance, I asked the assistant, “What is Apple’s stock opening price on 18th of June 2024?” Unfortunately, it couldn’t provide a useful answer because we had not yet uploaded the necessary data for it to use. Let’s get that fixed.
If you want your assistant to be more effective than just using ChatGPT, you should consider adding custom data or knowledge specific to your application. This could be a text file, a PDF, or even a CSV table containing data not typically accessible to ChatGPT by default.
For our project, I’ve downloaded historical stock price data for Apple from Yahoo Finance. This dataset includes opening, high, low, and closing prices from June 24, 2023, to June 24, 2024, and will serve as our custom knowledge source.
If you are following this tutorial and want to download the same data, visit this page and click the “Download” button. Feel free to use any data you prefer if you have different requirements.
To add this to your assistant, navigate to the “Tools” section, activate “File Search“, and then click “+ Files“.
Upload the file, and once it’s uploaded, click “Attach“.
Let’s test our assistant again to see if it can now access our data. I’m going to ask it the same question again and make sure to click the down arrow on the “Run” button and select “Require tool call“.
This time, the response is much more informative. It provided me with Apple’s stock opening price on June 18, 2024, retrieved from the file I uploaded earlier.
If you look at the response, you’ll notice a small numbered annotation. Hovering over this annotation will show you a snippet of the data source from where the information was retrieved.
As you can see, the assistant performs well with our data, delivering accurate information through a user-friendly interface.
Now, you can ask more complex questions to save time. For instance, I asked it to find out which day in 2023 Apple had the highest opening price.
Alternatively, you can ask it to provide a list of the highest opening prices throughout 2023.
With the provided data, you can ask all sorts of technical questions, enabling the assistant to sort and calculate information quickly, saving you considerable time compared to manual calculations.