Skip to content
Course contents
From analysis to automation

Execution is not analysis

Algorithmic trading is the automation of execution, turning a rule into live orders, and that is a different and harder thing than the analysis and backtesting you already know. This chapter separates the two, previews what the course builds, and sets the honest expectation that automation is a tool for discipline and scale, not an edge.

9 min readChapter 1 of 28
What you will learn
  • Define algorithmic trading as automated execution and distinguish it from analysis and backtesting
  • Preview the components an automated system needs
  • Understand that automating a losing idea only makes it lose faster

In Python for Trading you built a strategy and tested it on history. You wrote a rule, a moving-average crossover, ran it over past prices, and, tested honestly, watched it lose money. That backtest was analysis: reading data at your leisure, on a laptop, with nothing at stake. Algorithmic trading is what happens after you decide a rule is worth running for real. It is a program that places live orders in the market, automatically, with your money. This course is about that second thing, and the first lesson is that it is not the same as the first thing, and not as easy.

The gap between a signal and a trade

Algorithmic trading automates the execution: a signal becomes a live trade only across a gap of orders, timing, reliability, and risk. Automation is discipline and scale, not an edge.
Algorithmic trading automates the execution: a signal becomes a live trade only across a gap of orders, timing, reliability, and risk. Automation is discipline and scale, not an edge.

A backtest hides an enormous amount of work behind a single line of arithmetic. When your code wrote position = signal.shift(1), it quietly assumed that wanting to be long and being long are the same event. Live, they are not. Between the rule saying "buy" and you actually owning the shares sits a whole sequence. Your program has to send an order to the broker. The broker has to accept it. The exchange has to match it against a seller. You get filled at whatever price is available at that instant, not the one you saw. And you pay a cost for the trade. Only then do you have a position. Every step can be slow, can fail, or can happen at a worse price than you imagined.

ExampleAnalysis is a column of signals; execution is a sequence of orders, fills, and costsch01/signal_vs_execution.py
# Analysis produces a signal: a column that says "be long" or "be flat".
# Execution is the separate, harder work of getting there: you act on the NEXT
# bar, not the one that produced the signal, and every change of position pays a
# cost. This example shows the two side by side on five days of one stock.
import pandas as pd

# Five days of an illustrative stock close, in rupees.
close = pd.Series([1400, 1410, 1395, 1420, 1440],
                  index=["Mon", "Tue", "Wed", "Thu", "Fri"])

# THE ANALYSIS. A toy rule from the earlier courses: be long when the close is
# above its own 2-day average. This gives one signal per day.
avg2 = close.rolling(2).mean()
signal = (close > avg2).astype(int)          # 1 = want to be long, 0 = want to be flat

print("Analysis (what the rule wants):")
for day in close.index:
    print(f"  {day}: close {close[day]:>6}   signal {signal[day]}")

# THE EXECUTION. You cannot trade at the close that produced the signal, because
# you only know it once the day is over. So you act on the next day, at the next
# day's price, and you pay a cost every time the position changes.
cost_rate = 0.001                            # 0.1% per trade, illustrative
position = signal.shift(1).fillna(0)         # act on YESTERDAY's signal
changes = position.diff().fillna(position)   # non-zero on the days you trade

print("\nExecution (what actually has to happen):")
total_cost = 0.0
for day in close.index:
    if changes[day] != 0:
        cost = close[day] * cost_rate
        total_cost += cost
        target = int(position[day])
        print(f"  {day}: move to position {target:>2}, "
              f"traded at {close[day]}, paid cost {cost:.2f}")
print(f"\nTotal execution cost over the week: {total_cost:.2f} rupees")
Output
Analysis (what the rule wants):
  Mon: close   1400   signal 0
  Tue: close   1410   signal 1
  Wed: close   1395   signal 0
  Thu: close   1420   signal 1
  Fri: close   1440   signal 1

Execution (what actually has to happen):
  Wed: move to position  1, traded at 1395, paid cost 1.40
  Thu: move to position  0, traded at 1420, paid cost 1.42
  Fri: move to position  1, traded at 1440, paid cost 1.44

Total execution cost over the week: 4.25 rupees

Look at what the code shows. The analysis is a tidy column: on Tuesday the rule wanted to be long, on Wednesday flat, and so on. The execution is a different creature. You could not act on Tuesday's signal until Tuesday was over, so you entered on Wednesday, at Wednesday's price of 1,395, not the 1,410 that produced the signal. Every change of position cost money, about 4 rupees over the week on these tiny sizes, and far more on real ones. The analysis is a set of wishes. The execution is a sequence of orders, fills at prices you did not choose, and costs. Algorithmic trading is the engineering of that sequence.

So define it plainly. Algorithmic trading, also called algo trading or automated trading, is the use of a computer program to place and manage orders in the market automatically, according to a set of rules. It is not analysis, which is the study of data, and it is not backtesting, which is the testing of a rule on past data. Both of those feed it. Neither of them is it.

What automation actually gives you

Be clear-eyed about what you gain by automating. A program does not predict better than you. It does exactly three things well: it is fast, it is tireless, and it is obedient. It can watch fifty stocks at once and act in the same second, which you cannot. It never gets bored at two in the afternoon and never skips the dull trade that the plan called for. And it does precisely what you told it, every time, without the fear and greed that the Risk and Psychology course spent a whole part on. Those are real benefits, and for a disciplined trader they matter.

But notice what is not on that list: being right. Speed, stamina, and obedience do nothing to make a bad rule good. If your strategy loses money, automating it does not fix it. It just loses money faster, in more places at once, and without you watching. This is the single most important idea in the course, so read it twice.

The honest inheritance

The uncomfortable facts from the earlier courses are not repealed here. If anything they sharpen. The Risk and Psychology course cited SEBI's finding that around nine in ten individual traders in equity futures and options lose money. Automation is not an escape hatch from that number. A computer can act on a bad idea at a scale and speed a human never could, so a careless algo trader can lose faster than a careless manual one, not slower.

The traders who genuinely benefit from these skills are not the ones who rush to automate the first rule that backtests green. They are the ones who use code to test ruthlessly, reject most ideas, and automate only a rare survivor, wrapped in hard limits. That posture, patient and skeptical, is what this whole course teaches.

What this course builds

Over the coming chapters you will build, piece by piece, everything that sits in that gap between a signal and a filled order. You will learn the rules India now places on retail algo trading. You will connect a program to a broker, place and track orders, and keep a reliable record of what happened. You will turn a backtest into a strategy that runs itself, and then wrap it in the live-risk controls that keep a fast, tireless, obedient program from obediently emptying your account. And you will do all of it against a simulated broker, never a real one, until the very end, because the first rule of automation is that you do not practise with real money.

What to carry forward

Analysis is studying data. Execution is the separate, harder work of turning a decision into a filled position, through orders, fills at prices you did not pick, and costs. Algorithmic trading automates that execution, which buys you speed, stamina, and obedience, but not accuracy, so automating a losing idea only loses faster. The loss reality from the earlier courses follows you here, and sharpens. The next chapter starts where any Indian algo trader must start: with the rules you are now allowed to trade under.