Most position size calculators online stop at one line: risk amount divided by loss per unit. That is fine for shares. For Indian futures and options it leaves out the part that bites: you cannot hold 3.8 lots. The exchange fixes a lot size per contract, and whatever your arithmetic says has to be rounded to whole lots.
I make Option Radar, an options analytics web app for NSE index options, and we shipped a free position size calculator on it last month. This post is the arithmetic, the three rounding decisions, and the tests that keep it honest. The code is TypeScript, but nothing here depends on a framework.
The three inputs and one constant
A trader has already decided three things before they size anything:
- Capital: the money in the account, say ₹5,00,000.
- Risk per position: the share of capital they accept losing on this one position, say 1%.
- Loss per unit: how far against them, in rupees per unit, they accept the price moving before they close, say ₹20.
The constant is the lot size the exchange sets for the contract. From the January 2026 expiries NSE's index lot sizes are NIFTY 65, BANKNIFTY 30, FINNIFTY 60, MIDCPNIFTY 120 and NIFTYNXT50 25 units (NSE's market lot file, read on 1 December 2026, lists the same figures through the February 2027 contracts). A lot of pages online still say 75 for NIFTY, which is the old number.
The whole function
export function positionSize(i: { capital: number; riskPct: number; lossPerUnit: number; lotSize: number; }) { if (![i.capital, i.riskPct, i.lossPerUnit, i.lotSize].every((v) => Number.isFinite(v) && v > 0)) return { maxLoss: 0, units: 0, lots: 0 }; const maxLoss = (i.capital * i.riskPct) / 100; const units = Math.floor(maxLoss / i.lossPerUnit); const lots = Math.floor(units / i.lotSize); return { maxLoss, units, lots }; } Eleven lines. The interesting parts are the two Math.floor calls and the guard.
Decision 1: round units down, never to nearest
₹5,000 ÷ ₹20 is exactly 250 units. Change the loss per unit to ₹23 and you get 217.39. Math.round would give 217 here, but with ₹21.9 it gives 228 (228.31), and 228 × ₹21.9 = ₹4,993.2: fine. Now try ₹5,000 ÷ ₹26.6 = 187.97: Math.round gives 188, and 188 × ₹26.6 = ₹5,000.8, which is more than the 1% the user typed. Small, but the whole point of the tool is "at or below the number you chose". Math.floor keeps it true for every input; rounding to nearest breaks it about half the time.
Decision 2: round lots down too, and show what is left over
With NIFTY's lot size of 65, 250 units is 3.85 lots. You can hold 3. So the calculator shows three numbers, not one:
- Units your risk allows: 250
- Whole lots: 3 (195 units)
- Units left over: 55
and the loss on the whole lots: 195 × ₹20 = ₹3,900, which is 0.78% of capital, not 1%. Showing the left-over units is the honest part. A calculator that prints "3.85 lots" or silently rounds up to 4 tells the user they can hold something they cannot, or lets them lose more than they chose (4 × 65 × ₹20 = ₹5,200).
When the units come out below one lot (say a ₹1,00,000 account at 1% with ₹20 a unit: 50 units against a lot of 65), whole lots is 0. We show 0 and say why, rather than hiding the result. That 0 is the most useful number on the page for a small account.
Decision 3: refuse bad input instead of guessing
Every input must be a finite number above zero, or the whole result is zeros. No defaults that look like real answers, no NaN leaking into the UI, no division by a zero loss per unit giving Infinity lots. Form fields start empty (the lot size starts at 1, so the tool also works for shares).
What the function does not know
Margin. Your broker's margin requirement is a separate limit and can allow fewer lots than the risk arithmetic does. Gaps: a price can open beyond the loss per unit you planned for, and then the loss on the position is larger than the calculator says. Both are written on the page next to the result; neither belongs in an eleven-line pure function.
Checks that pin it down
These are the checks I ran against the function before writing this, in vitest form so you can drop them into your own project:
import { describe, expect, it } from 'vitest'; import { positionSize } from './sizing'; describe('positionSize', () => { it('worked example from the page', () => { expect(positionSize({ capital: 500000, riskPct: 1, lossPerUnit: 20, lotSize: 65 })) .toEqual({ maxLoss: 5000, units: 250, lots: 3 }); }); it('never exceeds the chosen loss', () => { for (let l = 1; l < 100; l += 0.1) { const r = positionSize({ capital: 500000, riskPct: 1, lossPerUnit: l, lotSize: 1 }); expect(r.units * l).toBeLessThanOrEqual(5000 + 1e-9); } }); it('below one lot is zero lots, not one', () => { expect(positionSize({ capital: 100000, riskPct: 1, lossPerUnit: 20, lotSize: 65 }).lots).toBe(0); }); it('bad input gives zeros', () => { expect(positionSize({ capital: 0, riskPct: 1, lossPerUnit: 20, lotSize: 65 }).units).toBe(0); expect(positionSize({ capital: 500000, riskPct: 1, lossPerUnit: 0, lotSize: 65 }).units).toBe(0); }); }); The second test is the one I would keep if I could keep only one: it sweeps the loss per unit and checks the invariant directly, instead of trusting a few hand-picked examples. Run the same sweep with Math.round and it fails on 482 of the 991 values.
Try it
The calculator is free, needs no sign-in and stores nothing you type: https://optionsradar.in/tools/position-size-calculator?utm_source=devto&utm_medium=article&utm_campaign=arlen-marketing
It has the formula, this worked example and a dated table of NSE index lot sizes on the page. It is arithmetic on your own numbers, not advice, and trading options carries a risk of loss.
If you have built something similar for other exchanges, I would like to hear how you handled lot sizes that change twice a year: we keep ours as a dated table that we re-check against the exchange file.