Level 5 — MasteryHow to Trade — Execution & Platforms

How to Trade — Execution & Platforms

75 minutes60 marksprintable — key stays hidden on paper

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 EE, risk fraction ff, entry price PeP_e, stop price PsP_s) to share quantity QQ, ignoring costs. Then compute the raw QQ 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 QQ (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 fEf\cdot E. Set up the equation symbolically, solve for QQ, 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 QQ 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 QQ shares bought at PeP_e on margin rate mm, derive the liquidation (square-off) price PliqP_{liq} at which the trader's remaining equity equals the maintenance margin mmm_m (as a fraction of current notional). Then, for Q=1000Q=1000, Pe=300P_e=300, initial margin m=0.20m=0.20, maintenance mm=0.10m_m=0.10, compute PliqP_{liq}. (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 PliqP_{liq} 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 ss per share) and pays proportional costs cc (as a fraction of one-side notional, charged both sides). Trade size is QQ shares at price PP. Derive total daily cost C(N)C(N) and the break-even gross edge per trade (in ₹/share) required before the strategy is profitable. (6)

(b) Given P=1200P=1200, Q=200Q=200, s=0.15s=0.15/share, c=0.03%c=0.03\% per side, and an average captured gross move of ₹0.90/share per trade, determine the maximum NN that still leaves positive net profit is not the right question — instead compute the net profit per trade and hence net daily profit if N=40N=40. 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 = PePsP_e - P_s. Rupee risk budget =fE= f\cdot E. Setting Q(PePs)=fEQ(P_e-P_s)=fE: Q=fEPePsQ=\frac{fE}{P_e-P_s} (2 marks derivation) Numbers: fE=0.015×500000=7500fE = 0.015\times500000 = 7500. Risk/share =820803.50=16.50=820-803.50=16.50. Q=750016.50=454.5454 shares.Q=\frac{7500}{16.50}=454.5\Rightarrow 454\text{ shares}. (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 (QfE/(PePs)Q\le fE/(P_e-P_s)).
  • Margin constraint: limits notional you can hold given capital: notional E/m\le E/m where m=0.20m=0.20 (5×). (2 marks) Margin-max notional =500000/0.20=2,500,000= 500000/0.20 = 2{,}500{,}000; max shares =2500000/820=3048.73048=2500000/820=3048.7\to3048. (1 mark) Actual Q=min(454,3048)=454Q=\min(454,3048)=\mathbf{454} — risk constraint binds. (1 mark)

(c) Total loss at stop = price loss + spread (entry) + round-trip cost: Q(PePs)+Qs+cQ(Pe+Ps)=fEQ(P_e-P_s) + Qs + c\,Q(P_e+P_s)=fE where s=0.20s=0.20, c=0.0005c=0.0005 (0.05% on combined turnover ≈ c(Pe+Ps)c(P_e+P_s) per share). Q[(PePs)+s+c(Pe+Ps)]=fEQ\big[(P_e-P_s)+s+c(P_e+P_s)\big]=fE Q=fE(PePs)+s+c(Pe+Ps)Q=\frac{fE}{(P_e-P_s)+s+c(P_e+P_s)} (4 marks setup+derivation) Denominator =16.50+0.20+0.0005×1623.50=16.50+0.20+0.81175=17.51175=16.50+0.20+0.0005\times1623.50 = 16.50+0.20+0.81175=17.51175. Q=750017.51175=428.29428 shares.Q=\frac{7500}{17.51175}=428.29\Rightarrow \mathbf{428}\text{ shares}. (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 QQ materially; ignoring it over-sizes and breaches the risk budget. (1 mark)

(d) Q=428Q=428. Gross move =849.00820=29.00=849.00-820=29.00/share → gross =428×29=12,412=428\times29=12{,}412. Costs: spread =428×0.20=85.60=428\times0.20=85.60; round-trip proportional =0.0005×428×(820+849)=0.0005×428×1669=357.166=0.0005\times428\times(820+849)=0.0005\times428\times1669=357.166. Net P&L =1241285.60357.17=11,969.23=12412-85.60-357.17=\mathbf{₹11{,}969.23}. (2 marks) Margin deployed =0.20×428×820=70,192=0.20\times428\times820=70{,}192. Return on margin =11969.23/70192=17.05%=11969.23/70192=17.05\%. Return on equity =11969.23/500000=2.39%=11969.23/500000=2.39\%. (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 =max(snapshots)=310000=\max(\text{snapshots})=310000. Required peak margin =0.20×310000=62,000=0.20\times310000=\mathbf{62{,}000}. (3 marks) Collateral =60000<62000=60000<62000 → non-compliant. Shortfall =6200060000=2,000=62000-60000=\mathbf{2{,}000}. (2 marks) Penalty =1%×2000=20.00=1\%\times2000=\mathbf{₹20.00}. (1 mark)

(b) Equity in a long on margin: Equity=QPDebt\text{Equity}=Q P - \text{Debt}. Debt (borrowed) =QPe(1m)=QP_e(1-m) (initial equity fraction mm). At current price PP: equity =QPQPe(1m)=QP - QP_e(1-m). Maintenance requires equity mmQP\ge m_m\cdot QP. At square-off equality: QPliqQPe(1m)=mmQPliqQP_{liq}-QP_e(1-m)=m_m QP_{liq} Pliq(1mm)=Pe(1m)P_{liq}(1-m_m)=P_e(1-m) Pliq=Pe1m1mm\boxed{P_{liq}=P_e\frac{1-m}{1-m_m}} (4 marks derivation) Numbers: Pliq=300×0.800.90=300×0.8889=266.67P_{liq}=300\times\frac{0.80}{0.90}=300\times0.8889=\mathbf{₹266.67}. (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 =sQ=sQ (crossing once effectively per side; model as sQsQ per RT), proportional cost =cQP=c\cdot QP each side ×2=2cQP\times2 = 2cQP. Cost per trade =sQ+2cQP=sQ+2cQP. Total: C(N)=NQ(s+2cP).C(N)=N\,Q(s+2cP). Break-even gross edge gg^* (₹/share) satisfies gQ=Q(s+2cP)gQ=Q(s+2cP): g=s+2cP.g^*=s+2cP. (3 derivation + 3 result)

(b) 2cP=2×0.0003×1200=0.722cP=2\times0.0003\times1200=0.72. Cost/share =s+2cP=0.15+0.72=0.87=s+2cP=0.15+0.72=0.87. Net/share =0.900.87=0.03=0.90-0.87=0.03. Net/trade =0.03×200=6.00=0.03\times200=₹6.00. (2) Daily (N=40N=40): 40×6=240.0040\times6=\mathbf{₹240.00}. (2) Break-even gross move =g=0.87/share=g^*=\mathbf{₹0.87/share}. (2)

(c) State machine (each position independent):

  • FLAT →(fill buy)→ LONG
  • LONG →(price ≤ stop trigger)→ ALERT_STOP →(square-off)→ CLOSED
  • LONG →(price ≥ target trigger)→ ALERT_TARGET →(book)→ CLOSED
  • ALERT_STOP/ALERT_TARGET → LONG only 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"}
]