How to Trade — Execution & Platforms
LEVEL 5 — Mastery Examination
Time limit: 75 minutes Total marks: 60 Instructions: Answer all three questions. Show all working. State assumptions explicitly. Round currency to two decimals unless told otherwise.
Question 1 — Position Sizing, Leverage & Margin Mechanics (22 marks)
A discretionary intraday trader operates a ₹500,000 account and follows a fixed-fractional risk rule of 1.5% risk per trade. She trades a stock currently at ₹820.00, with a planned stop-loss at ₹803.50. The broker offers 5× intraday leverage (i.e. 20% margin) on this stock. Brokerage + statutory costs are modelled as a round-trip cost of 0.05% of turnover (buy + sell notional combined), and the effective spread cost is ₹0.20 per share (paid once, on entry).
(a) Derive the general position-sizing formula that maps (account equity , risk fraction , entry price , stop price ) to share quantity , ignoring costs. Then compute the raw for this trade. (5)
(b) State whether leverage changes the risk-based quantity in (a), and explain the distinction between the risk constraint and the margin (capital) constraint. Compute the maximum quantity permitted by the 5× margin constraint, and hence give the actual tradeable (integer shares). (6)
(c) Re-derive an adjusted position size that keeps total loss at stop (price loss + one entry spread + round-trip costs) equal to exactly . Set up the equation symbolically, solve for , and evaluate numerically. Compare to part (a) and comment on why cost-aware sizing matters more for tight stops. (7)
(d) The trade hits target at ₹849.00. Compute net P&L (using the cost-aware from (c)), and express it as a percentage return on margin deployed and as a percentage of account equity. Explain why these two figures diverge. (4)
Question 2 — SEBI Peak Margin, Square-off & a Verification Function (20 marks)
Under SEBI peak-margin rules, the clearing corporation takes 4 random intraday snapshots and the trader must have maintained the required upfront margin (VaR + ELM) at the peak observed exposure. Suppose required margin rate on a position is 20%.
A trader has collateral (margin available) of ₹60,000. During the day her position notional at the 4 snapshots is:
[250000, 310000, 295000, 200000].
(a) Define peak-margin exposure mathematically and compute the peak required margin. State whether she is compliant, and if not, compute the shortfall and the resulting peak-margin penalty assuming a flat 1% penalty on the shortfall. (6)
(b) A margin call is triggered when equity falls below the maintenance margin. For a long position of shares bought at on margin rate , derive the liquidation (square-off) price at which the trader's remaining equity equals the maintenance margin (as a fraction of current notional). Then, for , , initial margin , maintenance , compute . (7)
(c) Write a self-contained Python function peak_margin_penalty(snapshots, margin_rate, collateral, penalty_rate) that returns the penalty amount (0 if compliant). Then write liquidation_price(Pe, m, mm) returning for a long. Include docstrings and one assert-based test each. (7)
Question 3 — Execution Cost, Spread Impact & Alert Logic (18 marks)
(a) A scalper takes N round-trip trades per day. Each round trip crosses the spread (cost per share) and pays proportional costs (as a fraction of one-side notional, charged both sides). Trade size is shares at price . Derive total daily cost and the break-even gross edge per trade (in ₹/share) required before the strategy is profitable. (6)
(b) Given , , /share, per side, and an average captured gross move of ₹0.90/share per trade, determine the maximum that still leaves positive net profit is not the right question — instead compute the net profit per trade and hence net daily profit if . Then state the minimum captured gross move (₹/share) needed to break even. (6)
(c) Design a conditional-alert state machine for managing 3 simultaneous open positions, where each position can be in states {FLAT, LONG, ALERT_STOP, ALERT_TARGET, CLOSED}. Draw/describe the transitions, and give pseudocode for an alert dispatcher that fires at most one notification per position per price tick and avoids duplicate alerts. Justify one design choice that prevents alert fatigue. (6)
Answer keyMark scheme & solutions
Question 1
(a) Risk per share = . Rupee risk budget . Setting : (2 marks derivation) Numbers: . Risk/share . (3 marks)
(b) Leverage does not change the risk-based quantity — risk is defined by stop distance and rupee risk, independent of how much margin funds the notional. (2 marks)
- Risk constraint: limits loss if stop hit ().
- Margin constraint: limits notional you can hold given capital: notional where (5×). (2 marks) Margin-max notional ; max shares . (1 mark) Actual — risk constraint binds. (1 mark)
(c) Total loss at stop = price loss + spread (entry) + round-trip cost: where , (0.05% on combined turnover ≈ per share). (4 marks setup+derivation) Denominator . (2 marks) Comment: costs (₹1.01175/share here) are ~6% of the 16.50 stop distance — for tight stops the cost term is a larger fraction of risk/share, shrinking materially; ignoring it over-sizes and breaches the risk budget. (1 mark)
(d) . Gross move /share → gross . Costs: spread ; round-trip proportional . Net P&L . (2 marks) Margin deployed . Return on margin . Return on equity . (1 mark) Divergence: leverage magnifies return on the deployed capital (5×) vs the whole account; only 14% of equity was posted as margin, so the same rupee gain is a large % of margin but small % of equity. (1 mark)
Question 2
(a) Peak exposure . Required peak margin . (3 marks) Collateral → non-compliant. Shortfall . (2 marks) Penalty . (1 mark)
(b) Equity in a long on margin: . Debt (borrowed) (initial equity fraction ). At current price : equity . Maintenance requires equity . At square-off equality: (4 marks derivation) Numbers: . (3 marks)
(c)
def peak_margin_penalty(snapshots, margin_rate, collateral, penalty_rate):
"""Return peak-margin penalty (0 if compliant).
Peak = max snapshot notional; required = peak*margin_rate."""
peak = max(snapshots)
required = peak * margin_rate
shortfall = max(0.0, required - collateral)
return shortfall * penalty_rate
assert peak_margin_penalty([250000,310000,295000,200000],0.20,60000,0.01) == 20.0
def liquidation_price(Pe, m, mm):
"""Long square-off price where equity == maintenance margin.
P_liq = Pe*(1-m)/(1-mm)."""
return Pe * (1 - m) / (1 - mm)
assert abs(liquidation_price(300,0.20,0.10) - 266.666666) < 1e-3(Function correctness 4, docstrings/tests 3)
Question 3
(a) Per round trip: spread cost (crossing once effectively per side; model as per RT), proportional cost each side . Cost per trade . Total: Break-even gross edge (₹/share) satisfies : (3 derivation + 3 result)
(b) . Cost/share . Net/share . Net/trade . (2) Daily (): . (2) Break-even gross move . (2)
(c) State machine (each position independent):
FLAT →(fill buy)→ LONGLONG →(price ≤ stop trigger)→ ALERT_STOP →(square-off)→ CLOSEDLONG →(price ≥ target trigger)→ ALERT_TARGET →(book)→ CLOSEDALERT_STOP/ALERT_TARGET → LONGonly if user cancels/adjusts. (3)
Pseudocode dispatcher:
for pos in positions:
if pos.state == LONG:
if price <= pos.stop and not pos.alerted_stop:
notify(pos, "STOP"); pos.state = ALERT_STOP; pos.alerted_stop = True
elif price >= pos.target and not pos.alerted_target:
notify(pos, "TARGET"); pos.state = ALERT_TARGET; pos.alerted_target = True
The per-position boolean flag (alerted_stop/alerted_target) guarantees at most one notification per position per trigger, preventing repeated firing on every tick — this deduplication is the key anti-alert-fatigue choice. (3)
[
{"claim":"Raw risk-based Q = 454 (floor of 7500/16.5)","code":"result = int(7500/16.5)==454"},
{"claim":"Cost-aware Q = 428","code":"den=16.5+0.20+0.0005*(820+803.5); result = int(7500/den)==428"},
{"claim":"Net P&L cost-aware = 11969.23","code":"Q=428; g=Q*29; sp=Q*0.20; rt=0.0005*Q*(820+849); pnl=g-sp-rt; result = abs(pnl-11969.23)<0.5"},
{"claim":"Peak margin penalty = 20.0","code":"peak=max([250000,310000,295000,200000]); req=0.20*peak; sf=max(0,req-60000); result = sf*0.01==20.0"},
{"claim":"Liquidation price = 266.67","code":"result = abs(300*(1-0.20)/(1-0.10)-266.6667)<0.01"},
{"claim":"Break-even edge 0.87 and net daily 240","code":"gstar=0.15+2*0.0003*1200; net=(0.90-gstar)*200*40; result = abs(gstar-0.87)<1e-9 and abs(net-240)<1e-6"}
]