Algorithmic trading for dummies

Algorithmic trading for dummies – part 2

In my previous post I explained the first step in mastering algorithmic trading – choosing a programming language to work with. After some research the obvious choice fell on python. Assuming you watched some python tutorials, you are ready to discuss some python packages now.

Dependencies

What are dependencies, you may ask. I will try to explain with an example: if you are building a car, you would probably need an engine, wheels, seats, doors, etc. You can of course try to build everything from scratch, however that is not the only way to build a car. Instead, you could order each part from a manufacturer that already has these parts.
Same is with python, which has predefined modules organized in packages. When you are building something with python, you don’t need everything that was ever written – you need only those packages that will support your specific project. By adding them, you would be installing your dependencies.

What dependencies we can use?

Fortunately for us, there are already many lines of code that someone was generous enough to already share with us. Here are the packages that I will be using in this tutorial:

  • Numpy – a fundamental package for scientific computing in Python. It is useful when working with advanced mathematical and other types of operations on large numbers of data.
  • Pandas – a package providing fast, flexible, and expressive data structures designed to make data analysis both easy and intuitive.
  • Requests – a package that allows you to send HTTP/1.1 requests extremely easily.
  • Xlsxwriter – a module that can be used to write text, numbers, formulas and hyperlinks to multiple worksheets in an Excel 2007+ XLSX file.
  • Math – a module that provides access to the mathematical functions defined by the C standard.

Keep in mind that these are only several modules/packages out of the thousands available. You can also write your own unique code, add it to modules/packages, and share with others.

Installing dependencies

To install the upper mentioned dependencies, you should use the “pip install” command in the terminal window. Follow these steps for each dependency:

  • Numpy – pip install numpy
  • Pandas – pip install pandas
  • Requests – pip install requests
  • Xlsxwriter – pip install xlsxwriter
  • Math – pip install python-math

Using dependencies

Now, after installing the prerequisites, we can start using the modules and functions stored in these powerful python packages. Before we use any of the stored functions in these packages, we shall import them into the environment of out project.

As seen in most courses and tutorials, Python code can be written in various IDEs (Integrated Development Environments) and code editors. I personally use PyCharm as my main IDE, since it allows easy editing and simple execution. Sometimes I use Jupyter notebooks to organize prototype code and quickly test it.

The following code snippet is what we type when we want to import the installed dependencies into our project:
Installing dependencies

What’s next?

We have installed and imported all the packages that we would use in our project, but we are still missing something before we could start coding at full speed.
Algorithmic trading requires importing data, analyzing it, and eventually executing orders. Therefore, in my next post, I will show you how to retrieve external data.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *