Python Trading – 5 – Creating a Conda environment

Since I started to lookup Python solutions for automated trading, I have found several dozen different ways to do it – but so far there seems to be no one-fits-all solution for different brokers.

 

It looks that Interactive Brokers is the biggest player here. Some resellers are using the IB infrastructure.

 

FXCM has a REST API, that looks promising. But would I like to learn something that requires to stay with FXCM?

 

There are dozens of frameworks, APIs, wrappers and they all have different advantages and disadvantages. One of the biggest disadvantages – at least in my eyes – is when you pick something that will only work for backtests.

 

Some solutions already have the status “discontinued”. Yes, they might have a big and active community, but would you invest your time to learn something that is already discontinued?

 

From Tony Robbins I learned that “success leaves clues”. So I try to find something that fits my needs.

 

In Metatrader4 and Metatrader5 I have a graphical interface, I have an integrated IDE, a complete set of precoded indicators, a strategy tester, a language that was developed for exactly what I want to do, including a reference and context based helpfile.

 

For Python the closest thing that I have seen so far is the Anaconda distribution.

 

The German Wikipedia Site for Anaconda calls it a “Freemium Open Source Distribution for the programming languages Python and R. It contains the IDE (integrated development environment Spyder and the web based Jupyter system that runs in each webbrowser.

 

As Anaconda is available for Windows, Linux and Mac, it is something that should work for almost every user.

 

There is also an included package manager called conda. So I guess I will use Anaconda, at least for the next few weeks.

 

Both Udemy courses that I have bought also use this environment, so I think this is the right choice.

 

So I looked for a Python trading solution that uses Anaconda and here is what I found:

Okay, I have done that before. The documentation looks nice, so let’s try to get the environment up and running.

 

To do that, I need to download the yml file, open an Anaconda command prompt and type in the command to set everything up. In my case the file is located in a new folder called fxcm on my e: drive.

Now – everything fails. There are some dependencies that can not be resolved.

Okay, let’s find out how to solve this problem.

 

First we need to update conda with the following command:

conda update conda

After we have confirmed the procedure, conda is downloading some files.

 

Now the version has been updated from 4.5.12 to 4.6.2

With the following command we can get all available Python versions:

 

conda search “^python$”

Now I want to create an environment called FXCMAPI using the version 3.7.2, so I run the following command:

 

conda create -n FXCMAPI python=3.7.2 anaconda

 

Here is the output:

After I have confirmed my choice, several files are downloaded and installed:

Once done, I can activate my new environment by using the following command:

 

activate FXCMAPI

Now my command prompt in the Anaconda Prompt window changes and it shows me the new environment in round braces.

 

Okay, so now I have created my new environment to use the FXCMAPI, in the next few steps we need to find out how to actually use it.

 

At this stage I can’t imagine to get this whole Python trading thing to the level where I am with MQL4 and MQL5.

 

Right now I am running a multi level backtest – 100 threads with a risk setting of 20 and an account balance related lot size on 16 cores for 10 years in Metatrader5 – with a random entry.

 

And I do it for over a dozen currency pairs. If you are interested, you can watch the video for 200 years of backtesting on one of my Youtube channels (just look for ”robottradingsystem 200 years” on YouTube).

So far I have never seen something like this in Python, but I will keep on trying, because I think that Python trading is a good solution – if I am able to do what I already did in MQL4 and MQL5…