The views and opinions expressed in this blog are those of the authors and do not necessarily reflect the official policy or position of SnoQap, any other agency, organization, employer or company. Assumptions made in the analysis are not necessarily reflective of the position of any entity other than the author(s). These views are subject to change and revision.

The Quickest Way to Your First Trading Algorithm

The Quickest Way to Your First Trading Algorithm

Originally published on September 8, 2016

Genetic Algorithms are fundamental tools that can help you develop your first trading ideas. But wait, what is an algorithm and why does it matter? This is important because algorithms are different than systems, matrices, strategies, and models. An algorithm is any set of rules, essentially a defined process, that yields a result. The name algorithm itself comes from a Persian mathematician, astronomer, and geographer who developed a technique for performing arithmetic with Hindu-Arabic numerals. It’s important to understand algorithms because they have really have started to dominate the world that we live in. Any type of search that you do on the internet is probably driven by an algorithm, but so are the ads that you see, some of the designs for the products you use daily, and in many cases the way you start your car, just to name a few. Spotify is one of my favorite examples of how algorithms work. They helped to give the algorithm the stage in the music industry when they developed a better way of shuffling songs than with a traditional “random shuffle”. If you are interested, here is a really interesting article on how it works. And don’t even get me started on how Facebook handle’s their information algorithms. but the point is that an algorithm’s job is primarily to handle decision making.

It’s not very different in certain areas of finance. A long time ago (around the 1970’s with the introduction of the DOT and SuperDOT on the NYSE), Investors had strategies that determined what big banks and hedge funds did with their money on relatively more liquid markets. Today, many, but not all of these decisions can be made by computer algorithms, commonly referred to as algorithmic trading or planning. Now, let’s apply this to trading and investing. How can understanding algorithms help you to become a better investor? Well, the first things you should look at are the things that you have control over.

There are three fundamental things that you get to decide when investing or trading, and they are:

  • When to buy

  • When to sell

  • And the magnitude of each (expressed in a percentage of or currency)

These can be the fundamentals of your approach when coming up with a trading strategy. You can develop rules that can be as simple as “I will never buy with more than X% of my buying power at any time” or “I will only buy into the market when the S&P Price-to-Earnings is 10% below its SMA” or “I will only buy on Wednesday”. The point is that you start with something, with anything, because this is the foundation that lets you find what will actually work for you.

I’d also like to mention that you are doing exactly what big banks and investment firms buy computers to do. You are executing on a set of ordered instructions that you create for yourself. You are disadvantaged in two particular ways here that you should be aware of:

  1. You can’t put in orders as quickly as a computer (which can place an order in the same time that it takes light to travel from third base to home plate)

  2. You do not have access to the amount of information that large banks do, and even if you did, you would not have the time available to digest all of it, and then place trades on it.

So this means that you’re not looking for a strategy that goes head to head with large banks. Your goal can’t be to read as much about the markets as possible and hope to buy and sell based on news before others do. There are programs that banks use to scan every financial document a company produces, analyze every number on the financial statements, and then make trades based on that information (not to mention a few other bits of information from all over the internet). In short, you will probably lose every time when you try to beat large firms.

But that’s okay, you can still make money. Finding out how is the fun part. So, the next question, “What makes an algorithm ‘genetic’?”. This is where things get pretty interesting.

Take, for instance, this discussion by economist Tim Harford:

So let’s say you want to make detergent, let’s say you’re Unilever, and you want to make detergent in a factory near Liverpool. How do you do it? Well. You have this great big tank full of liquid detergent, you pump it at high pressure through a nozzle to create a spray of detergent, the spray dries on a wall near the nozzle and turns into powder and falls to the floor. You scoop it up and put it in cardboard boxes and you sell it to the supermarket and make lots of money.


How do you design the shape of the nozzle?

If you ascribe to the idea that humans are usually intelligent, you get a bunch of really smart people together who use mathematics and engineering to design the nozzle.

Well, Unilever did this, and it didn’t work.

After some time, a geneticist that worked for Unilever came up with the solution. How did he do it? Trial and error. He developed ten different variations of the nozzle and tried them all out. The one that worked the best was then taken and ten derivations of that nozzle were created and tested. This was done many times over, producing a nozzle that did exactly what it was supposed too. The funny part? It looked nothing like a nozzle and none of the scientists or engineers knew why it worked. The point here is that it’s important to fail and practice this stuff (usually without actually risking your own money).

This is how a genetic algorithm works. It gets better and better over time based on the results it produces, based on empirical trial and error. This means that you have to approach your trading and investing ideas in a systematic, rule based way. This is one of the tool’s that IBM’s Watson has at its disposal, making it adapt to complex situations. You don’t have to be as fast as Watson to make a few extra bucks though. This takes a lot of time, and for most it’s much better to go the Ben Graham/Warren Buffet route. The risk here is often not worth the reward, but if you are interested, it could be exciting!

How Lin-Manuel Miranda and Hamilton Caused a Modern-Day Political Revolution

How Lin-Manuel Miranda and Hamilton Caused a Modern-Day Political Revolution

Actions Speak Louder than Words: The Problem of Russian Cyber Intervention

Actions Speak Louder than Words: The Problem of Russian Cyber Intervention