Coding for Retail Traders: Algo-Trading for the Rest of Us
Because Trading on Gut Instincts & Lines on a Chart is So Last Century
Artificial Intelligence, or “AI” is all the rage right now, and is responsible for the vast majority of the increase in everyone’s Superannuation balances over the past year or two.
I was a very early adopter of “AI”. Not as early as the Wall Street Hedge Funds, but I was immediately facinated by it and eager to explore the opportunities it may present, both a) business-wise, and b) in terms of improving my own personal quality of life and overall efficiency (ie being able to get more stuff done, while spending more time travelling / golfing / at the beach).
I purposefully delayed several of my own business ideas and encouraged some of the start-ups I liaise with to do the same as we waited for AI to mature. In my opinion, these models are now becoming extremely powerful and easy to use, and we’re now very close to the point that they can significantly improve the average person’s life in various ways.
These days, I reckon I spend 2+ hours per day using either ChatGPT, Google Gemini, or Anthropic (the 3 most well-known models) for any number of tasks. The ChatGPT Mac App is permanently open on my Macbook.
Looking through my ChatGPT history, I primarily use these models for Tasks relating to:
Trading Related: Visualisation of Data, Backtesting, Strategy Development, Coding
Writing: Content Ideas, Emails, Text to Image.
School for the Kids: Creating Tests, Subject Matter, Random Questions
Travel Related: Translation, Modern History, Places to Go, Places to Eat, Image to Text (ie WTF is this meat I’m looking at in this Greek supermarket??)
General: PS5 Spiderman 2 Help, Top 20 Comedy Movies, ‘Friends’ Trivia Questions, Iphone Troubleshooting,
Best Romantic Movies, Hair Growth Treatments(My wife is responsible for those, I swear).
Obviously, the one that’s of most interest here is how we can use these tools to improve our trading. According to ChatGPT, Ai can assist traders in the following ways:
“Retail traders can leverage the power of AI and coding in several ways to enhance their trading strategies and decision-making processes. Here are some ideas:
1. **Sentiment Analysis**: AI models can be trained to analyze news articles, social media posts, and other textual data to gauge the overall sentiment surrounding a particular stock or market. This information can help traders identify potential buying or selling opportunities based on market sentiment.
2. **Technical Analysis**: AI can be trained to recognize patterns in historical price data and identify potential entry and exit points for trades. Simple coding can be used to backtest trading strategies and optimize parameters for technical indicators.
3. **Algorithmic Trading**: Retail traders can develop simple algorithms using coding languages like Python to automate their trading strategies. These algorithms can be designed to execute trades based on predefined rules and conditions, reducing the influence of human emotions.
4. **Portfolio Optimization**: AI models can be employed to analyze a trader's portfolio and suggest optimal asset allocation strategies based on risk tolerance, investment goals, and market conditions.
5. **News Monitoring**: AI-powered news monitoring tools can be used to track relevant news and announcements related to the trader's holdings or watchlist. This can help traders stay informed and make timely decisions.
6. **Data Visualization**: Coding can be used to create interactive data visualizations, such as charts and dashboards, to better understand market trends, patterns, and potential trading opportunities.
7. **Backtesting and Simulation**: Retail traders can use coding to backtest their trading strategies on historical data and simulate different market scenarios to assess the potential risks and rewards of their strategies.
8. **Machine Learning Models**: With some coding knowledge, retail traders can develop and train machine learning models to identify patterns, make predictions, and generate trading signals based on various data sources, such as price data, news sentiment, and economic indicators.”
This stuff is WAAAAAAY out of my area of expertise, and I intend to spend a significant amount of time over the next few months learning more about how to best exploit these opportunities. However in terms of the most basic tasks for dummies like me, these are a couple of tasks I currently carry out on a regular basis:
PART A: Develop conditional code so I have no discretionary decisions to make in my trading executions
Let’s say you’ve done your backtesting, developed your strategy, and decided that you want to trade LONG the SPX every time that a) the prior day move was positive, and b) the price is trading above the 200 day moving average. Obviously this is an oversimplified example, but you can add as many conditions as you feel is required.
Let’s get AI to write me the python code so we can run in a program like Visual Studio.
Next, let’s copy the code and import into a program such as ‘Visual Studio Pro’, and press Play.
Now the program prompts me to enter the variables which we agreed on. Note that I’m sure it’s quite easy for these variables to be automatically imported via some kind of Library, however that’s over my head at the moment.
If we enter, for example, “20” for the S&P Move Prior Day, and “Yes” that the price is currently above the 200-day moving average, the program automatically tells us to Trade LONG the SPX. Anything other than this, we get a “DO NOT Trade SPX” result.
Very basic I know, but for a dummy like me, it’s been quite useful. Particularly for my daily trading strategies which have defined instructions and entries based on several market variables, derived from statistical backtesting of the data.
PART B: Testing Trading Strategies
The other area where I see that these tools can aid the retail trader is via testing of various strategies. This is one task that, until the release of ChatGPT 4o, has not been possible.
I gave this example in last week’s review, but I think it’s a good one for what can be achieved for any event if you have the required data. I use this to shape my own trading decisions daily, and to provide context when producing the daily TGM substack.
In this case I uploaded the historical statistics for the first session moves on the UK100 when it re-opens following long weekend over the past 3 years, and provided ChatGPT with an outline of a basic tiered short strategy I wanted it to evaluate.
Firstly it extracts the data, and confirms the strategy to be evaluated.
Next it works out the steps on how to calculate the profit for each occurrence, and documents in table form.
Finally it provides the overall profit / loss which would have resulted from the strategy.
In this case given it was calculating short positions, it provided the profit figure as a negative. Adding the 34pts profit you would have achieved from executing this strategy last Tuesday, the overall strategy has returned 903pts (excluding spread costs), or an average of 53pts profit on each trade. Not too bad. And you can literally just upload a simple table of data from any source, and ask it to do all the work.
The bottom line of all of this in my opinion is that by having access to these tools, (which were once out of reach for even the most sophisticated hedge funds), it puts much more power in the hands of the retail trader. I believe that this is a massive opportunity for traders to become both more sophisticated and granular in terms of their trading strategies (PART B), and also improve their execution discipline when trading (PART A) by making it very much a black and white decision of whether to trade or not.
Testing the underlying data is of course critical to fully exploiting these tools in the above manner. Whether gaining access to the relevant data via a paid service (like mine here), or building your own database, is the key which can help unlock much of this potential in my opinion.
If you have any questions on any of this, I’m probably not the best person to ask. In fact, if there are any budding programmers out there….I would be very interested in learning more, or chatting about some mutually beneficial opportunities to develop these tools further.
Cheers
Marto