Building An AI-Based Algorithmic Trading Strategy

I Know First Research Team LogoThis article was written by the I Know First Research Team.

For decades, trading has been done primarily by humans, some of them crowding at the busy exchange, others picking out the best assets to buy and sell from the office. Today, however, a major share of market transactions is in fact conducted by sophisticated algorithms. In fact, just a few years ago, algorithmic trading was reportedly behind 60-70% of transactions on US financial markets, although their current share is probably lower.

In itself, however, algorithmic trading is not necessarily something particularly new: in fact, the widely spoken-about practice known as High-Frequency Trading, one of the prime examples of top-notch algorithmic strategies, stems from the early 2000s. What is new these days, however, is a fintech trend that holds a promise of amplifying the success of algo-traders by giving them extra tools to improve the performance of their models.

This trend is the rise of the artificial intelligence industry, which is re-shaping the world one visionary idea at a time. Among other things, AI is capable of modeling the market dynamics and predicting what happens next with a solid accuracy level. Feeding its predictions into your algorithm makes for an extra measure of what are the best assets to long and short and what is the best time to enter and exit the market.

Best of all, with a whole variety of online platforms offering a free environment to build and test your trading algorithm in, algorithmic trading has never been as accessible as today. How do you get a piece of this pie, where do you start, and how to use AI to make sure your algorithm beats the market? Continue reading to find out.

Getting Started

So what do you actually need to build your own trading algorithm? Well, in most absolute terms, you need two things to start algorithmic trading. First, you need a strategy, a set of rules that explains when to enter a trade, what asset to go for, what are the conditions for exiting the market and the rest of the details. The second thing is the algorithm itself, that effectively codifies this strategy for the computers to interpret and act upon.

Now, investment strategies are many and diverse these days, and no matter what asset universe you are planning to conquer, there is probably something for you out there, an approach that will take into account your funds and appetite for risk. In this article, however, we would focus on AI-driven algorithmic trading, discussing some ideas for it in the next section, so for now, let us briefly talk about the algorithm itself.

The good news is that, in absolute terms, you do not necessarily have to know how to code to build your own automated trading solution. No coding algorithm trading platforms like TSLab allow users to design algorithms using a visual interface that can be used to build the logical blocks. Similar tools are offered by some of the brokers, like Interactive Brokers with their Elite Trader portal.

These, however, at times utilize approaches that are not too friendly towards smaller players. Furthermore, working in a proper application programming interface (API) would give you more versatility, a higher degree of control over your code and the ability to bring in extra data sources. This would come in handy if you want to plug in the AI predictions into your code – by letting the algorithm open a connection with the service that you get your predictions from and add in the data processing functions, you can make your trading fully automated.

Thus, it is recommendable to learn at least the basics of coding. Many algorithmic trading platforms, like Quantconnect, for example, expect you to be familiar with Python. Python is a sought-after and versatile high-level programming language which is relatively friendly to people with no formal background in Computer Science. A variety of free online courses is available: see here and here, for example. To get down to trading, you will need to get an understanding of how to write the logics (especially the if-else statements, while-loops can also come in handy), work with numbers and process datasets.        

Ideas For AI-Based Algorithmic Trading Strategy

Now that we have figured out where to start, the next question to ask is what is our strategy going to be. In this article, we will use the I Know First AI-driven swing trading strategy, which utilizes the predictive power of the AI as a supplement for traditional technical analysis.

Before we delve into the details of this approach let us briefly discuss what the I Know First AI does and why exactly we will be using its predictions in our algorithm. The deep learning-based AI trained by I Know First on a historic dataset covering 15 years of trading provides predictions for over 10,500 financial instruments, including stocks, currencies, ETFs and commodities. Its forecasts are delivered as a heatmap with two numeric indicators: signal and predictability. Signal shows how far the asset’s current price is from the price point that the Ai considers fair, with a positive signal indicating the price is about to go up, and a negative signal predicting a nosedive. Predictability, in its turn, demonstrates how successful the algorithm has been in predicting the asset before. The forecasts cover time horizons ranging from 3 to 365 days.

The algorithm can easily adapt to new market conditions by virtue genetic programming in its design. In other words, it keeps track of its own successes and failures, and updates its models as soon as they start to lose their predictive power. This also ensures that the prediction accuracy goes up after every iteration. The AI also draws on chaos theory to account for market volatility.

So how can we use all this to build an algorithm? In Dr. Roitman’s strategy, we do it in the following fashion. We enter the trade when two conditions are met: the 5-day moving average price of the stock is below its current price and the algorithm’s predicted 3-day signal for the stock has been on average positive. This, as we noted, is essentially an updated version of traditional technical analysis for swing trading, where the moving average meets advanced AI predictions.

Now, thankfully, most of the algorithmic trading platforms provide price data feeds that you can easily plug into your algorithm, but if you are going solo on this one, you may need to open a connection to Bloomberg or Yahoo Finance and read the data into the algorithm from there. The conditions can be coded in as a simple if-statement which is true when the two means, the mean for the price and the signal, are above 0. To pick up the stocks of interest, just have this algorithm iterate through the trading dataset.

The next step is to identify the most lucrative stocks; this can be done by having the algorithm take a closer look at the stocks identified at the previous step and ranking them. The ranking can be done either on the basis of the current price or as a function of it, with signal and predictability readings used as the weight. Similarly, when choosing how to allocate the funds across the assets that the algorithm has picked, you can split them on an equal basis or, again, use the signal and predictability for weights.

What is left is to deal with the code that works with the actual trading, which will, again, depend on the platform and broker service you are using, and the block of code that will exit the trade as soon as one of the conditions that we have already established is broken. In other words, if the average prediction turns negative or if the moving price average goes above the current price, the algorithms need to sell off the assets.

This, of course, is only one of the many ways to use the I Know First AI in a trading algorithm. As an idea, you could cross-reference the 3-day,-2-week and 3-month forecasts to pick up the financial instruments that are predicted to show a long-term positive trend and capitalize on it in a way that is more in line with positional trading than swing trading. Or, alternatively, you can focus instead on the negative forecasts and use those for short-trading. Or, indeed, you can go for both long and short positions; in fact, if you are hoping to license your algorithm out to the platform you built it on – incorporating both short and long trading is a frequent prerequisite there. But even if that is not what you are after, with some training and thought put into it, AI-driven algorithmic trading can work as a great source of passive income and reward all the effort you put in your code with real returns.