MORITZ PUTZHAMMER
03 May 2023 • 14 min read
First things first—this article on artificial intelligence and crypto trading bots has not been generated by artificial intelligence (read: ChatGPT). We’re not that meta here at Trality HQ. While it’s true that AI can do (basic) content, it hasn’t quite mastered the art of humor (yet?).
At any rate, the basic subject at hand is the intersection of technology and trading, in this case AI, machine learning, and the buying and selling of cryptocurrencies. Longtime readers of our blog will already know that we are big proponents of automated investing given the sheer number of benefits: speed and efficiency, precision, consistency, and lack of emotions, among other things. The harsh reality is that we, as human beings, make inefficient traders, whether due to a lack of knowledge or our emotions (FOMO) or simply because we were asleep when a major movement in the crypto market occurred.
In many ways, artificial intelligence (AI) has revolutionized the world of finance, and crypto is no exception. Automated trading using AI has become increasingly popular, as many retail traders absorb the lessons of Wall Street, chief among them being the ones mentioned above (i.e., greater efficiency, lack of emotions, etc.). AI-powered trading bots are simply better at analyzing large amounts of market data, identifying patterns and trends, and making trading decisions, thereby increasing the likelihood of minimizing risks while increasing profits.
While we can’t possibly cover everything within the scope of a blog article, we will mention in passing some interesting points within the history of algorithmic trading, which, incidentally, precedes machine learning. We’ll then sketch a brief timeline of AI and ML, looking at how they are used in finance, before considering AI crypto trading bots (i.e., what they are, how they work, why people use them) before wrapping things up with some final thoughts on the future of crypto trading with artificial intelligence and machine learning.
Let’s get to it!
As mentioned, the history of algo trading precedes the use of machine learning and artificial intelligence. In fact, it’s a long and fascinating journey, one that would require multiple books on a range of topics. In order to do it justice, one would have to consider things such as the rise of quant funds, the invention of the Merton model for pricing options, portfolio theory by Harry Markowiz, Kiyosi Itô and stochastic calculus, microwave technologies used by Jump Trading and Jane Street, and even John Nash and game theory, among many others.
The use of artificial intelligence and machine learning in finance has a long and complex history. Before we dig a bit deeper into the details of AI crypto trading bots, the following are some of the major historical milestones:
It goes without saying that both AI and ML are expected to continue to evolve, promising to have a revolutionary impact on the finance industry and crypto market in the months and years ahead.
With the introduction of ChatGPT in late 2022, artificial intelligence (AI) is now everywhere (or so it seems). But what exactly is it? Broadly, AI is a term that refers to computer systems that can perform tasks that typically require human intelligence, such as perception, reasoning, learning, and decision-making. Whether it’s writing texts, creating an image, composing a song, or generating lines of code, artificial intelligence can do it all, although the results are often a mixed bag.
Despite the recent hype, though, the use of artificial intelligence to create texts is nothing new. In fact, the first book ever written by artificial intelligence dates back to 1984, when The Policeman’s Beard is Half Constructed was produced by a program called “Racter.”
The history of artificial intelligence and music is even older. Russian researcher Rudolf Zaripov published the first paper on algorithmic music composition using the "Ural-1" computer as early as 1960, while only five years later Ray Kurzweil debuted a piano piece that was created by a computer capable of pattern recognition in various compositions.
And if you think that the confluence of artificial intelligence and art is a novel concept, then think again. As a Wiki entry explains,
One of the first significant AI art systems is AARON, developed by Harold Cohen beginning in the late 1960s at the University of California at San Diego. AARON is the most notable example of AI art in the era of GOFAI programming because of its use of a symbolic rule-based approach to generate technical images.
So much for the (recent) hype.
Financial services companies are becoming hooked on artificial intelligence, using it to automate menial tasks, analyze data, improve customer service and comply with regulations.
—Nick Huber (2020)
As Huber suggests, artificial intelligence has a variety of applications within traditional and more disruptive forms of financial services. If we think of trading, for example, the power of AI is being applied to the modeling and prediction of financial time series data.
What’s the point, you might be asking? The holy grail in this case are statistical inefficiencies, or situations in which the AI algorithm outperforms a baseline algorithm in predicting future market movements, as Yves Hilpisch notes in his book Artificial Intelligence in Finance: A Python-Based Guide. These statistical inefficiencies suggest economic inefficiencies, and this information can provide a basis for a trader to develop an effective trading strategy, one that can exploit the inefficiency to such an extent that above-market returns are achieved. As Hilpisch writes, “[...] there is a strategy—composed of the prediction algorithm and an execution algorithm—that generates alpha”—or the measurement of excess return when trying to outperform the market.
But beyond trying to identify and leverage inefficiencies within markets (whether traditional, crypto, or otherwise), AI is being used in finance in a number of interesting ways, from credit scoring, fraud detection, and trade execution to derivatives hedging, portfolio management, and even something as mundane as customer service. The ability of AI to identify (often anomalous) patterns, sift large amounts of data efficiently and precisely, and interact with customers, among other things, reveals the extent to which neural network–based approaches (and neural networks in general) can be trained on large datasets as well as cope with nonlinear relationships and structured and unstructured data (often simultaneously). In fact, what we’re seeing is just the tip of the iceberg.
Machine learning (ML) is a subset of artificial intelligence (AI) that involves the use of algorithms and statistical models to enable computers to learn from data without being explicitly programmed. Essentially, machine learning algorithms can identify patterns and make predictions based on large datasets, allowing for more accurate and efficient decision-making. Additionally, there are various subsets within machine learning, one of which is reinforcement learning.
In the case of crypto trading, reinforcement learning is a type of machine learning that involves training a bot to make optimal decisions in a dynamic environment by maximizing a cumulative reward signal. In stochastic control problems, the environment is subject to random and unpredictable events, making it difficult to design a deterministic control policy that can achieve optimal performance. But RL can address this challenge by allowing the bot to learn from experience and adapt its behavior based on the changing conditions of the market.
As the above summary suggests, reinforcement learning has proven to be particularly useful for trading applications, where the goal is to make profitable trades in a highly dynamic and unpredictable market. One of the key advantages of reinforcement learning for trading is its ability to handle complex decision-making problems that are difficult to model using traditional methods. For example, RL can be used to learn optimal trading strategies for high-frequency trading, where decisions need to be made in a matter of microseconds or for optimizing portfolio allocation in which the goal is to balance risk and return across multiple coins.
In terms of defining ML, IBM, which has a long relationship with machine learning, describes it in a clear and concise way: “Machine learning is a branch of artificial intelligence (AI) and computer science which focuses on the use of data and algorithms to imitate the way that humans learn, gradually improving its accuracy.”
At this point in the article, you’ll likely be unsurprised to learn that machine learning isn’t new either. IBM’s Arthur Samuel is often cited as having coined the term in 1959, and one of the earliest applications involved a simple game of checkers. Ironically, only a few years later a self-proclaimed checkers master, Robert Nealey, lost to an IBM 7094 computer, further cementing the age-old rivalry between man and machine.
Remember those statistical and economic inefficiencies that we mentioned? The use of machine learning in investing is like automating the process of looking for a needle in a haystack, or like mining for gold.
In his book Advances in Financial Machine Learning, Marcos López de Prado likens the ongoing development of today’s investment strategies to the historical changes that have taken place in the mining of gold and silver. In the sixteenth and seventeenth centuries, mining gold and silver was fairly straightforward, so much so that the amounts of the precious metals circulating in Europe exploded in a relatively short period of time. Fast-forward to today, however, and the situation is vastly different, as complex industrial mining operations are now required to extract increasingly smaller volumes of gold and silver.
Investing and trading today are similar. As López de Prado makes the point convincingly:
The discovery of investment strategies has undergone a similar evolution. If a decade ago it was relatively common for an individual to discover macroscopic alpha (i.e., using simple mathematical tools like econometrics), currently the chances of that happening are quickly converging to zero. Individuals searching nowadays for macroscopic alpha, regardless of their experience or knowledge, are fighting overwhelming odds. The only true alpha left is microscopic, and finding it requires capital-intensive industrial methods. Just like with gold, microscopic alpha does not mean smaller overall profits. Microscopic alpha today is much more abundant than macroscopic alpha has ever been in history. There is a lot of money to be made, but you will need to use heavy ML tools.
In other words, manual retail trading is a fool’s errand. Without the use of automated investing and trading strategies such as crypto trading bots, it is virtually impossible to achieve alpha, particularly in a volatile market such as crypto.
A rudimentary definition might describe an artificial intelligence (AI) crypto trading bot as a computer program that uses advanced algorithms and machine learning techniques to automate the process of buying and selling cryptocurrencies.
Strictly speaking, an AI crypto trading bot could be understood to be a bot that has been developed by artificial intelligence itself, i.e., artificial intelligence has generated the code for a bot. It’s the same thing as an AI novel (a novel generated by AI) or AI art (art generated by AI) or AI music (music generated by AI). You get the idea.
One of the main differences between an AI trading bot and a regular trading bot is the ability to adapt and learn from new data. Regular trading bots are limited to the rules set by human traders, which may not be able to capture all the nuances of the market. In contrast, an AI trading bot can learn from new data and adjust its trading strategies accordingly.
Another difference is the complexity of the algorithms used by AI trading bots. Regular trading bots typically use simple algorithms based on technical indicators or price movements. Conversely, AI trading bots use more complex algorithms such as neural networks, which can identify patterns and relationships that are not apparent to human traders.
In light of Marcos López de Prado’s point above about microscopic and macroscopic alpha today, automated trading bots using artificial intelligence are becoming increasingly popular among retail traders. By using machine learning algorithms to analyze extremely large amounts of data, AI trading bots can help traders find microscopic alpha, even within a sea of crypto red.
The first step in terms of how an AI bot works relates to data collection. The artificial intelligence program (a ChatGPT-like equivalent for crypto trading bots) must gather the relevant data for the trading bot to analyze. By providing market data (price, volume, etc.), for example, the bot can analyze real-time and historical market data in order to identify trends and patterns that can inform its trading decisions. Depending on the market, macroeconomic indicators such as inflation, interest, and GDP rates can be useful (obviously less so when it comes to crypto). The bot can also be trained on its own trading history in order to optimize its predictions and strategies as well as the preferences and risk tolerances of individualized users (thereby providing a personalized service).
Once the data for the AI crypto trading bot has been collected, it needs to be preprocessed so that it can be used for analysis, and this typically involves cleaning the data, removing outliers, and normalizing it so that predictions learned from the past are more likely to explain the future.
So where’s the AI and ML in all of this, you might be wondering. An AI trading bot that uses machine learning is designed to learn from data and improve its trading decisions over time. Instead of following predetermined rules, the bot uses algorithms to analyze large amounts of historical data and identify patterns and relationships between different variables. It then uses this analysis to make predictions and decisions about future trades.
Will the price of a token increase? If so, is it possible to predict when and by how much?
A basic, actionable schema for using machine learning would involve the following elements:
An important step for the artificial intelligence program is to train the model, and this is where the power of ML shines. With a traditional trading bot, you are effectively using a heuristic approach. For example, you might program it in the following way: “if the relative strength index (RSI) is above 20, then buy.” While there is nothing inherently wrong with this approach, it is highly specific and quite narrow in terms of its parameters.
However, ML allows artificial intelligence to throw millions of data points at the bot without having to specify the exact way to solve an issue. Whereas previously you would have had something like “if x then y,” ML allows the retail trader to simply specify “maximize profits” (for example) and artificial intelligence will automatically find the best solution.
Trality users will be familiar with some of our machine learning-powered tools and the many benefits that they confer for retail traders. After all, creating a profitable Python-based bot can be a challenging proposition. Even when you have an algorithm idea with which you’re satisfied, optimizing its parameters can be frustrating and time-consuming, which is why Trality offers a machine learning-powered Optimizer. A new feature for the backtester when creating Python Code Bots, the Optimizer allows you to automate the parameter optimization process. When writing your bot code, you simply define relevant parameters and their respective ranges that you want to be optimized to achieve the highest PnL. And the Optimizer does the rest.
But how does an AI bot make predictions? This is where machine learning algorithm selection comes into play. For example, linear regression is a supervised learning algorithm used to predict a continuous target variable based on one or more input variables. In trading, linear regression can be used to predict the price of an asset based on historical price data.
Random forests are an ensemble learning algorithm that creates multiple decision trees and combines them to make a prediction. Each decision tree in the forest is trained on a random subset of the input data. In trading, random forests can be used to identify patterns in market data and make predictions based on those patterns.
Neural networks are a type of machine learning algorithm inspired by the structure and function of the human brain. They consist of layers of interconnected nodes that process input data to make a prediction. In trading, neural networks can be used to identify complex patterns in market data that may not be obvious to human traders.
The selection of the algorithm depends on the specific requirements of the trading bot, the data that is available, and the accuracy needed. For example, if the bot needs to make simple predictions based on a single input variable, linear regression may be sufficient. On the other hand, if the bot needs to identify complex patterns in market data, neural networks may be the best choice.
Models tend to be either classifiers (i.e., what type of market are we in) or continuous (i.e., what is the price tomorrow). Naturally, each has its benefits. For example, classifiers are essentially continuous, but with one extra step of converting the output into a probability.
Python is a popular programming language for building machine learning and AI crypto trading bots. It offers a wide range of libraries and frameworks that can be used to implement machine learning algorithms, such as PyTorch Geometric, Scikit-learn, TensorFlow, and PyTorch, among others.
Python's simplicity and readability make it a popular choice for building trading bots, as it can be used to quickly prototype and test different trading strategies. Additionally, Python offers a range of tools for data analysis and visualization, which can analyze market data and identify patterns and trends.
So which specific tools can be used when coding AI and ML crypto trading bots with Python? PyTorch Geometric, for example, is a library for deep learning on irregular input data such as graphs, point clouds, and manifolds, while Scikit-learn is a Python library for machine learning. TensorFlow is an open-source machine learning framework developed by Google. Keras is a high-level neural networks API written in Python. Matplotlib is a Python library for creating visualizations, and PyCharm is an integrated development environment (IDE) for Python. Obviously, this is just a basic list, as there are plenty of additional tools at a coder’s disposal.
And while we’re on the subject, Trality has developed a state-of-the-art Code Builder—the world’s first browser-based Python code bot editor. It is designed for experienced traders who want to develop sophisticated trading algorithms using the latest technology. In-browser editing with intelligent auto-complete as well as in-browser debugging provide a seamless process for the development of trading ideas and their eventual realization as profitable trading bots.
With a full range of technical analysis indicators and a growing number of libraries, including NumPy, the Code Editor provides maximum flexibility for customizing bots based on a variety of market conditions and a variety of short- and long-term trading goals. Blazing-fast, in-browser backtesting also means that testing and fine-tuning algorithms can be done quickly and easily. Benefit from clear versioning and backtest history, while also having access to financial data with easy-to-use API.
With the rise of cryptocurrencies and their volatility, machine learning-powered crypto trading bots have become popular among retail traders, as these bots enable traders to leverage advanced technology to improve their trading efficiency and profitability while minimizing risk.
AI crypto trading bots now represent the next stage in the evolution of retail crypto trading and investing. As we defined it, an AI bot is a bot generated by AI, whereas a machine learning bot specifies the actual technique used to solve the underlying problem.
For investors looking to test the waters, there are many options from which to choose, such as the Trality Bot Marketplace. Investors can rent profitable bots tailored to specific risk tolerances (low, medium, and high) and individual investment goals. A full suite of metrics is available, allowing investors to decide on a bot based on clear, quantifiable data.
Despite their promise (and AI crypto trading bots are indeed extremely promising), there are some things to bear in mind. An AI crypto trading bot will only be as good as the AI program that has created the bot, and early iterations of AI are not all created equal. There is also a question of transparency, specifically in terms of how the AI program works (many have raised similar concerns about ChatGPT). And a case can be made about the extent to which AI can react in real time to market dynamics, to say nothing of ethical concerns and regulatory uncertainty.
Nevertheless, with the emergence of AI crypto trading bots, it’s never been a more exciting, and potentially more profitable, time to be a crypto trader or crypto investor!