Tutorials

A LLM Framework for Financial Trading

People have always tried to get the best results out of their investments using whatever they have available, including novel technologies. As a result, one of the biggest and most important use cases for algorithmic solutions has always been the financial sector, and trading software has been an essential part of the continued advent of the internet. Not only do such technologies help anyone seeking to make investments be as timely as possible, but they also have gone so far as to have democratized trading for the wider community.

But what can they do to actually tell us how and why to make trades? Can these algorithms and trading softwares actually inform our decisions? The answer is not really, before the AI revolution. But now, people are using machine learning techniques like time-series forecasting and sentiment analysis to inform their decisions in ways that weren’t possible in the past.

This past month, a new and powerful tool for making informed trading decisions, TradingAgents, hit the open-source community, and it is quickly making waves. This first release of the tool is fairly simple; it uses a series of LLM agents to create a comprehensive report about a specific stock. This straightforward tool is deceptively powerful: the pipeline consists of four comprehensive, agent perspectives that are collected before being collated into a single decisive report.

In this article, we will look at how TradingAgents works to create the report & discuss our opinion of its capabilities. Follow along for a full look at how TradingAgents works, and a demo on how to run TradingAgents on a DigitalOcean Droplet.

TradingAgents is a multi-LLM based trading platform designed collaboratively to evaluate market conditions and inform trading decisions. It achieves this by using a series of informed agents that analyze different components of the market pertinent to the relevant stock.

To achieve this, it starts by using agents for up to four different categories to conduct analytical research, focusing on the financial data of the market, sentiment from social media, news, and company fundamentals like the company profile and financial history. This comprises the analyst team which concurrently works to gather pertinent market information for the researcher team. The Researcher Team in turn is composed of bullish and bearish agents. This team takes the information gathered by the analyst team and uses analytic discussion to critically evaluate the data. Their conclusions are then passed to Trader agent which makes the theoretical trading decision. The transaction proposal is then given to a series of risk management agents which evaluate the soundness of the request. Finally, a fund manager agent approves and executes the trade if it is deemed a good decision.

While the authors do not at this time recommend the pipeline is used for any purpose other than experimentation, it represents a potent simulacra of a real life decision making process for making a trading decision. We also agree, and do not recommend ever using this agent to make real life trading decisions. Nonetheless, let’s look at how we can run TradingAgents.

In this section, we walk through the steps for running TradingAgents and discuss its capabilities based on a report on the sample stock SPY.

Setting up the Environment

On the machine of your choice, clone the TradingAgents repo into the directory of your choice.

git clone https://github.com/TauricResearch/TradingAgents

Once the repo is cloned in, we can get started setting up our environment. First, let’s install the required packages:

pip install -r requirements.txt

This process should only take a few moments. Once that’s finished, we need to save our environment variables for FinnHub and OpenAI. For the record, you only need a free FinnHub account to do this tutorial, but a paid OpenAI account is required for API access. Save the variable using the code below after replacing the values with your own API keys.

export FINNHUB_API_KEY=$YOUR_FINNHUB_API_KEY export OPENAI_API_KEY=$YOUR_OPENAI_API_KEY

If everything was done correctly, we are now ready to get started generating the report!

Generate a TradingAgents Report

To generate a report, run the following command:

python -m cli.main

This will start up the TradingAgents program in your browser. To continue, enter in the ticker value for the publicly traded company you are interested in studying. We used the default value “SPY” for this demo. You will then be prompted to select a date.

Finally, we select which agents we want to use for the analysis. There are four available options: technical, sentiment, news, and fundamentals. Each of these covers a different approach to the problem of whether or not to purchase/trade a stock. Together, they create the holistic reporting technique we described earlier in this article. We recommend using as many agents as possible when using TradingAgents, so we get the best considered answer to the task.

Next, we are prompted to select the depth of the research the agents go into. There are three options: shallow, medium, and deep. These correspond to increasingly more thorough research on the stock. Whenever possible, we recommend using the deep research option for the best results.

Finally, we are asked to select the models used for “Quick-Thinking” and “Deep-Thinking” from the LLM provider, OpenAI. The “Quick-Thinking” model, for which they recommend using either gpt-4o-mini and gpt-4o, handles fast tasks like low-depth tasks like summarization, data retrieval, and converting tabular data to text. The “Deep-Thinking” model, in contrast, should be a reasoning model like o1-preview to handle decision making tasks that require deeper thought, like evidence-based report writing and data analysis. We suggest selecting the most powerful model afforded by your API plan for each, as this will enhance the research the models conduct. More powerful models will be more time consuming to run, but this tradeoff is worth it in our experience running the pipeline.

With these final selections, we can begin generating our report. Before continuing, be sure to make your terminal window as large as possible. Due to the in window formatting of the application, the text may be truncated if you do not do so. Since the report is not sent to an external file, this is the only way to view the report, so it is best to avoid the truncation.

All in all, the results are fairly comprehensive and useful. While by no means do we recommend using this to make investment decisions, and in fact advise against doing so, this is an interesting experiment that shows the potential for these tools going forward to make predictive analytics about different stock tickers.

TradingAgents is a truly innovative application of LLM technologies with tool calling capabilities. Thanks to the intensive research and analytical capabilities afforded by the pipeline, we believe this experiment generates some very interesting results. We encourage everyone to try it out!

We want to reiterate here that DigitalOcean does not recommend using TradingAgents for financial decision making. This is solely an experiment, and should be treated as such.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button