Social Commerce

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 and click on the “Create” button.

Screenshot showing the Create button on OpenAI's platform

Next, provide a name for your assistant and enter the instructions you want it to follow.

Screenshot displaying the fields for naming and instructing a new AI assistant

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.

Screenshot showing the selection of LLM models on OpenAI's platform

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.

Screenshot showing the assistant's inability to answer without data

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.

Screenshot displaying Apple's historical stock price data from Yahoo FinanceScreenshot displaying Apple's historical stock price data from Yahoo Finance

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“.

Screenshot showing how to activate File Search and add files in the assistant tools section

Upload the file, and once it’s uploaded, click “Attach“.

Screenshot displaying the upload and attach process for a file

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“.

Screenshot illustrating how to ensure the assistant requires a tool call to process a query

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.

Screenshot showing a more accurate response from the assistant

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.

Screenshot showing an annotated response with a data source snippet

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.

Screenshot displaying the answer to which day in 2023 had the highest opening price for Apple

Alternatively, you can ask it to provide a list of the highest opening prices throughout 2023.

Screenshot showing the list of highest opening prices for Apple in 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.

The post How to Build a Custom AI Assistant to Analyze Stock Market Data appeared first on Hongkiat.

Leave a Reply

Your email address will not be published.