Home Creators Posts Import Register Favorites Logout

Content

In this post I will give you the complete and simple ‘playbook’ that you can follow to install the Freqtrade bot, including the AI capabilities.I presented this playbook also in my Youtube video: https://youtu.be/D5IJUrxziII?si=I4ng71Tws4LrvS6I

Hardware & software requirements

According to the Freqtrade website at https://www.freqtrade.io/en/stable/, the following hardware and software requirements are:

Hardware requirements

  • 2GB RAM
  • 1GB disk space
  • 2vCPU

Personally I think that these hardware requirements are very limited and I doubt that the AI will work nice and smoothly with this setup.

Software requirements for a scripted installation:

  • Python 3.8+ (full support for Python 3.11 as of version 2023.5)
  • pip (pip3)
  • git
  • TA-Lib (although this is also installed by the script)
  • virtualenv (recommended)

Software requirements for a Docker installation:

  • Docker
  • Docker-compose

Regular installation of Freqtrade with AI

I follow the installation instructions given at the following location: https://www.freqtrade.io/en/stable/installation/

It is almost 100% similar to a regular freqtrade scripted installation. The only difference is the choice to install AI and PyTorch during the setup questions.

Update repository and install packages:

sudo apt-get update
sudo apt install -y python3-pip python3-venv python3-dev python3-pandas git curl

Download the freqtrade github repository

git clone https://github.com/freqtrade/freqtrade.git

Move into the downloaded freqtrade directory, checkout the stable git branch and create a Python virtual environment:

cd freqtrade
git checkout stable

Then start the installation script

./setup.sh -i

During the installation, there will be questions asked to install additional capabilities. You should say Yes to at least the AI and Pytorch module installation here!

After everything is installed, you can check the installation with:

source ./.env/bin/activate
freqtrade --help

Docker installation

Before I continue here I would like to note that the Docker installation is not dependent on the scripted installation or that a scripted installation should need Docker to run. You can run these INDEPENDENT FROM EACH OTHER.
I might not have been clear on that in the video I made for Youtube since I got some questions about that. I thought it would be evident, but clearly I was wrong.

THe Docker installation instructions are located at the following webpage: https://www.freqtrade.io/en/stable/docker_quickstart/

Additional information can be found here: https://www.freqtrade.io/en/stable/freqai/#usage-with-docker

I assume that you already have installed Docker and Docker-Compose!

First, create the ft_userdata in a preferred location (I always use the /opt directory for that)

mkdir ft_userdata
cd ft_userdata/

Now download the specific freqtrade AI docker-compose file in this directory:

wget  https://github.com/freqtrade/freqtrade/blob/develop/docker/docker-compose-freqai.yml

You can now download the Docker  image with:

docker-compose pull

After the Docker image is pulled, you can create the user directory structure with the Docker container:

docker-compose run --rm freqtrade create-userdir --userdir user_data

This will set up the necessary freqtrade user directory structure. Just as with the setup script installation.

Downloading the necessary AI enabled files

After the setup or Docker installation is finished, you should now have a user_directory that contains the necessary directory structures and files for the following steps.

Here I will use the scripted setup installation!

First download the freqAI example config to the user_data dir (assuming that you are already in the freqtrade directory of the scripted installation - for the docker installation you should be in ft_userdata):

cd user_data
wget https://github.com/freqtrade/freqtrade/blob/develop/config_examples/config_freqai.example.json

Now you will have to download the AI enabled sample strategy. This file should be downloaded in the strategy dir of the user_data directory

cd strategies
wget https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/FreqaiExampleStrategy.py

Now you have a default config and strategy that are both enabled for AI.

The next step is to test if the installation is correct and AI files are working. If this is not the case, check if everything is downloaded into their respective correct directory.

Running the bot with AI

This is also run in the scripted install of freqtrade!

You should be in the freqtrade directory for this, so change directories if you are not here.

Assuming there are no mistakes, you can do a first run of the bot with command:

freqtrade trade --config config_examples/config_freqai.example.json
--strategy-path freqtrade/templates
--strategy FreqaiExampleStrategy --freqaimodel LightGBMRegressor

Note: Docker users should use the next command structure here:

docker-compose run --rm freqtrade …

You should now see a lot of output on your screen, like downloading data, testing models and more. See my youtube video to check out how this should look on your screen.

You can stop the bot with Ctrl+C and continue with the next step…

AI enabled Backtesting

Before continuing with the backtest, we have to first download the necessary backtesting data.

Use the config file to determine the pairs and use the timeframes and time range options to get the data of the correct time frames/time range. The command I used, based on these settings is:

freqtrade download-data --config config_freqai.example.json --timeframes 3m 15m 1h --timerange 20210101-20210701

THis should download the data for the configured pairs in the example.json for the given time frames and time range. If backtesting should give any problems, then check the errors in the output. It might well be that there should be other timeframes and/or longer time ranges downloaded.

Also download more (earlier) backtest data than your actual backtest period since this additional data is used for training the model.

Now start a backtest to see of this is working also:

freqtrade backtesting --strategy FreqaiExampleStrategy --strategy-path freqtrade/templates --config config_examples/config_freqai.example.json --freqaimodel LightGBMRegressor --timerange 20210501-20210701

You will see the model training and after a while there should be backtesting output with results. If this is the case, then the AI enabled environment is ready for further use and you can start creating your own AI enabled strategies.

Good luck and until the next post on Patreon!

Comments

No comments found for this post.