Using AI to Improve Investment Strategies: An Introduction to Prompt Engineering
Using prompt engineering with ChatGPT to improve investment strategies based on current market conditions
Investment strategies are the lifeblood of any successful trader. They allow one to navigate the complex world of financial markets with precision and confidence. However, these strategies can often be complex and difficult to master. This is where Artificial Intelligence (AI) can come into play, especially when combined with prompt engineering. In this article, we will walk you through how AI, specifically the GPT-4 model developed by OpenAI, can be utilized alongside a trading platform like Composer to enhance investment strategies.
Unpacking the power of AI in creating automated trading bots (without code!)
ChatGPT and Bing are two AI models that have been used to create different trading strategies. These models have the ability to learn and adapt based on the inputs they receive. They can analyze complex trading strategies and then modify them to improve performance. Now that OpenAI has launched web browsing in beta, the strategies can be modified using up to date data. For traders who are not familiar with Python code, this is a welcome development as these AI models allow you to build trading strategies using a no-code strategy builder.
Composer is a trading platform built on top of the Alpaca API. This platform allows traders to construct trading strategies without having to write Python code. Instead, Composer uses a visual programming language that can be understood by AI models like ChatGPT and Bing. This way, traders can visualize the steps the AI is taking to make trades.
Exploring Trading Strategies with AI
Once a strategy has been selected, the AI models are tasked with understanding and explaining it. They do this by learning the syntax of the Composer programming language, essentially understanding what the strategy does and how it works. This process, known as in-context learning, helps the AI models generate accurate outputs based on the inputs they've received.
After the AI models understand the strategy, they can be then prompted to make it more profitable. This involves modifying the existing strategy to increase its profitability by up to 20 percent. The AI models are able to make these modifications by adding new components to the strategy. These additions could include a momentum filter to select assets with positive momentum, or a risk on core risk parity group to include the momentum filter.
Contextual Changes and Strategy Adjustments
AI models have the ability to adapt trading strategies based on changes in the global economy. By providing the AI with context on how the economy has changed, or alternatively by incorporating real-time data, the AI models can create more profitable strategies. This might involve investing in specific stocks or ETFs that are relevant to the current economic climate.
For instance, if there is a global shift towards de-dollarization and a potential for hyperinflation, the AI could suggest investing in real estate ETFs to hedge against potential inflation or gold miners ETFs for a safe haven during uncertain times. Likewise, the AI models could suggest investing in technology ETFs if there is a significant rise in AI technologies and automation.
A Deeper Look into Prompt Engineering
AI models require prompt engineering to improve their outputs. Prompt engineering involves providing more context to the AI models to help them understand the task at hand better. This can be done by giving the AI more examples, explaining the task in a different way, or breaking the task down into smaller, simpler tasks.
In this case, the AI models are given more context about the syntax of the Composer language. This enables them to understand how the language works and avoid syntax errors when modifying the strategies. Once the AI models have this understanding, they can successfully modify the strategies and ensure they are error-free.
Bringing Real-Time Feeds into the Mix
Both Bing, and ChatGPT, are now connected to real-time feeds from the internet. This allows them to adapt trading strategies based on the latest economic news and events. By providing Bing with news articles about the economy, it can create profitable strategies for the current market.
Putting it all Together Using an Example
To demonstrate how this works in practice we can use a real life example. We can start with one of the existing strategies that Composer provides on the Discover page. In this case we are going to select The Not Boring: Rising Rates with Vol. Switch and under the ‘More’ dropdown are going to 'copy the GPT prompt'.

We can then head over to ChatGPT and select ChatGPT 4 with the browsing functionality enabled. What this does is give ChatGPT access to live data. Chat GPT learns the syntax of the Composer language and outputs a natural language explanation of what the strategy does:

The goal however, is to use prompt engineering to improve the strategy. ChatGPT has guardrails around investing or trading so it pays to be nice!

ChatGPT after telling us that it can’t provide financial advice then does go on to provide a modified version of the strategy.

We can then take this code and head back to Composer where we ‘Create’ a new symphony and paste in the schema. Then we can run another backtest to see how it compares.

But so far we aren’t really taking advantage of the benefits of being connected to the internet. So let’s modify the prompt to see if we can improve it further. Using the web based connection w/ ChatGPT pull core inflation data and market sentiment data including what the bond market is saying about rates.

GPT goes through a series of macroeconomic data and sentiment analysis to create a strategy based on the below theme:

The question then is does it work. So we take the code and head back to Composer where we paste it in.

The backtest of the strategy that GPT creates for us outperforms the SPY but doesn’t have the same historical returns as the modified ‘Rising Rates with Vol Switch’ symphony. However, we specifically prompted GPT to give us a strategy that will work under current market conditions and going forward. These are conditions that are different to those under which the backtest results were generated. Like this we can continue to prompt GPT to improve the strategy until we arrive at a place where we are satisfied.
AI models like ChatGPT can act as a thought partner in the strategy development and creation process. Since they are reasoning engines, but with limited knowledge we can provide them the specific knowledge we want and use their outputs to help sharpen our thinking.
Important Disclosures
Investing in securities involves risks, including the risk of loss, including principal. Composer Securities LLC is a broker-dealer registered with the SEC and member of FINRA / SIPC. The SEC has not approved this message.
Certain information contained in here has been obtained from third-party sources. While taken from sources believed to be reliable, Composer has not independently verified such information and makes no representations about the accuracy of the information or its appropriateness for a given situation. In addition, this content may include third-party advertisements; Composer has not reviewed such advertisements and does not endorse any advertising content contained therein.
This content is provided for informational purposes only, as it was prepared without regard to any specific objectives, or financial circumstances, and should not be relied upon as legal, business, investment, or tax advice. You should consult your own advisers as to those matters. References to any securities or digital assets are for illustrative purposes only and do not constitute an investment recommendation or offer to provide investment advisory services. Furthermore, this content is not intended as a recommendation to purchase or sell any security and performance of certain hypothetical scenarios described herein is not necessarily indicative of actual results. Any investments referred to, or described are not representative of all investments in strategies managed by Composer, and there can be no assurance that the investments will be profitable or that other investments made in the future will have similar characteristics or results.
Charts and graphs provided within are for informational purposes solely and should not be relied upon when making any investment decision. Past performance is not indicative of future results. The content speaks only as of the date indicated. Any projections, estimates, forecasts, targets, prospects, and/or opinions expressed in these materials are subject to change without notice and may differ or be contrary to opinions expressed by others. Please see Composer's Legal Page for additional important information.