Skip to content


Algorithmic Trading or algotrading is trading using algorithms. Although in modern days, most people do immediately associate this with the use of computers, it does not need to be so.

Focusing on the algo part, the first definition of algorithm which can be found on is:

A set of rules for solving a problem in a finite number of steps, as for
finding the greatest common divisor.

No computer is actually needed to apply of a set of rules, which can also be done with pen and paper or in a hypothetical example by reading the news as in

Buy stock X each time positive news are in the press and sell it two days

The important part here is that algo in algotrading is telling you that your trading has to be done according to a set of rules that you will define. As such:

  • You can choose to use a computer, but you don't have to.

  • You may want to work in a very specific algotrading domain, but you don't have to

  • You can decide to work with a weekly timeframe, but you may also do that on a 30-minutes basis

  • You may use the algorithms, and with it the rules used to define them, to give you the power to make the final judgmental decision

In any case, the focus here is the the use of a computer to execute the algorithms and find patterns in the prices which one can benefit from. An algorithm is also known as a strategy in the algotrading world and it will be referred as such.

Even when one limits algotrading to the computer domain, if one as a newcomer asks for advice as how to start, for example in Reddit algotrading, the answer which may be received can well look like this

You have no chance, unless you use modern C++ and co-locate directly at
the Exchange and you will still probably have to bypass the network drivers
of the operating system to gain some extra nanoseconds in your order
delivery mechanism

Every grandmother around the world could quickly identify this as an answer which has nothing to do with what the poster is asking and is looking for and it is for sure not a helpful one. It is simply an example of humanity itself: everyone tends to see things through your own eyes. And so is the case with the poster providing such an answer.

The answer is actually talking about High Frequency Trading (or HFT), one of the most well known, yet highly specialized, algotrading domains, in which one competes to be the faster to take advantage of micro price movements and/or price irregularities. Such an answer would be good if one wanted to offer advice about how to compete (or the impossibility of) in the HFT arena against well established players like the Goldman Sachs boys.

HFT is not the only form of algotrading. There are other trading approaches which fall under this category such as: Bid/Ask or Spread trading, simple time series trading, news based trading, arbitrage and others.

Things that will be considered in this algotrading notes:

  • Define the set of rules that will be the guideline for algotrading development, namely:

    • House Rules
    • Entry Rules
    • Exit Rules
    • Sizing Rules
    • Analysis Rules
    • Backtesting Rules
  • Present backtrader, its features and how to:

    • Load OHLC (Open-High-Low-Close) data.
    • Define a working setup for backtesting a strategy against the data
    • See where the set of rules apply and where can be applied, i.e.:

    • Apply the entry, exit

    • Apply sizing rules and see how this affect the entry/exit setup
    • Apply analysis rules to be able to decide if a strategy is fit for the
    • purpose
  • Show examples of sample strategies along the way

And this is what is not in:

  • A winning strategy

    Even if some of the examples in the book make money, this is just for the presented period of time and likely not to hold for other periods of time

  • Bid/Ask (aka Spread or Order Book) trading

  • HFT trading

    The approach presented in the book does not prevent using any of the strategies developed using the approach to be applied to HFT, but in the world of HFT time periods occurr are measured in very small timeframes. Taking into account that the technology in this book is based in the programming language Python and given its speed, HFT can be ruled out.


    The approach and tools can stil be used for rapid prototyping of ideas

  • Options Trading if it goes beyond managing a given option as an OHLC series