Technical Stuff
Copy of "Kumodroid Bot Documentation"
Introduction
Kumodroid Bot follows a modular framework in order to be executed in a microservices architecture. This design allows the bot to be in a constant state of evolution. The bot can be working at all times, even when new strategies are added or when existing strategies change.
A number of strategies are being back tested at all times, ensuring that the strategy with the highest probability of achieving a successful trade is always picked to serve signals to the user. As a result of this, any changes to the strategies must prove that they not only improve the strategy itself, but that it will also help it beat the others.
Python was chosen as the main programming language, as this programming language provides a rich ecosystem for machine learning applications.
Microservices
The modular design of Kumodroid Bot allows it to run it in different modes. Different instances of the bot are in charge of different tasks, such as: data gathering, strategy backtesting, signal serving, data import/export to remote services, neural network training, automatic generation of documentation, etc.
This scalable architecture allows Kumodroid Bot to grow in complexity regarding its data sources, strategies and signal serving to its users.
Data
The data module extracts data from different APIs, such as price data from exchanges, or text from social networks to perform sentiment analysis. All the data extracted is then transformed into data structures that are compatible with any of the existing strategies. This means that any change to the data sources will never result in issues with existing strategies, and existing strategies could immediately benefit from these changes.
This module is also in charge of performing any preprocessing operations on the raw input data.
Trading Symbol Selection
The list of symbols that are traded by Kumodroid Bot are selected based on the symbols traded volume in the past 24 hours. As these values can change over time, the list of symbols will be updated from time to time in order to reflect a list of the most traded symbols in the exchanges where the bot is currently trading.
This decision was taken in order to guarantee enough liquidity to perform trades as fast as possible, and also because markets with high trading volumes tend to be less prone to periods of unusual high volatility [2].
Currently, the list of supported symbols is as follows:
BTC/USDT
SOL/USDT
SUI/USDT
ADA/USDT
XRP/USDT
TRX/USDT
FTM/USDT
ETH/USDT
FET/USDT
BNB/USDT
MKR/USDT
DOT/USDT
XLM/USDT
AVAX/USDT
CRV/USDT
PT/USDT
UNI/USDT
AGLD/USDT
ATOM/USDT
ACT/USDT
Strategies
Kumodroid Bot is designed to work with multiple strategies. The strategies follow different “schools of thought”: technical analysis, machine learning, fundamental analysis, etc. And at the same time, each of these strategies have their own particular design: different technical indicators, different machine learning algorithms, etc. Furthermore, as the components of these strategies are parameterized, the bot generates different versions of these strategies. This means that Kumodroid Bot is constantly backtesting dozens of versions of strategies ranging from deep learning neural networks to conservative moving average-based strategies.
Every strategy is designed to receive as input a heterogeneous dataframe, which can consist of different kinds of data, such as of prices, support and resistance levels, and sentiment analysis data; and as an output, the strategy needs to provide an action, a take profit, and a stop loss.
As a minimum, the strategy action should be either a BUY or a SELL signal, and it can provide more complex actions such as canceling all open positions, increasing or decreasing open positions, or simply doing nothing.
The take profit and the stop loss are price levels for the market that is being predicted by the strategy.
Even though Kumodroid Bot provides a number of strategies that use technical indicators as their main prediction mechanism, the aim of the bot is to provide robust prediction models based on machine learning algorithms.
Strategy Format
Strategies are defined by two files: a python file, specifying the logic of the strategy; and a TOML file, specifying configuration parameters for the strategy. This design provides flexibility to the strategy, as each strategy can specify its “needs”, such as what data sources to use, the parameter ranges for its technical indicators, among others; and at the same time, it provides a standard structure for all the strategies, in order to ensure compatibility with the other components of the bot. As a result, a strategy that uses neural networks will look very similar to a strategy that uses technical indicators. This simple and flexible design allows the creation of a domain specific language (DSL) that can be used by the user to design their own strategies in an intuitive way.
Neural Networks
Deep reinforcement learning is used as the training mechanism for the neural network-based strategies in Kumodroid Bot, as this algorithm has proved to achieve more generalized and better performing prediction models [1]. In particular, Proximal Policy Optimization (PPO) was chosen, as it has been demonstrated to provide a balance between exploration and exploitation when finding an optimal solution.
The neural network models that are used in production are the result of lengthy training sessions. The models that are saved are the ones that perform the best in a validation dataset, consisting of thousands of data points.
The strategy file for a neural network-based strategy will usually consist of just a call to the neural network model (saved to disk as a PTH file) using the provided input data, and then a return of the model’s prediction (an action, a take profit and a stop loss).
Technical Indicators
Kumodroid Bot uses Python’s talib to create its technical indicator-based strategies. Unlike the strategies that use neural networks, these strategies need to provide a relatively more complex logic. This logic needs to define how a buy or a sell signal will be triggered, as well as what the take profit and stop loss will be. The calculation of these outputs will require expertise in the field of technical analysis, as well as a valid choice of technical indicators, as not all of them can help to determine a take profit and a stop loss, for example.
The TOML configuration file associated with each of a technical indicator-based strategy is responsible for providing the range of possible values for the technical indicators to be used. For example, the following configuration:
[optim_params.ti.stoch] fastk_period = [ 4, 10, 2,] slowk_period = [ 2, 10, 2,] slowd_period = [ 2, 6, 2,] buy_threshold = [ 10, 20, 10,] sell_threshold = [ 70, 80, 10,] [optim_params.ti.rsi] period = [ 4, 8, 2,] buy_threshold = [ 10, 30, 10,] sell_threshold = [ 70, 90, 10,]
specifies the value ranges for a strategy that uses two technical indicators: RSI and Stochastic Oscillator. Kumodroid Bot will use the values in brackets to backtest different value combinations for the parameters. For instance, in the case of fastk_period, the bot will use the values 4, 6, 8 and 10, as it’s being specified to try the values from 4 to 10, using a step of 2. Using this configuration, Kumodroid Bot would end backtesting 6,480 combinations for this strategy.
Currently, the bot covers strategies that use the following technical indicators:
Stochastic oscillator
CCI
RSI
MACD
Moving averages
The values for the parameters are determined using a metaheuristic, such as a genetic algorithm. If the number of combinations to backtest is relatively low, a brute-force algorithm is used instead.
Sentiment Analysis
One of the data sources used by Kumodroid Bot is sentiment analysis data. This data is extracted from multiple web sources, which include social networks such as X (Twitter) and Reddit.
The data is scraped using specialized libraries, like tweepy for X, or BeautifulSoup in the cases of not existing such specialized libraries for the web sources being scraped. Then, after retrieving and storing this data, the data is processed using TextBlob to calculate polarity and subjectivity scores.
Kumodroid Bot retrieves the sentiment analysis scores that are relevant for the symbols being predicted, and applies a decay algorithm to assign different weights to the scores according to their age. This way, the older the data, the less relevant it is for the predictions. The data is fed to the neural network in addition to other data sources.
Risk/Reward
After backtesting thousands of strategies, in the end, the ones with the best risk/reward are chosen to serve signals to the user. The risk/reward is calculated in terms of the predicted take profit and stop loss, as well as the score obtained by the strategies by trading a validation dataset.
This way, Kumodroid Bot is answering the questions: which strategies are performing the best, and which ones are promising the most reward and the least risk.
Backtester
The backtester takes each of the strategies and runs a simulation for each of the currently supported symbols. An input dataset is provided to the strategy in order to perform trades, which are opened whenever the strategy outputs either a BUY or a SELL signal, and are closed whenever a take profit or a stop loss is hit. The input dataset consists of data that was not used for training a strategy.
JSON files are generated by the backtester, containing data that can be used to determine what strategies to be used to serve signals to the user, or to generate utility assets, such as trade plots, like the one below.
These plots are mainly used for debugging purposes, for ensuring that the strategies’ trades are consistent with the final results, but the data used for generating these plots can also be served to the user via our API, if needed.
API
The Kumodroid Bot API uses an authorization schema based on JWT. This approach was chosen in order to facilitate scalability. Furthermore, a user’s JWT can define different levels of access to the features provided by the bot.
[1] T. Kabbani and E. Duman, "Deep Reinforcement Learning Approach for Trading Automation in the Stock Market," in IEEE Access, vol. 10, pp. 93564-93574, 2022, doi: 10.1109/ACCESS.2022.3203697.
[2] Lee, D. (2015). The Role of Trading Volume in the “Volatility Puzzle”. Asia-Pacific Journal of Financial Studies, 44, 783-809. https://doi.org/10.1111/AJFS.12113.
Last updated