Get your API key

Intermediate · 5 lessons · 47 min

Backtest a strategy with Python and AI

Test a written trading rule on past data with costs, a train/test split and an honest report, without writing code yourself.

Education only. This is not investment advice and nothing here is a buy or sell recommendation. Trading carries risk of loss, and past results do not predict the future. Backtests are hypothetical: practise on paper only, never connect broker API keys or place live orders from these lessons. For personal advice, talk to a SEBI-registered Investment Adviser.

Who it's for

Excel-comfortable students and office workers who are curious about trading ideas and want to test them properly before believing them.

What you'll build

A small Python backtest project (data check, rule, costs, train/test and walk-forward) and a one-page honest report you can reuse for any rule.

Why this course

Most individual traders in India lose money: SEBI found 87.7% of individual equity-derivatives traders made net losses in FY26, after about ₹25,000 crore of transaction costs that year, and 7 in 10 individual intraday traders in the cash segment lost money in FY23. Research shows that trying a few dozen settings is enough to make a useless strategy look brilliant on past data. Learning to backtest honestly, with costs and unseen test data, protects you from believing a lucky curve.

Take first: Prompting for AI coding, Terminal and files, without fear

Lessons in this course

  1. 1What a backtest really is (and your project setup)A backtest replays an exact rule on past prices with costs. Write the rule, set up Python, and give your agent safe project rules. 9 min Free
  2. 2Get price data and check itFree data sources and their terms, downloading NIFTY 50 daily data once, and a check script for gaps, duplicates and odd days. 9 min Log in to open
  3. 3Code the rule in pandas, without peeking aheadMoving averages, signal, shift(1) to avoid look-ahead, returns and an equity curve, then a check table you verify in Excel. 10 min Log in to open
  4. 4Costs, slippage and honest numbersIndian trading costs per trade, slippage, and a report with CAGR, max drawdown, trade count and time in the market. 9 min Log in to open
  5. 5Why most backtests lie: train/test and walk-forwardLook-ahead, survivorship and overfitting; judging a rule on unseen test years; walk-forward; and paper trading as the next step. 10 min Log in to open
Next upBuild a UPI expense and budget trackerTurn your bank statement into a private Google Sheet that sorts every UPI payment, tracks a monthly budget and draws the charts.