Moneydesks

🤖 Systematic and algorithmic trading: rules, backtests and SEBI's retail algo rules

Open this guide in the app →

🎯 In 30 seconds: A systematic trader follows written rules that say exactly when to buy, when to sell and how much. An algorithm is those rules turned into code. You can test rules on past prices, called backtesting, before risking money. The hard part is testing honestly, because a computer can always find rules that would have worked in the past. In India, retail algo trading through a broker's API has its own SEBI framework, fully in force for all brokers from 1 April 2026: your broker is responsible, algos carry an exchange ID, and "black box" strategies sold to you must come from a SEBI-registered research analyst.

From hunch to rule

Discretionary trading means deciding each trade by judgment. Systematic trading means following rules fixed in advance. Algorithmic trading means a computer applies those rules, and often places the orders too.

Think of a dosa chain's recipe card. "Add enough batter" is not a recipe. "Pour 120 ml, spread in a 22 cm circle, cook 90 seconds" is. A trading rule is only a rule if two people reading it would make the same trade. "Buy strong stocks on dips" is not a rule. This is:

  • Universe: one Nifty 50 index fund or ETF.
  • Signal: on the last trading day of each month, compare the Nifty 50's closing value with its 200-day simple moving average.
  • Entry: if the close is above the average, hold the fund.
  • Exit: if the close is below the average, sell and hold a liquid fund or cash.
  • Timing: act at the next trading day's price, not the same close.
  • Size: 100% in the fund or 100% out.

This trend filter is a teaching example, not a recommendation. Moving averages are explained in Moving averages, and this style of system in Position trading and trend following.

What a backtest is

A backtest runs your rules over historical prices as if you had traded them and reports what would have happened. Done well, it rejects bad ideas cheaply. Done badly, it produces confident numbers that mean nothing.

  1. Write the rules down completely before you look at any results.
  2. Get clean data. NSE Indices publishes historical index values on niftyindices.com. For shares, prices must be adjusted for splits, bonus issues and dividends, and must include companies that were later delisted.
  3. Decide which part of the data you will hold back for a final test. Do not look at it yet.
  4. Run the rules day by day, using only information that was public at each moment.
  5. Subtract realistic costs: brokerage, STT, exchange charges, stamp duty, GST, DP charges and slippage.
  6. Record the results below, then run the rules once on the held-back data.

The numbers to read

MeasureWhat it tells you
Annual return (CAGR)The yearly growth rate that turns the starting balance into the ending balance.
Maximum drawdownThe largest fall from a peak to a later low. This is the pain you must sit through. See Drawdowns and losing streaks.
VolatilityThe standard deviation of returns: how bumpy the ride is.
Sharpe ratioReturn above a risk-free rate, per unit of volatility.
Number of tradesFewer than about 30 trades says very little. A handful of trades is mostly luck.
Win rate and expectancyHow often trades win, and the average rupee result per trade. See Risk/reward and expectancy.
ExposureThe share of time money is actually in the market.

The Sharpe ratio, with hypothetical numbers:

Sharpe = (strategy return - risk-free rate) / volatility

A system that returned 13% a year, with an assumed 7% risk-free rate and 18% volatility, has a Sharpe ratio of (13 - 7) / 18 = 0.33. In India the risk-free rate is usually taken from Treasury bill or government bond yields, which are higher than in many countries. A system that beats a fixed deposit by a little, with far more risk, is not much of a system. A backtest showing a Sharpe ratio of 3 on a simple daily strategy should make you suspicious, not excited.

The four biases that fool almost everyone

1. Look-ahead bias. Using information you could not have had at the time. Examples: buying at today's close based on today's close, or using quarterly results from the date the quarter ended instead of the date the company announced them to the exchange. Indian companies have weeks after quarter end to file results, so that gap is real. Fix: act on the next bar, and time-stamp every input by when it became public.

2. Survivorship bias. Testing only on companies that exist today. The Nifty 50 of today is not the Nifty 50 of 2010. Companies that were dropped, merged or delisted are missing from a list you download now, so a "buy cheap stocks" rule looks better than it really was. Fix: use the index's membership as it was on each date, or data that includes delisted stocks.

3. Overfitting (data snooping). Trying many rule variations and keeping the one with the best past result. With enough tries, some rule will fit the noise. It has learned the history, not the market.

4. Ignoring costs. A system that trades often can look profitable before costs and lose money after them. What trading really costs lists every charge to include.

How overfitting happens: a worked example

Say you test a moving-average crossover on the Nifty. You try fast averages from 5 to 50 days and slow averages from 50 to 300 days, in steps of 5. That is 10 x 51 = 510 combinations. You keep the best one.

The problem in plain arithmetic: if none of the rules had any real edge, and you used a common test that calls a result "significant" when it would happen by chance only 5% of the time, about 5% of 510, roughly 25 rules, would still pass. The winner of 510 tries is very likely one of those lucky ones.

Researchers have studied this formally. A well-known paper by Bailey, Borwein, López de Prado and Zhu on "the probability of backtest overfitting" argues that a simple hold-out test is not enough on its own when many variations were tried.

Overfit rule: great in-sample, poor out-of-sampleIn-sample: used to pick the ruleOut-of-sample100150200Best of 510 triesSimple ruleOverfit ruleFixed simple rule
Illustration with made-up numbers, starting at 100. The rule chosen for its in-sample peak loses ground once it meets data it was not fitted to. A simpler rule with fewer choices often holds up better.

Testing honestly: in-sample, out-of-sample, walk-forward

In-sample data is the part you use to build and tune the rules. Out-of-sample data is the part you set aside and touch only once, at the end. If performance collapses out-of-sample, the rule was probably fitted to noise.

The catch: once you look at the out-of-sample result and go back to tweak, that data is no longer out-of-sample. Be strict.

Walk-forward testing repeats the process through time. Tune on one window, test on the next unseen window, then slide both forward and repeat. Join the test windows and you get a record of how the method would have done if you had used it in real time.

Walk-forward: tune, test, slide forwardRound 1Round 2Round 3Round 4TimeTuneTest
Only the green test windows count toward the final result. Each one was unseen when its rules were chosen.
The most common mistake
Tweaking until the backtest looks good, then believing it. Every change you make after seeing results uses up some of your data's honesty. Keep a log of every variation you tried, not just the winner. If you tried 50 versions, write that down, and expect live results to be well below the best backtest.

Costs: a worked example in rupees

Hypothetical system: a ₹2,00,000 account, each trade uses the full amount in delivery shares, 100 round trips a year. Suppose brokerage, STT, exchange charges, stamp duty, GST, DP charges and slippage together come to 0.30% of the trade value per round trip. That figure is an assumption for teaching. Work out your own from a real contract note.

Cost per round trip: ₹2,00,000 x 0.30%₹600
Round trips per year100
Yearly cost₹60,000, or 30% of the account

The system must earn 30% a year before costs just to break even. Intraday and options systems have a different cost mix but the same problem: the more often a system trades, the more the cost assumption decides whether it makes money. SEBI's August 2026 study found that individual F&O traders paid about ₹25,000 crore in transaction costs in FY26 alone.

From backtest to live

  1. Paper trade it. Run the rules forward on paper for a few months and compare every simulated fill with what the backtest assumed. See Practice first.
  2. Start tiny. Trade the smallest real size possible. Real fills, real emotions and real mistakes only show up with real money.
  3. Set a stop rule for the system. Decide in advance the drawdown that will make you stop and review, for example "if live drawdown passes 1.5 times the worst backtest drawdown".
  4. Automate carefully. If code places orders, cap the order size and the number of orders, and keep a way to switch it off at once. A bug in a loop can send hundreds of orders in seconds.
Simple beats clever
Prefer rules with few settings and a reason you can explain in one sentence, like "trends tend to persist" or "costs eat fast systems". If a rule only works with a 37-day average and fails with 35 or 40, it is not robust. Test nearby settings: a good rule should work reasonably across a range.

SEBI's rules for retail algo trading

Until 2025, many Indian retail traders ran code through broker APIs or bought strategies from "algo platforms" with little oversight. SEBI's circular of 4 February 2025, "Safer participation of retail investors in Algorithmic trading", set a framework. Its start date was pushed from 1 August 2025 to 1 October 2025, and then a SEBI circular of 30 September 2025 gave brokers a glide path and made the framework applicable to all brokers from 1 April 2026. The main points:

  • The broker is the principal. Any algo provider or fintech that places orders through a broker's API acts as the broker's agent. The broker handles complaints about algo trading.
  • Every algo order is tagged. Orders that come through an API carry a unique identifier from the exchange, so each one can be traced.
  • Algo providers must be empanelled. SEBI does not regulate algo providers directly, but they must be empanelled with the exchanges, and brokers may deal only with empanelled providers. NSE publishes its list.
  • Your own code below a speed limit. NSE's implementation standards set the threshold at not more than 10 orders per second per exchange, as of October 2026. Below it, a self-built algo does not need separate registration. Above it, you must register it with each exchange through your broker. A registered self-built algo may be used for your family (self, spouse, dependent children and dependent parents), not for other people.
  • Static IP and secure login. API access needs a static IP address registered with the broker, OAuth-based authentication and two-factor login. Open APIs are not allowed, and API sessions must be logged out every day before the next trading day.
  • White box and black box. An algo whose logic is disclosed and can be replicated is a "white box" or execution algo. One whose logic the user cannot see is a "black box". A provider of black box algos must register with SEBI as a Research Analyst and keep a research report for each algo.
  • Kill switch. Exchanges can shut off orders from a particular algo ID if it misbehaves or harms the market.
"Our algo makes 5% a month"
Telegram channels and apps still sell strategies with screenshots of past profits. Under the framework, a black box strategy offered to you must come through your broker from an exchange-empanelled provider registered as a Research Analyst. Check the provider on NSE's empanelled list and the RA registration on SEBI's website. A backtest screenshot is not evidence; you now know how easy it is to produce a beautiful one.

Algorithms in the wider Indian market

Institutions in India trade mostly by algorithm. SEBI's August 2026 study found that in FY26, 86% of foreign portfolio investors and 47% of proprietary traders active in equity derivatives traded through algorithms, and that 99% of the gross trading profits of those two groups came from entities that used algorithmic orders. Among individuals, only about 15% were flagged as algo users, and SEBI notes even that overstates real use, since it includes positions that brokers squared off automatically near the close.

As a retail trader you will not win on speed. Where an individual can compete is patience, small size and holding periods that large funds find awkward. Whether any trading edge exists at all is the question in Does technical analysis work?

Try it

Use a spreadsheet and free data.

  1. Download daily Nifty 50 closing values for as many years as you can from the historical data page on niftyindices.com.
  2. Before you calculate anything, write down what you expect: annual return, maximum drawdown and number of trades for the 200-day trend filter above.
  3. Add a 200-day average column. Mark the last trading day of each month and apply the rule, acting on the next day's close. Use only the first two thirds of the history. Record the results.
  4. Try 150 and 250 days as well. Are the three results broadly similar? Write all three down.
  5. Now run the 200-day version once on the last third. Subtract an assumed cost for each switch in or out. Compare the maximum drawdown with simply holding the index. Which could you live with?
Check yourself
  1. What is look-ahead bias? Give an Indian example. Answer: Using information you could not have had at the time, such as treating quarterly results as known on the last day of the quarter, when the company only announced them to the exchange weeks later.
  2. A system returned 13% a year with 18% volatility, and the risk-free rate is 7%. What is its Sharpe ratio? Answer: About 0.33 ((13 - 7) / 18).
  3. A system trades ₹2,00,000 a time, 100 round trips a year, at 0.30% all-in cost per round trip. What does it need to earn just to break even? Answer: ₹60,000 a year, or 30% of the account.
  4. Under SEBI's framework, who is responsible to you for an algo you run through your broker's API with an empanelled provider? Answer: The broker. The algo provider acts as the broker's agent, and the broker handles complaints.
  5. A platform sells you a strategy but will not say how it decides trades. What must the provider be? Answer: That is a black box algo. The provider must be empanelled with the exchange and registered with SEBI as a Research Analyst, and must keep a research report for the algo.

Sources