Algorithmic trading: what it is and how it works

Algorithmic trading is buying and selling with a computer program that follows set rules. The rules say what to trade, when, how much and at what price, and the program places the orders without a person clicking each one. Big firms use it for speed and scale, while individual investors mostly use it to follow a plan without emotion.

Key points#

  • An algorithm is a step-by-step recipe. In trading, it turns data into orders.
  • Common types include trend following, mean reversion, arbitrage, market making, execution algorithms and high-frequency trading.
  • Banks, hedge funds and market makers use algorithms for much of their trading. Individuals can use them too, through broker software and APIs.
  • Algorithms can fail fast. A single sell program helped set off the “flash crash” of May 6, 2010.
  • A rule run by a computer is still only as good as the rule. Test it before you trust it.

What is algorithmic trading?#

Algorithmic trading is trading where a computer program decides and places orders by following written instructions. “Algo trading” is the short name for the same thing.

An algorithm is a recipe a computer can follow exactly. The SEC staff describe it as a problem-solving method that can be written as a computer program (SEC staff report, 2020). In trading, the recipe answers questions like these:

  • What should I hold?
  • How much of it?
  • When should I buy or sell?
  • At what price, and through which market?

A simple trading algorithm might read: “Every day after the close, check whether the S&P 500 fund is above its 200-day average. If it is, hold it. If not, hold a Treasury bill fund.” The 200-day average is the average closing price over the last 200 trading days, about ten months.

How does algorithmic trading work?#

Algorithmic trading works in a loop: read data, check the rules, send orders, and repeat on a schedule. That schedule can be once a month or many times a second.

  1. Data comes in. Prices, volumes, and sometimes economic numbers or news.
  2. The rules run. The program checks its conditions and works out what it should hold.
  3. Orders go out. It compares what it should hold with what it does hold, and trades the difference.
  4. A broker fills the orders. Most programs talk to a broker through an API, a channel that lets software send orders and read account data.
  5. Someone watches. Good setups have limits and alerts, so a broken rule cannot trade without end.

What are the main types of trading algorithms?#

Trading algorithms fall into a few families. Some try to profit from where prices go. Others try to trade cheaply or provide a service to the market.

TypeWhat it doesTypical speed
Trend followingBuys what is rising, steps aside when the trend breaksDays to months
Mean reversionBets that a price that moved too far will move backMinutes to weeks
ArbitrageTrades tiny price gaps between related things, like a fund and the stocks inside itSeconds or less
Market makingOffers to buy and sell all day and earns the small gap between the two pricesMilliseconds
Execution algorithmsBreak a big order into small pieces to avoid pushing the priceMinutes to hours
High-frequency tradingMany small trades held for seconds or less, often a mix of the aboveMicroseconds to seconds

The first two try to guess direction. The middle two try to earn small, steady amounts from how markets work. Execution algorithms do not decide what to buy at all. A pension fund that has already decided to buy $50 million of a stock might use one to buy it slowly over a day.

Who uses algorithmic trading?#

Mostly professionals. Market makers, banks, hedge funds and big asset managers all trade through algorithms. The SEC staff found algorithms are used everywhere in today’s stock and bond markets (SEC staff report, 2020).

Individual investors use them in two main ways. Some write code that connects to a broker’s API. Others use tools that let them build rules without code and then run those rules on a schedule. A person who designs these rules for a living is often called a quantitative trader.

What is quantitative trading?#

Quantitative trading means using data, statistics and math to decide what to trade. Algorithmic trading is about a computer carrying out the plan. The two overlap a lot: most quant strategies run as algorithms, but an algorithm can also run a plan with no math behind it.

Our quantitative trading guide, listed in the series below, covers the job itself, the skills and the pay.

A worked example#

Say you have $10,000 and you write this rule, checked once a day after the market closes:

  • If the S&P 500 fund is above its 200-day average, hold 100% of it.
  • If it is below, hold 100% in a Treasury bill fund.

Most days, nothing happens. Then one day, after a long slide, the fund closes below its average. The next time the program runs, it sells the stock fund and buys the bill fund. Months later, the fund climbs back above its average, and the program switches back.

The rule never feels fear or hope. But it can still be wrong. In a choppy market, it may sell low and buy back higher several times. A backtest shows how often that happened in the past. The 200-day moving average strategy is this exact rule, with its full hypothetical record.

What happened in the 2010 flash crash?#

On May 6, 2010, major US stock indexes were already down more than 4% for the day. Then they fell another 5% to 6% in minutes and bounced back almost as fast (SEC and CFTC staff report). Over 20,000 trades in more than 300 securities went through at prices more than 60% away from where they had been moments before.

The joint SEC and CFTC staff report traced the start to one large seller. A mutual fund company used an execution algorithm to sell 75,000 stock index futures contracts, worth about $4.1 billion. The algorithm was set to keep pace with trading volume. In the report’s words, it sold “without regard to price or time”. On a stressed day, it sold in about 20 minutes what had taken more than 5 hours on an earlier day. Fast traders then passed the contracts back and forth, and buyers pulled back.

The lesson for anyone running an algorithm: a rule that ignores price can do great harm when markets get strange. Add limits.

How is algorithmic trading regulated?#

In the US, algorithmic trading is legal, and the firms that do it are regulated like other trading firms. A few rules focus on algorithms in particular:

  • FINRA guidance (2015). FINRA told member firms how to supervise trading algorithms. Its advice covers risk checks, code testing, trading controls and the ability to shut a strategy down (Regulatory Notice 15-09).
  • Registration (2017). The person mainly in charge of designing or changing a broker’s stock trading algorithm must pass an exam and register (Regulatory Notice 16-21).
  • SEC review (2020). Congress asked the SEC staff to study algorithmic trading. Their report covers its benefits and risks in stock and bond markets.

FINRA keeps its notices on one algorithmic trading page. Regulators also warn the public. The CFTC says fraudsters use AI hype to sell trading bots with promises of huge, sure profits (CFTC).

Does algorithmic trading work?#

It can, but there is no promise it will work for you. An algorithm removes emotion and follows a rule exactly. It does not make a bad rule good.

Speed-based strategies like market making depend on costly technology, so individuals rarely compete there. Slower rules, like trend following across a few funds, are within reach. But they have long dry spells, and many that look great in a backtest do worse with real money.

Common mistakes#

  • Testing too many versions. Try enough rules and one will look great by luck.
  • Forgetting costs. Every trade costs something. Fast rules pay that cost often.
  • No limits. A program with no cap on order size or losses can do real damage, as 2010 showed.
  • Trusting promises. Nobody can sell you a bot that wins for sure.
  • Never checking. Data feeds break and brokers change their APIs. Look at what your program did.

Guides in this series#

Getting started

Measuring results

Strategy families

Try it on Tactfolio#

Tactfolio is built for slow, rules-based quant investing. It does no high-frequency trading. You build a strategy from blocks in the visual builder, such as a check on whether a fund is above its average. On US stocks and ETFs it runs once a day or less, on daily prices. It is long only, with no short selling or borrowing. You can backtest it, run it on paper, or let it trade your own Alpaca account with your own API keys, as a rules-based trading bot. Each strategy trades only the starting balance you give it. To see how other tools compare, read the best algo trading platforms for retail investors.

Common questions#

What is algorithmic trading in simple terms?#

It is trading where a computer follows a set of rules to decide and place orders. You write the rules once, and the program applies them every time it runs. People also call it algo trading or automated trading.

Yes. In the US, algorithmic trading is legal, and firms that do it follow the same market rules as everyone else. FINRA also has rules on supervising algorithms and on registering the people who design them at brokers.

Is algo trading profitable?#

Sometimes, but there is no promise. Professional firms spend heavily on data, people and speed. For individuals, slow rules can help you stick to a plan. Many still lose money once costs are counted, or because their backtest was luck.

Can beginners do algorithmic trading?#

Yes, if they start slow and small. A simple rule checked once a day or once a month is a good first step. Test it on many years of prices, run it on paper first, and only then use real money.

What programming language is used for algo trading?#

Python is the most common choice for research and slower strategies. High-frequency firms also use faster languages such as C++. You can also build rules without code in some tools.

Sources