Calculating Zerodha intraday and delivery charges in Go
A backtest without trading costs will flatter almost any intraday strategy. Here is the small Go function I use to estimate Zerodha brokerage, STT, exchange fees, stamp duty, GST and DP charges for intraday and delivery trades.
I have a paper trader in Go that replays a day of candles for one stock and records every fill it would have made. Each fill has a price, a quantity and a realised profit or loss. Those numbers mean nothing without costs, because on Zerodha the brokerage is the small part. STT, stamp duty, exchange fees and GST add up, and on intraday trades they eat a good chunk of a small move.
In this blog we will look at the Go function I use to estimate those charges, and a few numbers that show why it matters.
This is not investment advice, it's about the code and how the costs work.
The rates
These are the rates in my code, written down in November 2026 from Zerodha's published charges for NSE equity. They change from time to time. Treat them as an estimate as of that date. The contract note you get after the trade is the real number, always.
- Brokerage: intraday is 0.03% of the order value or Rs 20 per executed order, whichever is lower. Delivery is zero.
- STT: intraday 0.025% on the sell side only. Delivery 0.1% on both buy and sell.
- Exchange transaction charge: 0.00297% of the value.
- SEBI fee: 0.0001% of the value.
- Stamp duty: intraday 0.003% on the buy side only. Delivery 0.015% on the buy side only.
- GST: 18% on brokerage plus exchange charges plus the SEBI fee.
- DP charge: Rs 15.93 plus 18% GST, on delivery sells.
In Go they are just constants.
package main
import (
"fmt"
"math"
)
// Zerodha NSE equity charges, Nov 2026 schedule.
// An estimate only: the contract note is the authority.
const (
brokerageRate = 0.0003 // intraday: 0.03% or Rs 20 per order, lower one
brokerageCap = 20.0 // delivery brokerage is zero
sttIntraday = 0.00025 // sell side only
sttDelivery = 0.001 // both sides
txnRate = 0.0000297
sebiRate = 0.000001
stampIntraday = 0.00003 // buy side only
stampDelivery = 0.00015 // buy side only
gstRate = 0.18 // on brokerage + exchange + SEBI fees
dpCharge = 15.93 * 1.18
)
I write the rates as fractions, not percentages. 0.03% is 0.0003. It's very easy to be off by a factor of 100 here, so check each one against the percent in a comment.
The charges function
One order, one call. It takes whether it's a buy, whether it's intraday, and the order value (price times quantity).
func charges(buy, intraday bool, value float64) float64 {
if value <= 0 {
return 0
}
brokerage := 0.0
if intraday {
brokerage = math.Min(brokerageRate*value, brokerageCap)
}
var stt, stamp float64
switch {
case intraday && !buy:
stt = sttIntraday * value
case !intraday:
stt = sttDelivery * value
}
if buy {
if intraday {
stamp = stampIntraday * value
} else {
stamp = stampDelivery * value
}
}
fees := txnRate*value + sebiRate*value
return brokerage + stt + stamp + fees + gstRate*(brokerage+fees)
}
Notice GST is not on STT or stamp duty. Only on brokerage and the two fees. That's easy to get wrong if you just do 18% of everything.
The DP charge is not in this function. It's per stock per day when shares leave your demat, not per order, so the caller adds it once on a delivery sell. In my paper trader it's added on the sell of shares bought on an earlier day.
The same day CNC problem
There's one awkward case. When the paper trader buys in CNC (delivery), it doesn't know yet if it'll sell those shares later the same day. If it does, the exchange treats the round trip as intraday, so the buy should have been charged at intraday rates.
My fix is to charge every CNC buy at the delivery rate when it happens, then true it up if the shares get sold the same day. The true up is just the difference between the two.
// sameDayBuyRefund trues up a CNC buy that was charged at the delivery
// rate and then sold the same day. It comes out negative.
func sameDayBuyRefund(value float64) float64 {
return charges(true, true, value) - charges(true, false, value)
}
It's negative because the intraday buy is cheaper. On the sell side, the shares bought today get charged as an intraday sell plus this refund, and the older ones get the delivery sell plus DP. When one sell covers both old and new shares, the paper trader splits the quantity into "bought today" and "bought before" and charges each part separately.
Some numbers
Here is a main that puts it together. Same trade, 100 shares bought at 1500 and sold at 1505, once as intraday and once as delivery. Then a small loop that finds the break even sell price for a few sizes.
// breakEven is the lowest intraday sell price that does not lose money.
func breakEven(buy float64, qty int, tick float64) float64 {
q := float64(qty)
in := charges(true, true, buy*q)
for sell := buy; ; sell += tick {
if (sell-buy)*q-in-charges(false, true, sell*q) >= 0 {
return math.Round(sell/tick) * tick
}
}
}
func main() {
qty := 100.0
buy, sell := 1500.0, 1505.0
in := charges(true, true, buy*qty)
out := charges(false, true, sell*qty)
gross := (sell - buy) * qty
fmt.Printf("intraday: gross %.2f, charges %.2f + %.2f, net %.2f\n",
gross, in, out, gross-in-out)
in = charges(true, false, buy*qty)
out = charges(false, false, sell*qty) + dpCharge
fmt.Printf("delivery: gross %.2f, charges %.2f + %.2f, net %.2f\n",
gross, in, out, gross-in-out)
fmt.Printf("refund on same-day CNC buy: %.2f\n", sameDayBuyRefund(buy*qty))
for _, q := range []int{5, 20, 100, 500} {
fmt.Printf("break-even for %3d @ 1500.00: %.2f\n", q, breakEven(1500, q, 0.05))
}
}
Put all the Go blocks above in one main.go and run it.
go mod init charges
go run .
intraday: gross 500.00, charges 33.53 + 66.68, net 399.79
delivery: gross 500.00, charges 177.93 + 174.75, net 147.32
refund on same-day CNC buy: -144.40
break-even for 5 @ 1500.00: 1501.60
break-even for 20 @ 1500.00: 1501.60
break-even for 100 @ 1500.00: 1501.05
break-even for 500 @ 1500.00: 1500.65
A 5 rupee move on 100 shares is 500 gross. Intraday, a fifth of it goes in charges. Delivery, more than two thirds goes, mostly to the 0.1% STT on both sides. Delivery costs are meant to be spread over a bigger move held for days, so that's not a fair fight, but it shows how much STT matters.
The break even lines are the ones that changed how I read my backtests. With 5 or 20 shares the stock has to go up about 0.11% before you're even flat. Both sizes give the same number because the brokerage is still the 0.03% part, it hasn't hit the Rs 20 cap yet. The cap only kicks in once one order is above about Rs 66,667 (20 divided by 0.0003). Past that, brokerage stops growing with size, so bigger orders need a smaller move in percent. At 500 shares the break even is about 0.04%.
Now think about a strategy that wins small, 0.1% here and 0.1% there, on small quantity. Without costs it looks like it works. With costs, every one of those wins is a small loss. That's the kind of result I don't want the paper trader showing me.
Checking it against a contract note
The function is an estimate, so it's worth checking once against a real contract note. Pick one intraday trade, put the same price and quantity through charges, and compare line by line. Brokerage, STT, transaction charges, SEBI fee, stamp duty and GST are all listed separately on the note. If yours is off by a rupee or so, it's most likely rounding. If it's off by a lot, check the rate constants first. And when the rates change, update the constants and the date in the comment together, so the next person (probably me) knows how old they are.