This project presents how the Kraken trading bot I previously developed was trained and how the optimal set of parameters was selected.
This is an educational project, not a real investment strategy or advice, and I take no responsibility for any financial losses or misuse of this code.
- Python 3.6 or Higher
- Kraken's Python API client
krakenex(set-up described below) - Script
algorithm.py - Script
evaluate_algorithm.py - The cryptocurrency price history data stored in a parent folder
- Install
virtualenvif it is not already installed
pip install virtualenv- Create virtual environment in your folder of interest
virtualenv krakenex- Activate the virtual environment
source krakenex/bin/activate- Install the required libraries in the virtual environment using the
requirements.txtfile
pip install -r requirements.txtsource krakenex/bin/activateThe cryptocurrency price history data used to simulate trading was stored in the parent folder and was made of the complete trade history available on Kraken. Please refer to my crypto history extraction project if you want to extract the history data on your own.
The scripts algorithm4.py and algorithm5.py were provided as examples of training codes, but in practice, several other
scripts were used with different time frames and parameter sets, to test several different algorithms and algorithm versions,
as detailed in Code_Specifications.txt. The present instructions will only detail the use of the script algorithm5.py.
The modules utilities.py and query_public_info.py from the package tradingbot are used by the scripts algorithm4.py
and algorithm5.py to provide different utility functions.
The script evaluate_algorithm.py processes the output files of the algorithm benchmark and selects the optimal set of
parameters for profit generation.
pipeline_parameters.txt: File that contains the different parameter combinations for the algorithm benchmark. Generated byalgorithm5.py$CRYPTO_records.txt: File that contains the algorithm trading decision history for the cryptocurrency$CRYPTO. Generated byalgorithm5.pyalgorithm5_ranked_results.txt: File that contains the algorithm profit results for each parameter combination. Generated byevaluate_algorithm.pyalgorithm5_benefit.png: Graph that shows the average gains / losses / net benefit per day for the top 10 parameter sets. Generated byevaluate_algorithm.pyalgorithm5_total.png: Graph that shows the total gains / losses / net benefit for the top 10 parameter sets. Generated byevaluate_algorithm.py$CRYPTO_balance_evolution.png: Evolution of the base currency balance over time based on the trading results for the cryptocurrency$CRYPTO. Generated byevaluate_algorithm.py
You will need to specify the fiat base currency as the value of the variable base_currency in the script algorithm5.py
which is set to ZEUR by default which stands for the Euro.
You can define the list of cryptocurrencies you want the trading bot to speculate on with the variable currencies in the
script algorithm5.py. The pairs should also be specified with the variable all_pairs.
The available base currency balance per cryptocurrency is defined by the variable funds.
The following parameters were assigned various values, and all combinations of these values were tested by simulating trades:
drop_rate: Price drop percentage value over adrop_time_framethat will trigger a buy orderdrop_time_frame: History time frame on which the price drop is assessed, e.g. adrop_rateof 2% will trigger the buy condition only if the price dropped by at least 2% on this specified period of timeend_tendency: A price dropping tendency will be considered over after the price raised of this specific percentage. E.g. if the price drops for a while and then increases of 2%, the dropping tendency will be considered as finished. The buy condition will be triggered only after the dropping tendency finishesmin_benef: The trading bot will only sell a cryptocurrency if it made at least this percentage of benefithistory_regression: History time frame on which the price trend and direction is assessed
Launch the cryptocurrency trading bot with all the parameter combinations on the cryptocurrency price history
A simple Python command will launch the benchmark:
python3 algorithm5.py # To test the algorithm 5The benchmark script tests several parameter combinations over a large history. Therefore, I recommend running it in a
detached terminal state. You can use the terminal multiplexer Screen for this purpose.
The following command uses the output of the previous benchmark to generate graphs and statistics, thereby enabling to select the most optimal parameter values for the selected algorithm:
python3 evaluate_algorithm.pyThe overall best strategy is to select the algorithm with the highest total net benefit per day. In the case of this project,
the algorithm was developed during a bull run, and trained on a short bull run period in order to optimize the short term
profits. The algorithm is therefore designed to run only during a bull run period, as it focuses on high fluctuations. If
you want more details regarding my algorithm development history and strategy, you can examine the file Code_Specifications.txt.
Based on the graph algorithm5_benefit.png the most optimal parameter sets can be selected:

Based on the graphs per crypto, as shown in the below example, algorithms that tend to trade more regularly can be selected:
The purpose of selecting an algorithm that trades more regularly is to adapt the strategy to the short duration of a bull run.
- Start Date: September 2020
- Completion Date: December 2020
- Maintenance status: Inactive