Chapter 7 — The Mathematics of Trading
Indicators, position sizing, backtests and value at risk: the mathematics a trader actually uses — what it can prove, what it cannot, and why the size of each bet matters more than the cleverness of the signal.
Open any trading app and the chart arrives decorated: moving averages, an RSI panel, MACD bars, Bollinger bands. Channels on social media promise "90% accurate calls", "golden cross alerts" and systems that "never lose". Behind the decorations is a set of very ordinary formulas — weighted averages, ratios, standard deviations — applied to past prices; behind the promises is a set of claims that probability and statistics can check. A trader who understands the formulas knows exactly what each line on the screen says and, more importantly, what it does not say.
This chapter is about that mathematics, used honestly. We start with technical indicators as mathematics: moving averages as filters with a provable lag, crossovers and the MACD as delayed slope estimates, the RSI as a ratio of average gains to losses, Bollinger bands as a running standard deviation — and a theorem that settles what any of them can do on a random walk. Then the part that decides whether a trader survives: risk management — sizing each position from a stop-loss, expectancy (win rate alone means nothing), the Kelly criterion found by setting a derivative to zero, and the probability of long losing streaks and ruin. Then backtesting: turning a rule into an equity curve, charging realistic costs, and testing whether the result is better than luck rather than the product of trying many rules. Finally value at risk and stress testing: how banks, brokers and funds put a number on "how much could we lose", and where that number fails. Every price series in these pages is simulated, so you can see what pure chance produces before you look at any real chart.
- compute SMAs, EMAs, the MACD, the RSI and Bollinger bands by hand or in a spreadsheet, and explain each as a weighted average, a ratio or a standard deviation;
- prove that every moving average lags a trend by its average age, explain why $\alpha=2/(n+1)$, and read a crossover as a delayed estimate of the slope;
- explain why no indicator can have an edge on a random walk, and test a signal's record against luck with the binomial distribution and a $t$-statistic;
- size a position from the risk per trade and the stop-loss, and estimate how often noise will hit the stop;
- compute a system's expectancy and break-even win rate, its Kelly fraction and the growth rate of any betting fraction, and explain why fractional Kelly is used;
- estimate the probability of long losing streaks and of ruin, by formula and by simulation;
- build an equity curve from a trading rule, measure its CAGR, Sharpe ratio and maximum drawdown after costs, and recognise overfitting and data snooping;
- compute historical, parametric and Monte Carlo value at risk and expected shortfall, and explain the limits of VaR.
Where this shows up in real life
Every Indian broking app and charting platform draws the indicators of §7.1, and many trading courses and social-media channels are built on them; knowing that an EMA is a geometric-series weighted average and that a band is a running standard deviation is the first defence against claims that a line "predicts" a move. The risk rules of §7.2 — risk per trade, stop-losses, position limits — are how professional desks and careful individual traders control losses, and the gap between win rate and expectancy is the most common reason a "90% accurate" system still loses money. SEBI has published studies of the profits and losses of individual traders in equity derivatives, and its rules for algorithmic trading, like the exchanges' risk checks, rest on the backtesting and execution ideas of §7.3. Banks, brokers, clearing corporations and mutual funds measure portfolio risk with value at risk and stress tests (§7.4), and exchange margin systems use the same kind of "how much could this lose in a day" calculation. In interviews for quant, risk and trading roles, the Kelly criterion, gambler's ruin, the longest-run problem and "is this backtest overfitted?" are classic questions.
Sections in this chapter
Technical Indicators as Mathematics
SMA and EMA as weighted averages and filters, lag and noise reduction, crossovers and MACD as slope estimates, RSI, Bollinger bands, support and resistance, and what signals can and cannot do on random data.
Risk Management: Position Sizing, Expectancy and Kelly
Risk per trade and stop-losses, fixed-fractional position sizing, how often noise hits a stop, win rate and expectancy, the Kelly criterion and fractional Kelly, gambler's ruin, losing streaks and risk of ruin by simulation.
Backtesting, Costs and Algorithmic Trading
Backtest logic and equity curves, a strategy's CAGR, Sharpe ratio and maximum drawdown, transaction costs and slippage, overfitting and data snooping, in-sample vs out-of-sample, testing significance, and how algorithmic orders are executed.
Value at Risk and Stress Testing
Historical, parametric and Monte Carlo VaR, portfolio VaR with correlations, expected shortfall, stress scenarios, and what VaR cannot tell you.
You need percentages, logarithms and geometric series (§1.1 and §1.2), log returns (§1.3), how orders and the bid–ask spread work (§2.1), and above all Chapter 3: volatility, the $\sqrt{\text{time}}$ rule, drawdowns and volatility drag (§3.1), correlation and the Sharpe ratio (§3.2), and random walks, geometric Brownian motion and Monte Carlo simulation (§3.3). From probability you need expected value, the binomial and normal distributions and the standard error of a mean; one derivative is used for the Kelly criterion. Options (§6.2) appear only in examples. A spreadsheet with AVERAGE, STDEV.P, RAND, NORM.S.INV and BINOM.DIST, or Python with numpy, is enough for every project. This chapter teaches mathematics, not trading: nothing in it is a recommendation to trade, and the honest conclusion of much of it is that edges are rare, small and expensive to find.