Using ChatGPT to create an AI commodity trading bot
Creating an AI trading bot using ChatGPT and Composer - A no-code trading bot creator
In today's fast-paced world of technology, ChatGPT stands out as an impressive language model that is transforming how we interact with the digital realm. Created by OpenAI, ChatGPT boasts remarkable abilities in natural language understanding and generation, offering users a highly adaptable tool for a wide range of uses. ChatGPT operates in a Q&A format, allowing you to ask questions/enter instructions, while ChatGPT will answer and also remember previous instructions you gave it.
2022 was a year that really emphasized the importance of commodities in a diversified portfolio. On the global scale, the global energy and food supply crises (primarily caused by the Ukrainian war) caused rampant inflation and soaring commodity prices. So you may be thinking, as an investor, how can I use AI to create a commodity strategy to maximise returns during these times?
This article will delve into how you can combine the power of ChatGPT to develop a commodity strategy trading bot from scratch. The key focus of this article will be on how to personalize this commodity strategy based on your needs.
Composer is the tool we’ll use for this tutorial. It allows you to build trading algorithms with AI, backtest them, then execute—all in one platform
Why are we using Composer in this tutorial? Composer uses ChatGPT4 which is the latest AI model by OpenAI (released in March 2023). Composer has also invested heavily in finetuning the ChatGPT4 model specifically for the trading use case. Therefore you get a much better AI assistant for trading use cases (you can test it on the free plan and it's included as part of the Pro Plan).
Step 1 - Head to Composer and click on the ‘Create’ section.
On the Create page you’ll have the option to “Create with AI”.


Step 2 - Create a baseline strategy by giving the AI assistant some details
For some context, Chat GPT is a natural language processing (NLP) model so you interact with it in a question/answer style.
Start by giving the AI assistant some basic facts so we can create a baseline retirement strategy (don't worry too much as we can continue to amend it as necessary).
The example we'll use: "Create a commodity strategy that invests in a few commodity ETFs when the commodities are doing well. When commodities are not doing well, invest in other real assets like Gold and Real Estate"
Great! We have a baseline strategy that rebalances monthly and checks if the 50-day moving average price of DBC (a broad commodity ETF) is greater than its 200-day moving average price. If it is, the strategy allocates equal weights to a few commodity ETFs (DBC, USO, UNG, CORN, and SOYB). If not, the strategy allocates equal weights to Gold (GLD) and Real Estate (VNQ) ETFs.

Step 3 - Click “Insert and Backtest”.
This places the code that the AI assistant has created into the visual editor. Here it’s much easier to see how the logic works. You can also edit the strategy directly in this editor e.g. you may want to use the various indicators e.g. relative strength index or moving average to filter your assets.

If you scroll down, you’ll arrive at the backtester so you can use professional grade data to understand how the trading bot would have performed historically. There is also detailed performance metrics for the trading bot e.g. maximum drawdown, calmar ratio, sharpe ratio etc. You can also find how the bot would have allocated across assets each day.

As we can see the strategy did very well when commodity prices were soaring in 2022 however the volatility is still very high with a maximum drawdown of 21.4% in this 3 year window.

Step 4 - Continue the conversation and finetune your strategy.
This is where things can get interesting! Let's adjust the strategy to reduce the volatility.
For the purpose of this tutorial, we will ask the AI assistant "Can you adjust the strategy to reduce the volatility?

Great! The AI assistance now weights the basket of ETFs by 90d inverse volatility so less volatile assets get more weight in the strategy. Now insert and backtest and your updated strategy has been created for you to backtest.
As you can see, the Sharpe Ratio in this 3 year period has increased and the maximum drawdown and standard deviation fell! (Please remember that past performance is not an indicator of future performance and watch out for overfitting - test out different time to see how your strategy fares in different economic conditions).

This is only the start - You can adjust the strategy as you wish in the editor until you're ready to invest.
Step 5 - Invest with the click of a button.
Composer automatically executes your trades for you based on your rebalancing schedule. Composer is a Registered Investment Advisor (RIA) and they are regulated by FINRA and the SEC. Funds are protected up to $500k through SIPC and the custodian is BMO Harris bank.

Common Mistakes
If you find that the AI assistant throws an error, this can be due to a few common pitfalls.
1) Ensure that you are only using the indicators currently available on the Composer Symphony Editor. E.g. You can't currently as AI assistant to create the Composer code for a trading bot that trades based on CPI as CPI is not a function you can use in Composer yet.
2) Sometimes, the stock ticker will be imported into the Composer Symphony editor but may require manual editing of the name in case ChatGPT has misspelt the ticker name or the ticker name has changed since ChatGPT was released. ChatGPT may also suggest tickers that may now not be traded publically.
You can find the full documentation here.
Summary
As you can see, Composer's AI assistant with ChatGPT4 is a versatile tool that can assist you in building a personalised commodity strategy based on your needs. The AI assistant can also help you change the rebalancing frequency of your investment strategies to ensure they follow the desired schedule. When it comes to identifying potential investment options, the AI assistant can provide recommendations for commodity ETFs and stocks. Another great use of the tool is finding and replace assets within existing strategies.
I hope I've provided some initial inspiration for you to create your own AI commodity strategy trading bot. I look forward to seeing what you create!
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.