Branch: Quantitative Methods (Finance-Plus Ring) · Node QM1.05 · ~18 focused hours · Mastery gate ≥ 85%
A ₹2 crore position in the Bharat Midcap Composite (synthetic) carried a one-day 99% value at risk of ₹15,73,183 on the last day of a 500-day sample. On the quietest day in the same sample the identical position, the identical index and the identical model produced ₹3,50,944. Nothing changed except what had happened the day before, and the two numbers sit 4.48 times apart.
The standard deviation of that index over the whole 500 days was 1.3114% a day, and a risk report built on it would have shown ₹6,10,157 on both of those days. That single number is not wrong. It is answering a question nobody asked. A risk committee wants the standard deviation of tomorrow, and tomorrow's is not a constant.
The Quantitative Methods branch has so far treated variance as a fixed property of a series, estimated once and reused. Everything in the first half of this node exists because that assumption fails in exactly the way that costs money: quiet periods cluster, violent periods cluster, and the transition between them is the thing a model has to forecast. Engle's autoregressive conditional heteroskedasticity, which won a Nobel prize in 2003, is a regression you can run by hand on nineteen pairs of numbers, and the whole idea is that yesterday's squared surprise predicts today's variance.
Advertisement
The second half is a different problem with the same shape. An analyst with four candidate factors and thirty-six months of data can fit them all by ordinary least squares and get coefficients that look precise and mean almost nothing, because two of the four are 98% correlated. Penalised regression buys a large reduction in variance for a small deliberate bias, and the price of the purchase is a tuning parameter that has to be chosen by cross-validation rather than by eye.
Then the vocabulary. Support vector machines, nearest neighbours, classification trees, ensembles, neural networks and hierarchical clustering are the algorithms an analyst meets in a broker note, a vendor pitch or a data-science colleague's deck, and being unable to say what each one assumes is a professional handicap. The treatment here is concepts and hand arithmetic. Every coded build, every pipeline, every hidden-tested implementation belongs to the quant-code track, and the boundary is stated once and honoured everywhere.
One warning before you start, because it is the reason the gate is set where it is. The techniques in the back half of this node are the ones most likely to arrive on your desk already run, by a tool or a colleague, with a number attached and no assumptions named. A LASSO that zeroed a factor made a decision about this sample, not a discovery about the world. A dendrogram cut at a different height gives a different number of clusters, and on the same ten stocks below the count moves from two to five depending on nothing but the linkage rule. A classifier that is 89.5% accurate on a 12% default base rate can be worse than useless. None of those failures announces itself.
Learning objectives
By the end you can:
- Fit a linear trend and a log-linear trend to the same series by hand, back-transform the log-linear forecast correctly, state what each model assumes about growth, and read the Durbin-Watson statistic on both sets of residuals against the published bounds.
- Explain why a failed Durbin-Watson on a trend model is a specification verdict rather than a nuisance, and state what a correctly specified autoregressive model implies about residual autocorrelation at every lag, with the standard error 1/√T that makes the test operational.
- Apply the chain rule of forecasting to an estimated AR(1), iterate two and three periods ahead by hand, reconcile the chained answer against the closed form, and locate the mean-reverting level b₀/(1 − b₁).
- Compare models on out-of-sample rather than in-sample criteria: run a split-sample exercise in which the better in-sample model loses, quantify the loss in root mean squared error, and read coefficient instability across estimation windows as the warning it is.
- Run an ARCH(1) regression of squared residuals on their own lag, test the coefficient, say what a positive coefficient does to the parent regression's standard errors, and produce a one-step-ahead conditional variance and the value at risk it implies.
- State GARCH(1,1) at concept depth: persistence as α + β, the long-run variance ω/(1 − α − β), the half-life of a variance shock, and why volatility clustering is a measured fact rather than a figure of speech.
- Explain and compute penalised regression: why a penalty on coefficient size trades bias for variance, how ridge shrinks while LASSO shrinks and zeroes, what elastic net blends, and why λ must come from cross-validation.
- Describe support vector machines, k-nearest neighbours, CART, bagging, boosting, random forests and feed-forward neural networks accurately enough to say what each assumes, what its complexity dial is, and how it fails.
- Build an agglomerative hierarchical clustering from a distance matrix by hand, read a dendrogram at two cut heights, and demonstrate that the linkage rule and the cut height each change the answer.
- Choose the evaluation metric that fits the decision: compute accuracy, precision, recall, F1 and the area under the ROC curve from a confusion matrix, and show numerically why an accuracy-maximising threshold can be the expensive one.
The duality, stated once. Objectives 1 to 9 are what the gate rewards, and they are gated because they are what lets you audit an output. Objective 10 is where the money is. A tool will fit a GARCH, tune a LASSO and draw a dendrogram in four seconds; none of those outputs carries any visible sign of whether the window was long enough, whether standardisation happened inside the cross-validation folds, or whether the cut height was chosen before or after somebody saw the answer they wanted.
Prerequisites & connections
Builds on. QM1.02 supplied the regression machinery every technique here reuses: ordinary least squares, the standard error, the t-statistic, and the four diagnostics. Its Durbin-Watson treatment is the direct parent of the trend-model work below, and its heteroskedasticity section is the reason an ARCH coefficient matters at all. QM1.03 supplied autoregressive and moving-average processes, stationarity, the unit root and the machine-learning survey; the trend and AR work here completes what it started, and its supervised/unsupervised framing is assumed rather than repeated. QM1.04 supplied the dispersion and shape statistics, the sampling biases, and the multiple-testing discipline that the mini-project's honest model count feeds. From the analyst core, M2.03 and M4.01 supply the margin and returns vocabulary the worked examples borrow, and M9.01 supplies the position-sizing frame in which a conditional value at risk is actually used.
Feeds forward. DA2.01 builds supervised learning in code, with the tree and ensemble machinery described here turned into a graded scikit-learn pipeline. DA2.02 builds unsupervised learning, feature engineering and leak-free validation, including k-means and principal components. DA2.03 builds deep learning, natural language and the production forecasting pipeline, and it is where a network's forward pass and backpropagation get computed rather than described. QD1.02 constructs empirical factors and evaluates them, and it consumes the penalised-regression discipline set out here. QD1.03's backtesting harness enforces the chronological-split rule as an automated guard. QD2.02 turns a conditional variance forecast into a production risk engine with a value-at-risk backtest.
The deliberate non-overlaps are these. QM1.03 owns stationarity, unit roots, the augmented Dickey-Fuller test, cointegration and Monte Carlo simulation, and nothing here re-derives them; where a series below might be non-stationary, the test is named and its home is cited. DA2.01 and DA2.02 own the coded supervised and unsupervised builds, including trees, ensembles, k-means and principal component analysis; the concepts and hand arithmetic live here and the implementations live there, with no worked content duplicated in either direction. DA2.03 owns deep learning and natural language processing, so the network section below stops at a single forward pass. QD1.02 owns empirical factor construction and the information coefficient. QM1.04 owns the deflated Sharpe ratio and the false-discovery-rate screen that the mini-project's model count is an input to. AA1.03 owns performance attribution and the risk-adjusted measure family.
Core teaching content
1. What the time-series work already established, and what changes here
Nothing below re-teaches the following, and all of it is assumed. The left column is what you should already be able to do; the right column is what this node adds on top of it.
| Already established | What this node adds |
|---|---|
| An AR(1) is an ordinary regression of a series on its own lag; stationarity needs |φ| < 1 | The chain rule of forecasting, the mean-reverting level, and the residual-autocorrelation test that decides whether the order is right |
| The autocorrelation and partial autocorrelation functions, and the Box-Jenkins identification grid | The autocorrelation of squared residuals, which is a different object and the whole basis of volatility modelling |
| Deterministic trend against stochastic trend, and why the eye cannot separate them | Fitting a linear and a log-linear trend by hand, and using Durbin-Watson as the specification verdict |
| Stationarity, the unit root, the augmented Dickey-Fuller test, cointegration | Nothing. Those remain where they are, and a series suspected of a unit root is sent back there before anything here is applied to it |
| Overfitting as a bias-variance tradeoff, train/validate/test, k-fold cross-validation | Cross-validation used to choose a parameter rather than to report a score, and the penalty methods that need it |
| Supervised against unsupervised learning, named at survey depth | Six named algorithm families with their assumptions, complexity dials and failure modes, plus the evaluation set |
| Monte Carlo simulation and simulated value at risk | Conditional value at risk, where the variance input is forecast rather than assumed constant |
One idea runs through the whole node and it is worth stating before the arithmetic starts. Every model below has a complexity dial: the order of a trend polynomial, the penalty λ, the number of neighbours k, a tree's depth, the number of hidden units, the height at which a dendrogram is cut. Turning the dial toward complexity always improves the fit to the data you already have. Whether it improves anything else is a separate question, answerable only with data the model has not seen.
Log-linear trend model
A log-linear trend model regresses the natural log of a series on time, so its slope is a steady proportional change per period. It suits series that grow at a rate, such as revenue or dividends, though the exact growth rate comes from exponentiating the slope and subtracting 1. A forecast needs a correction too: exponentiating the fitted log value gives the median of the forecast distribution, and the mean sits above it.
3 min read, on its own page
Durbin-Watson test
The Durbin-Watson test checks whether a regression's residuals are correlated with the residuals just before them. Its statistic runs from 0 to 4 and sits near 2 when successive residuals are unrelated, with lower values pointing to positive autocorrelation and higher values to negative autocorrelation. On a trend model a reading well below 2 means the line is the wrong shape, and a corrected standard error won't fix that.
3 min read, on its own page
4. The chain rule of forecasting
An estimated AR(1) forecasts one period ahead directly:
x_hat(T+1) = b0 + b1 x_T
For two periods ahead you have no observed x at T + 1, so you feed the forecast back into the same equation, and for three periods you feed that forecast back again. Iterating an estimate through its own output is the chain rule of forecasting, and it has a closed form worth carrying:
x_hat(T+k) = mu + b1^k (x_T - mu), where mu = b0 / (1 - b1)
That μ is the mean-reverting level, the value the series settles at when every future shock is set to its expectation of zero. Because |b₁| < 1 for a stationary series, b₁^k shrinks toward zero, so every long-horizon forecast from an AR(1) converges on μ regardless of where the series happens to be today. Ridgeline Freight Systems' gross margin sits at 23.37% in the last observed quarter with an estimated level of 21.8499%, so the eight-quarter path walks the gap down from +1.5201 points to +0.2179 points, and it never crosses.
The half-life of a shock, ln(0.5)/ln(b₁), converts b₁ into the unit an analyst can act on. At b₁ = 0.7844 the half-life is 2.85 quarters, so a margin surprise this quarter is half gone in under nine months. Closing 95% of the gap takes ln(0.05)/ln(b₁) = 12.34 quarters, which is a slower reversion than most equity narratives assume.
Two disciplines attach to the chain rule and both are commonly skipped. The chained forecast and the closed form must agree to machine precision, and on the eight-step path below the largest discrepancy is zero, which is the arithmetic check you run before quoting anything. And the forecast interval widens with k in a way the point forecast conceals, because the variance of a k-step AR(1) forecast error is σ²(1 + b₁² + b₁⁴ + ... + b₁^(2k−2)), which converges to σ²/(1 − b₁²) rather than growing without bound. A point forecast eight quarters out that is quoted to two decimals and no interval is a presentational choice, not a statistical one.
In-sample vs out-of-sample
In-sample fit measures how well a model matches the data it was estimated on, and out-of-sample fit measures how well it predicts data it never saw. Analysts compare the two because a model that wins in sample can lose out of sample, as a straight-line trend did against an AR(1) on an operating margin series. The usual safeguard is to hold out the last few periods before fitting anything.
3 min read, on its own page
ARCH model
An ARCH (autoregressive conditional heteroskedasticity) model lets the variance of today's regression error depend on the square of yesterday's error, so big surprises tend to follow big surprises. You test for it by regressing the squared residuals on their own lag and checking that the slope is reliably positive. Analysts care because ignoring ARCH makes ordinary standard errors too small, and a fitted model gives a one-step-ahead variance forecast for value at risk.
3 min read, on its own page
GARCH(1,1) model
A GARCH(1,1) model makes today's variance depend on yesterday's squared surprise and on yesterday's variance, which gives volatility a long memory. Its persistence is the sum of the two coefficients: below 1 the forecast drifts back to a long-run variance, and the closer to 1 it sits, the slower a variance shock fades. Analysts use it because volatility clustering is a measured fact, and it forecasts variance many days ahead.
5 min read, on its own page
Ridge vs LASSO regression
Ridge and LASSO are regressions that add a penalty on the size of the coefficients, accepting a small bias in return for a large cut in variance. Ridge shrinks every coefficient toward zero, while LASSO can set some exactly to zero and so drops those predictors. Analysts use them when predictors are nearly collinear, because ordinary least squares then gives unstable coefficients, and the penalty has to be chosen by cross-validation.
5 min read, on its own page
9. Support vector machines
Two labelled groups that can be separated by a straight line can usually be separated by infinitely many straight lines. A support vector machine picks the one with the widest margin, where the margin is the perpendicular distance from the boundary to the nearest point on either side. Cortes and Vapnik set out the modern form in 1995.
The consequence worth carrying is that only the points sitting on the margin matter. Those are the support vectors, and moving any other point, however far, changes nothing at all about the fitted boundary. That makes the method insensitive to outliers that sit deep inside their own group and highly sensitive to a handful of borderline cases, which is a very different failure profile from a regression, where every observation pulls on the line.
Real data is rarely separable, so the soft-margin version allows violations and charges for them through a cost parameter C. Large C means violations are expensive, so the boundary contorts to classify the training data, which is the high-variance end. Small C means violations are cheap, so the boundary stays smooth and misclassifies more training points, which is the high-bias end. C is the complexity dial, and it is chosen by cross-validation like every other one.
The kernel trick extends the method to boundaries that are not straight, by computing inner products in a higher-dimensional space without ever constructing that space. A radial-basis kernel can separate almost anything, which is precisely why it can also memorise almost anything.
10. K-nearest neighbours, and why scaling decides the answer
Predict a new observation by finding the k training observations closest to it and taking their majority label or their average value. Cover and Hart formalised the idea in 1967, and it remains the only method here with no parameters at all: the training set is the model.
Small k means a jagged boundary that follows every local quirk, which is high variance. Large k smooths the boundary and eventually predicts the overall base rate for everything, which is high bias. At k = 1 the training error is exactly zero and carries no information whatsoever, because every point is its own nearest neighbour.
Two choices decide the output and neither is a detail. The distance metric defines what "close" means, and Euclidean, Manhattan and correlation distance can rank the same neighbours differently. The scaling of the features decides which feature the distance is really measuring. Consider six firms described by revenue growth in percent, which ranges from 7 to 26, and net debt to EBITDA, which ranges from 0.45 to 3.40. A raw Euclidean distance is almost entirely a statement about growth, because growth's numbers are an order of magnitude larger. Practice problem 7 works exactly this case: on raw features the three nearest neighbours of a query firm vote 2 to 1 for "downgraded", and after standardising both features to unit variance the same query's three nearest neighbours vote 3 to 0 the other way. Same data, same k, same metric, opposite answer.
Nearest neighbours also degrades badly as the number of features grows. In high dimensions the distance from a point to its nearest neighbour and to its farthest neighbour converge, so "nearest" stops meaning anything, and the volume of the space grows so fast that any fixed sample becomes sparse. Ten features is usually fine and a hundred usually is not, which is why dimensionality reduction and nearest neighbours are so often used together.
CART decision tree
Classification and regression trees, from Breiman, Friedman, Olshen and Stone's 1984 book, split the data repeatedly on one feature at a time. At each node the algorithm searches every feature and every possible cut point, and takes the split that most reduces impurity. A tree grown until every leaf is pure has memorised the training set: its training error is zero, its structure changes completely when one observation is added, and its out-of-sample performance is often worse than a linear model's.
3 min read, on its own page
Bagging vs boosting
Bagging, from Breiman's 1996 paper, fits the same model to many bootstrap resamples of the training data and averages the predictions. Boosting works the other way. Instead of fitting many independent models and averaging, it fits models in sequence, each one trained on what the previous ones got wrong, and adds them with small weights. Gradient boosting is the dominant form on structured financial data.
2 min read, on its own page
Feed-forward neural network
A feed-forward neural network is a stack of alternating linear maps and non-linear squashes. Each layer multiplies its input vector by a weight matrix, adds a bias vector, and applies an activation function elementwise. The count of parameters is what should worry an analyst: a modest network with two hidden layers of fifty units on twenty inputs carries about 3,600 weights, which is more free parameters than most financial panels have observations.
2 min read, on its own page
Hierarchical clustering
Hierarchical clustering sorts observations into nested groups, usually by merging the two closest clusters again and again, and draws the result as a tree called a dendrogram. You choose the number of clusters afterwards, by cutting the tree at a height. Analysts have to state the linkage rule and the cut height, because on one set of ten stocks a single cut gave five clusters under average linkage and two under single linkage.
3 min read, on its own page
Machine learning project steps
A machine learning project on structured financial data runs in six steps, from writing down the decision the model will change to monitoring it on live data. The metric is set in the first step, before any data is touched, because a model with no named decision has no correct metric. Accuracy fails first: with a 12% default rate, a model that never predicts a default is 88% accurate, and the most accurate threshold can cost several times the cheapest one.
6 min read, on its own page
Common mistakes & how experts think differently
- Reading a low Durbin-Watson on a trend model as a standard-error problem. On a cross-sectional regression, serial correlation is a nuisance you correct for. On a trend fitted to a growing series it is a specification verdict, and Newey-West standard errors will silently make the wrong model look better behaved. The linear fit below returns DW = 0.4006 with three sign runs across twenty residuals; the expert changes the model, not the standard error, and the log-linear fit returns 1.8500.
- Quoting b₁ from a log-linear trend as the growth rate. The growth rate is e^b₁ − 1. At b₁ = 0.062567 that is 6.4565% a quarter, not 6.2567%, and the 20 basis point gap compounds to 0.96 percentage points a year. The same slip in reverse produces the back-transformation error, where exponentiating a fitted log gives the median rather than the mean and the smearing factor exp(s²/2) is the correction. And comparing the two models' R² figures is inadmissible, because a regression on rupees and a regression on log rupees do not share a total sum of squares.
- Choosing between a trend and an AR model on in-sample fit. Cascade Instruments' trend beats the AR(1) in sample on R², on t-statistic and on RMSE, and then loses out of sample by a factor of 2.47. The expert holds out the last few periods before fitting anything, scores both models on the identical target observations, and prints the parameter path across rolling windows, where the trend slope's decay from +0.3876 to +0.0345 was visible two years early.
- Testing an AR model's residuals at lag 1 only. A correctly specified AR model implies zero residual autocorrelation at every lag, so a clean lag-1 result with a significant lag-2 means the order is wrong. Use the 1/√T standard error and check four to six lags, and treat any |ρ̂|√T above 2 as a reason to re-specify rather than a curiosity.
- Ignoring ARCH because the coefficients are unbiased anyway. They are, and that is not the point. On the midcap mean equation the heteroskedasticity-consistent standard error is 32.1% larger than the ordinary one, which drops the t-statistic from −1.65 to −1.25 and widens the confidence interval by a factor of 1.32. Unmodelled ARCH manufactures significance, always in the direction that flatters the presenter.
- Estimating a volatility model on a window short enough to hand-compute. The nineteen-pair window below returns a₁ = 0.9426 with a t-statistic of 2.52, which passes the 5% test and is nonsense: it implies an unconditional daily standard deviation of 3.1478% against a sample figure of 1.3114%, and it produces a value at risk 73% above the one the full-sample coefficients give on the same day. The expert always checks the model's own implied unconditional variance against the sample variance, because that single comparison catches a bad fit that every t-statistic passed. The same discipline catches a persistence estimate at or above 1, where ω/(1 − α − β) is undefined and the forecast diverges.
- Running a penalised regression on unstandardised predictors, or standardising outside the folds. A penalty on raw coefficient size is a penalty on your choice of units, so the predictor with the largest numbers carries the smallest coefficient, contributes almost nothing to the penalty and escapes the shrinkage its neighbours absorb. And computing means and standard deviations on the whole sample before cross-validating leaks the test rows into the scaling of the features used to predict them, always in the flattering direction. Fit every transformation inside each training fold.
- Reporting a LASSO's zero as a finding about the world. On the four-factor sample the LASSO keeps one twin and zeroes the other at λ = 0.20, and on 400 resamples of the same data it keeps the other one alone 15 times and keeps both 43 times. The expert writes "at λ = 0.20 chosen by five-fold cross-validation, LASSO retained X and dropped Y; on resampling, that selection held in 342 of 400 draws", which is a longer sentence and a true one.
- Optimising accuracy on an imbalanced target. A 12% default rate makes "never predict default" 88% accurate, and the accuracy-maximising threshold on the loan book below costs ₹1,54,20,000 against a cost-minimising ₹40,30,000. Name the two error costs first, then choose the threshold that minimises expected cost, and report precision, recall and the base-rate baseline beside whatever headline metric you quote.
- Presenting a dendrogram without its distance, linkage and cut height. The same ten-stock correlation matrix cut at 0.72 yields five clusters under average linkage and two under single linkage. A clustering is a triple of choices before it is a result, and an expert states all three, plus whether the cut height was fixed before the memberships were seen.
The thread through all ten is the same. Every technique in this node has a complexity dial and a set of choices that do not appear in the output. Turning the dial toward complexity always improves the fit you can see. What an expert does is name the dial, name the choices, and then go find the number the dial cannot improve, which is always an error measured on data the model was not allowed to touch.
Worked examples
Every figure below was produced by a Python computation before it was written down, and each example closes with an independent check on its own answer. All entities are synthetic. All series are simulated from stated data-generating processes, so they are internally consistent and they are not market data.
Worked example 1: Volatility clustering priced in rupees (India, ₹)
Bharat Midcap Composite (synthetic) has 500 daily returns. The sample mean is −0.0064% a day and the sample standard deviation is 1.3114%, or 20.8179% annualised. The sample excess kurtosis is 1.4800. Test for ARCH, fit an ARCH(1) by hand on the most recent twenty days, and price the difference between a conditional and an unconditional one-day 99% value at risk on a ₹2 crore position.
Solution. Step 1, look for the effect before modelling it. The lag-1 autocorrelation of the returns themselves is −0.0733, inside the ±0.0894 Bartlett band, so the sign of tomorrow's move is close to unpredictable. The lag-1 autocorrelation of the squared residuals is +0.2086 and the lag-2 is +0.1596, both outside the band. Magnitude is predictable where sign is not.
Step 2, the full-sample benchmark. Regressing e²_t on e²_(t−1) across all 499 pairs gives a₀ = 0.0001353957 (standard error 0.0000158866, t = 8.52) and a₁ = 0.212654 (standard error 0.044269, t = 4.80, p = 2.1 × 10⁻⁶). Engle's Lagrange multiplier statistic is n × R² = 499 × 0.044370 = 22.14 against a chi-square(1) 5% critical value of 3.84.
Step 3, the hand regression on the last twenty days. Working in units of 10⁻⁴ keeps the arithmetic on a calculator. The twenty most recent residuals, in percent, and their squares:
| Day | Residual | e² (×10⁻⁴) | Day | Residual | e² (×10⁻⁴) |
|---|---|---|---|---|---|
| 481 | −1.3750% | 1.8905 | 491 | +0.1137% | 0.0129 |
| 482 | −0.2020% | 0.0408 | 492 | −0.4717% | 0.2225 |
| 483 | +0.2263% | 0.0512 | 493 | −0.7785% | 0.6060 |
| 484 | +0.4433% | 0.1965 | 494 | −1.6219% | 2.6305 |
| 485 | −0.8482% | 0.7194 | 495 | +1.1955% | 1.4293 |
| 486 | +0.3230% | 0.1043 | 496 | +0.5607% | 0.3144 |
| 487 | −0.4398% | 0.1934 | 497 | −0.1113% | 0.0124 |
| 488 | −0.2764% | 0.0764 | 498 | +0.9774% | 0.9554 |
| 489 | −0.8505% | 0.7233 | 499 | −2.2924% | 5.2550 |
| 490 | −2.2401% | 5.0179 | 500 | +3.3949% | 11.5256 |
Nineteen pairs remain after lagging. The six sums are Σx = 20.4521, Σy = 30.0871, Σx² = 67.8966, Σxy = 75.6336, x̄ = 1.076427 and ȳ = 1.583533, giving centred sums S_xx = 45.8814 and S_xy = 43.2470. So
a1 = 43.2470 / 45.8814 = 0.942583 and a0 = 1.583533 - 0.942583 x 1.076427 = 0.568912
with SSE = 108.7532, SST = 149.5171, R² = 0.2726, s² = 6.397248, standard error of a₁ = 0.373404 and t = 2.5243 on 17 degrees of freedom against a two-tailed 5% critical value of 2.1098. The coefficient is significant.
Step 4, the one-step-ahead variance and the value at risk. Day 500's squared residual is 11.5256 × 10⁻⁴, so
h_501 = 0.568912 + 0.942583 x 11.5256 = 11.4327 x 10^-4 = 0.00114327
giving a conditional standard deviation of 3.3812%, which is 2.58 times the unconditional 1.3114%. At z = 2.326348 on ₹2,00,00,000:
| daily σ | 99% one-day VaR | |
|---|---|---|
| Conditional (ARCH, window fit) | 3.3812% | ₹15,73,183 |
| Conditional (ARCH, full-sample fit) | 1.9506% | ₹9,07,564 |
| Unconditional (sample σ) | 1.3114% | ₹6,10,157 |
| Conditional on the quietest day in the sample | 0.7543% | ₹3,50,944 |
Step 5, check the window fit against something. The window's coefficients imply an unconditional variance of a₀/(1 − a₁) = 0.00099084, a daily standard deviation of 3.1478%, against the directly computed sample figure of 1.3114%. The full-sample coefficients imply 0.00017196 against a sample 0.00017198, agreeing to four significant figures. The window fit fails a check the full-sample fit passes.
Read it. Two lessons sit on top of each other and both matter. Conditioning on yesterday genuinely moves the risk number, and the ₹9,63,026 gap between the window's conditional figure and the unconditional one is 4.8% of the position. And nineteen pairs cannot estimate a variance-persistence parameter, whatever the t-statistic says: the window's a₁ of 0.9426 against the full sample's 0.2127 inflates the same day's value at risk by ₹6,65,619, or 73%. Run the hand arithmetic to understand the machinery, then estimate on hundreds of observations, and always check the model's own implied unconditional variance against the sample's before quoting anything.
Worked example 2: Two factors that are the same factor (US, $)
A US manager has 36 monthly observations of a portfolio's excess return and four candidate factors: MKT, SMB, HML and VAL. The correlation between HML and VAL is 0.9834. The true data-generating process, which the analyst does not know, loads 0.90 on MKT and 0.55 on HML with residual standard deviation 2.4, and puts zero weight on SMB and VAL. Restated per one-standard-deviation move, the truth is MKT 4.2662, HML 1.9172, and zero for the other two.
Solution. Step 1, standardise, then run ordinary least squares. Every coefficient below is the effect of a one-standard-deviation move in its factor.
| Factor | OLS coefficient | Standard error | t | p | VIF |
|---|---|---|---|---|---|
| MKT | +4.500471 | 0.500001 | 9.00 | 0.0000 | 1.2183 |
| SMB | +0.041285 | 0.463834 | 0.09 | 0.9296 | 1.0484 |
| HML | +4.296105 | 2.664854 | 1.61 | 0.1171 | 34.6060 |
| VAL | −2.347551 | 2.711932 | −0.87 | 0.3933 | 35.8395 |
R² is 0.8056 and the residual standard deviation is 2.6800. Neither member of the collinear pair is significant, and one of them carries the wrong sign, yet their sum is +1.9486 against a true value of 1.9172. The data identified the sum to within 2%. It did not identify the split at all.
Step 2, ridge. Solving (Z′Z + λI)⁻¹Z′y:
| λ | MKT | SMB | HML | VAL | ‖b‖₂ | in-sample R² |
|---|---|---|---|---|---|---|
| 0 | 4.500471 | 0.041285 | 4.296105 | −2.347551 | 6.650072 | 0.805554 |
| 3 | 3.963792 | −0.053733 | 1.365396 | 0.625970 | 4.239184 | 0.794387 |
| 10 | 3.339768 | −0.082611 | 1.030374 | 0.907899 | 3.612039 | 0.768215 |
| 30 | 2.337226 | −0.084890 | 0.837029 | 0.864751 | 2.630256 | 0.670291 |
| 100 | 1.159806 | −0.046223 | 0.534577 | 0.567778 | 1.398367 | 0.436485 |
At λ = 10 the pair reads +1.0304 and +0.9079, summing to 1.9383 against the ordinary 1.9486. Ridge spread the sum sensibly across the twins and left the sum where the data put it.
Step 3, choose λ for the LASSO by five-fold cross-validation. Folds are five consecutive month blocks, and standardisation is refitted inside each training fold.
| λ | CV mean squared error | standard error | non-zero coefficients |
|---|---|---|---|
| 0.05 | 7.245615 | 0.614016 | 2 |
| 0.10 | 7.188673 | 0.631215 | 2 |
| 0.20 | 7.178447 | 0.674719 | 2 |
| 0.50 | 7.580777 | 0.758996 | 2 |
| 1.00 | 9.058802 | 0.871877 | 2 |
| 2.50 | 18.173341 | 1.972903 | 1 |
The minimum sits at λ = 0.20. The one-standard-error threshold is 7.178447 + 0.674719 = 7.853166, and the largest λ inside it is 0.50.
Step 4, the LASSO path.
| λ | MKT | SMB | HML | VAL | non-zero |
|---|---|---|---|---|---|
| 0.00 | 4.500471 | 0.041285 | 4.296105 | −2.347551 | 4 |
| 0.20 | 4.166888 | 0 | 1.848514 | 0 | 2 |
| 0.50 | 3.906832 | 0 | 1.588458 | 0 | 2 |
| 1.00 | 3.473406 | 0 | 1.155032 | 0 | 2 |
| 2.50 | 2.146030 | 0 | 0 | 0 | 1 |
At λ = 0.20 the LASSO keeps MKT and HML at 4.1669 and 1.8485, against truths of 4.2662 and 1.9172, and zeroes SMB and VAL. The selection happens to be right.
Step 5, ask how stable "right" is. Resample 30 of the 36 months, 400 times, and refit at λ = 0.20. The LASSO keeps HML alone 342 times, keeps VAL alone 15 times, and keeps both 43 times. On roughly one draw in seven the write-up would have named a different factor.
Step 6, check whether the penalty pays. Split at random into 24 fitting months and 12 test months, 500 times, and average the out-of-sample RMSE.
| Estimator | mean out-of-sample RMSE | against OLS |
|---|---|---|
| OLS | 2.961502 | |
| Ridge λ = 3 | 2.895613 | +2.22% |
| Ridge λ = 10 | 3.135781 | −5.88% |
| Ridge λ = 30 | 3.803625 | −28.44% |
| LASSO λ = 0.20 | 2.816494 | +4.90% |
| LASSO λ = 0.50 | 2.854580 | +3.61% |
Read it. Collinearity does not destroy information, it relocates it: the sum of the twins' coefficients was estimated to within 2% while each of them individually was a coin flip with a standard error more than five times the ordinary least squares standard error on MKT. The penalty bought a real 4.90% improvement in out-of-sample error, and pushing it further made things 28% worse, so the dial has an interior optimum and both ends of it are bad. The zero LASSO produced is a decision about this sample at this λ, and the only honest way to report it is with the resampling count attached.
Worked example 3: A trend that fails its own residual test (India, ₹)
Kaveri Diagnostics (synthetic) reports twenty quarters of revenue in ₹ crore:
41.64, 45.21, 42.61, 48.51, 53.30, 57.25, 59.73, 65.07, 66.93, 71.74, 75.53, 77.60, 83.09, 91.49, 94.76, 106.19, 113.04, 121.99, 123.33, 136.50.
Fit a linear trend and a log-linear trend, test both, and forecast the twenty-first quarter.
Solution. Step 1, the linear trend. Regressing revenue on t = 1 to 20 gives b₀ = 28.031526 (standard error 2.701868) and b₁ = 4.832759 (standard error 0.225548, t = 21.43), with R² = 0.9623 and residual standard deviation 5.816330. On the face of it this is an excellent fit.
Step 2, look at the residuals in order. Their signs across the twenty quarters run
+ + + + + + - - - - - - - - - + + + + +
which is three runs, not the ten or eleven that unrelated residuals would produce. The Durbin-Watson statistic is 0.4006, implying ρ̂ = 1 − DW/2 = 0.7997. At n = 20 with one explanatory variable, the published bounds are d_L = 1.20 and d_U = 1.41, so 0.4006 sits far below d_L and the null of no positive autocorrelation is rejected. The straight line is the wrong shape: it starts below the data, crosses above it in the middle, and falls below again at the end, which is what a straight line does to an exponential.
Step 3, the log-linear trend. Regressing ln(revenue) on t gives b₀ = 3.644616 (standard error 0.014685) and b₁ = 0.062567 (standard error 0.001226, t = 51.04), with R² = 0.9931 and residual standard deviation s = 0.03161349. The Durbin-Watson statistic is 1.8500, comfortably above d_U = 1.41, and the residual signs now alternate across nine runs.
Step 4, read the slope correctly. The implied quarterly growth rate is e^0.062567 − 1 = 6.4565%, not 6.2567%. Compounded over four quarters that is e^(4 × 0.062567) − 1 = 28.4367% a year.
Step 5, forecast and back-transform. For t = 21 the fitted log value is 3.644616 + 0.062567 × 21 = 4.958513, so the naive back-transform is e^4.958513 = ₹142.3819 crore. That is the forecast median. The smearing correction multiplies by exp(s²/2) = 1.00049983, giving ₹142.4531 crore as the forecast mean, a difference of 0.05%. The linear model's forecast for the same quarter is 28.031526 + 4.832759 × 21 = ₹129.5195 crore, which is ₹12.86 crore, or 9.93%, lower.
Read it. The linear model's R² of 0.9623 is high and worthless, because R² measures fit and the Durbin-Watson statistic measures whether the fit is the right shape. Two models that differ by 9.93% on a one-quarter-ahead forecast are not close, and the gap widens every quarter you extrapolate. Compare the two R² figures at your peril: they have different dependent variables and are not comparable, whereas the two Durbin-Watson statistics are measuring the same property and are.
Worked example 4: Iterating an AR(1) to its mean-reverting level (US, $)
Ridgeline Freight Systems (synthetic) reports 28 quarters of gross margin, in percent:
25.80, 24.35, 24.60, 24.06, 23.88, 22.59, 22.42, 22.25, 23.08, 22.26, 22.20, 21.08, 21.19, 20.94, 20.62, 19.60, 20.65, 21.17, 20.95, 21.33, 21.13, 20.54, 21.93, 23.04, 23.28, 23.18, 23.10, 23.37.
Fit an AR(1), forecast three quarters ahead by the chain rule, and locate the level the model reverts to.
Solution. Step 1, the fit. Regressing x_t on x_(t−1) across 27 pairs gives b₀ = 4.710391 (standard error 1.910444, t = 2.47) and b₁ = 0.784421 (standard error 0.085613, t = 9.16, p = 1.8 × 10⁻⁹), with R² = 0.7705 and residual standard deviation 0.646367.
Step 2, check the residuals at four lags, not one. With T = 27 the standard error of a residual autocorrelation is 1/√27 = 0.192450.
| Lag | ρ̂ | t = ρ̂ / 0.192450 | verdict |
|---|---|---|---|
| 1 | +0.037273 | +0.19 | not significant |
| 2 | +0.077353 | +0.40 | not significant |
| 3 | −0.138552 | −0.72 | not significant |
| 4 | +0.264934 | +1.38 | not significant |
The Durbin-Watson statistic on the same residuals is 1.8681. One lag is enough.
Step 3, the mean-reverting level. b₀/(1 − b₁) = 4.710391 / 0.215579 = 21.849928%, against a sample mean of 22.306786%. The half-life of a shock is ln(0.5)/ln(0.784421) = 2.8547 quarters.
Step 4, the chain rule. The last observation is 23.37%, which sits 1.5201 points above the level.
| Step | Chained forecast | Closed form μ + b₁^k (x_T − μ) | Gap to level |
|---|---|---|---|
| 1 | 23.042304% | 23.042304% | +1.192376 |
| 2 | 22.785252% | 22.785252% | +0.935325 |
| 3 | 22.583616% | 22.583616% | +0.733688 |
| 4 | 22.425448% | 22.425448% | +0.575520 |
| 8 | 22.067827% | 22.067827% | +0.217900 |
The two routes agree exactly, which is the arithmetic check. Closing 95% of the gap takes ln(0.05)/ln(0.784421) = 12.34 quarters.
Step 5, what the wrong model would have said. A linear trend on the same 28 quarters returns a slope of −0.071519 points a quarter (standard error 0.032061, t = −2.23) with R² = 0.1606 and a Durbin-Watson statistic of 0.2684, which fails the residual test badly. Its forecast eight quarters out is 20.7691% against the AR(1)'s 22.0678%, and the trend model has no floor, so forty quarters beyond the sample it forecasts 18.4805% and keeps descending.
Read it. The AR(1) says the margin is currently 1.52 points above where the business settles and will spend roughly three years closing most of that gap. The trend model says the margin declines forever at 7 basis points a quarter, which is not a statement anybody would make out loud about a freight business. Both fit the same 28 numbers. Only one passes its residual test, and the Durbin-Watson figures of 1.87 against 0.27 are the entire difference.
Worked example 5: The same ten stocks, two answers (India ₹ and US $)
Ten stocks, five Indian and five US, over 72 monthly returns. Cluster them on return correlation, using distance d = 1 − ρ. The correlation matrix, rounded to two decimals, is:
| BHRT | KAVR | NLGR | VNDH | MLBR | CSCD | BTRT | ALGH | KTLR | SNDH | |
|---|---|---|---|---|---|---|---|---|---|---|
| BHRT | 1.00 | 0.62 | 0.43 | 0.57 | 0.30 | 0.26 | 0.16 | 0.17 | 0.30 | 0.07 |
| KAVR | 0.62 | 1.00 | 0.48 | 0.60 | 0.21 | 0.24 | 0.19 | 0.06 | 0.08 | −0.05 |
| NLGR | 0.43 | 0.48 | 1.00 | 0.34 | 0.29 | 0.06 | −0.05 | −0.19 | 0.03 | 0.00 |
| VNDH | 0.57 | 0.60 | 0.34 | 1.00 | 0.26 | 0.12 | 0.14 | 0.06 | 0.25 | −0.03 |
| MLBR | 0.30 | 0.21 | 0.29 | 0.26 | 1.00 | 0.14 | 0.14 | 0.05 | 0.15 | 0.01 |
| CSCD | 0.26 | 0.24 | 0.06 | 0.12 | 0.14 | 1.00 | 0.62 | 0.57 | 0.16 | 0.29 |
| BTRT | 0.16 | 0.19 | −0.05 | 0.14 | 0.14 | 0.62 | 1.00 | 0.53 | 0.08 | 0.24 |
| ALGH | 0.17 | 0.06 | −0.19 | 0.06 | 0.05 | 0.57 | 0.53 | 1.00 | 0.18 | 0.10 |
| KTLR | 0.30 | 0.08 | 0.03 | 0.25 | 0.15 | 0.16 | 0.08 | 0.18 | 1.00 | −0.01 |
| SNDH | 0.07 | −0.05 | 0.00 | −0.03 | 0.01 | 0.29 | 0.24 | 0.10 | −0.01 | 1.00 |
The mean within-India correlation is 0.4097, the mean among the three core US names is 0.5747, and the mean across the two blocks is 0.0948.
Solution. Step 1, the merge sequence under average linkage. Subtract every correlation from 1 to get distances, then merge the closest pair repeatedly, recomputing each merged cluster's distance to the rest as the mean of the constituent distances.
| Step | Height | Merge |
|---|---|---|
| 1 | 0.3800 | BHRT + KAVR |
| 2 | 0.3800 | CSCD + BTRT |
| 3 | 0.4150 | (BHRT, KAVR) + VNDH |
| 4 | 0.4500 | (CSCD, BTRT) + ALGH |
| 5 | 0.5833 | (BHRT, KAVR, VNDH) + NLGR |
| 6 | 0.7350 | (BHRT, KAVR, VNDH, NLGR) + MLBR |
| 7 | 0.7900 | (CSCD, BTRT, ALGH) + SNDH |
| 8 | 0.8380 | Indian block + KTLR |
| 9 | 0.9183 | the two blocks |
Step 2, cut it twice. At height 0.50 the tree gives six clusters: {BHRT, KAVR, VNDH}, {CSCD, BTRT, ALGH}, and four singletons. At height 0.66 it gives five, because NLGR has joined the Indian core. At 0.74 it gives four, because MLBR joins too. One tree, three answers, and the analyst chose all three by choosing where to draw the line.
Step 3, change the linkage and hold the cut fixed. Complete linkage merges at 0.38, 0.38, 0.43, 0.47, 0.66, 0.79, 0.90, 0.97 and 1.19. Single linkage merges at 0.38, 0.38, 0.40, 0.43, 0.52, 0.70, 0.70, 0.71 and 0.74. Cut all three trees at 0.72:
| Linkage | Clusters at height 0.72 |
|---|---|
| Average | 5: {BHRT, KAVR, NLGR, VNDH}, {CSCD, BTRT, ALGH}, {MLBR}, {KTLR}, {SNDH} |
| Complete | 5: identical to average here |
| Single | 2: {BHRT, KAVR, NLGR, VNDH, MLBR, KTLR}, {CSCD, BTRT, ALGH, SNDH} |
Step 4, find out why. KTLR's largest correlations are +0.30 with BHRT, +0.25 with VNDH and +0.18 with ALGH, so it has one modest link into each block and no home in either. Single linkage merges on the smallest cross-pair distance, so one link of 0.70 is enough to absorb it; average linkage waits for the mean of all its cross-pairs to fall below the cut and never gets there.
Read it. KTLR and SNDH are the observations to report, because they are the ones whose membership depends on the choices rather than on the data. A dendrogram picture makes a clustering look like a discovery; the arithmetic makes it look like what it is, an answer conditional on a distance, a linkage and a height. Publish the triple, and say whether the height was fixed before the memberships were seen.
Worked example 6: The in-sample winner that loses out of sample (US, $)
Cascade Instruments (synthetic) reports 16 quarters of operating margin, in percent:
15.90, 18.02, 18.07, 17.22, 17.36, 18.98, 19.31, 19.22, 19.43, 19.66, 20.24, 20.14, 20.79, 20.16, 19.99, 19.55.
Fit a linear trend and an AR(1) on the first twelve quarters, then score both on the last four, which neither model has seen.
Solution. Step 1, fit both on the same eleven target observations. An AR(1) on Q1 to Q12 predicts Q2 to Q12, so the trend must be fitted to Q2 to Q12 too, or the comparison is rigged.
| b₀ | b₁ | t on b₁ | R² | in-sample RMSE | Durbin-Watson | |
|---|---|---|---|---|---|---|
| Trend | 16.905818 | +0.281636 | 5.73 | 0.7846 | 0.466625 | 1.4732 |
| AR(1) | 7.241609 | 0.629233 | 3.65 | 0.5966 | 0.638615 | 1.3994 |
The trend wins on every in-sample measure, and its slope of 0.2816 points a quarter is significant at better than the 0.1% level. The AR(1)'s implied mean-reverting level is 19.5314%.
Step 2, forecast the four held-out quarters.
| Quarter | Actual | Trend forecast | Trend error | AR(1) forecast | AR(1) error |
|---|---|---|---|---|---|
| Q13 | 20.79 | 20.5671 | +0.2229 | 19.9144 | +0.8756 |
| Q14 | 20.16 | 20.8487 | −0.6887 | 20.3234 | −0.1634 |
| Q15 | 19.99 | 21.1304 | −1.1404 | 19.9269 | +0.0631 |
| Q16 | 19.55 | 21.4120 | −1.8620 | 19.8200 | −0.2700 |
Out-of-sample RMSE is 1.150164 for the trend and 0.466447 for the AR(1), a ratio of 2.4658 to 1. The trend's errors grow monotonically because a straight line cannot stop climbing; the series had already reached the level the AR(1) identified.
Step 3, find the warning that was available in advance. Re-estimate the trend slope on rolling eight-quarter windows:
| Window | Slope | Standard error | t |
|---|---|---|---|
| Q1 to Q8 | +0.387619 | 0.114208 | 3.39 |
| Q3 to Q10 | +0.334405 | 0.085595 | 3.91 |
| Q5 to Q12 | +0.321667 | 0.070768 | 4.55 |
| Q7 to Q14 | +0.196548 | 0.044167 | 4.45 |
| Q9 to Q16 | +0.034524 | 0.072368 | 0.48 |
Read it. The AR(1)'s out-of-sample RMSE of 0.4664 is almost exactly its rival's in-sample RMSE of 0.4666, which is the cleanest possible statement of the difference between fitting and forecasting. The rolling-slope table is the diagnostic that was available before any of the forecasts were made, and it shows a parameter decaying by a factor of eleven across overlapping windows of the same series. A number that unstable is not a growth rate, and neither its standard error nor its t-statistic will tell you so, because both are computed as though the parameter were fixed.
Worked example 7: The metric that fits the decision (India, ₹)
Deccan Bharat Finance (synthetic), an NBFC, scores 200 loan applications with a model that outputs a default probability. 24 of the 200 actually default, a base rate of 12.0%. The mean score is 0.5960 for the defaulters and 0.3277 for the rest. A missed default costs ₹8,50,000; refusing a borrower who would have repaid costs ₹40,000 in forgone margin. Choose a threshold.
Solution. Step 1, tabulate the confusion matrix across thresholds.
| Threshold | TP | FP | FN | TN | Accuracy | Precision | Recall | F1 |
|---|---|---|---|---|---|---|---|---|
| 0.30 | 23 | 99 | 1 | 77 | 0.5000 | 0.1885 | 0.9583 | 0.3151 |
| 0.40 | 21 | 53 | 3 | 123 | 0.7200 | 0.2838 | 0.8750 | 0.4286 |
| 0.45 | 21 | 37 | 3 | 139 | 0.8000 | 0.3621 | 0.8750 | 0.5122 |
| 0.50 | 17 | 27 | 7 | 149 | 0.8300 | 0.3864 | 0.7083 | 0.5000 |
| 0.55 | 13 | 15 | 11 | 161 | 0.8700 | 0.4643 | 0.5417 | 0.5000 |
| 0.60 | 12 | 11 | 12 | 165 | 0.8850 | 0.5217 | 0.5000 | 0.5106 |
| 0.70 | 6 | 3 | 18 | 173 | 0.8950 | 0.6667 | 0.2500 | 0.3636 |
| 0.80 | 2 | 1 | 22 | 175 | 0.8850 | 0.6667 | 0.0833 | 0.1481 |
Step 2, compare against the do-nothing baseline. A model that never predicts a default is 88.00% accurate here, with recall of zero. At the 0.50 threshold the model scores 83.00%, which is below the baseline while being genuinely informative, and the accuracy-maximising 0.70 threshold beats the baseline by 1.50 percentage points while catching a quarter of the defaults.
Step 3, summarise the ranking rather than any threshold. The area under the ROC curve is 0.880445, computed three independent ways that agree: a trapezoid over all 166 distinct score cut points, a library routine, and the rank identity that AUC equals the probability a randomly chosen defaulter outscores a randomly chosen non-defaulter. A trapezoid over only the eight thresholds printed above gives 0.866122, understating the full figure by 0.0143, which is what a coarse grid costs.
Step 4, price the errors.
| Threshold | Misses × ₹8,50,000 | False alarms × ₹40,000 | Total expected cost |
|---|---|---|---|
| 0.30 | 1 | 99 | ₹48,10,000 |
| 0.40 | 3 | 53 | ₹46,70,000 |
| 0.45 | 3 | 37 | ₹40,30,000 |
| 0.50 | 7 | 27 | ₹70,30,000 |
| 0.60 | 12 | 11 | ₹1,06,40,000 |
| 0.70 | 18 | 3 | ₹1,54,20,000 |
Read it. The cost-minimising threshold is 0.45 and the accuracy-maximising threshold is 0.70, and choosing the second costs ₹1,13,90,000 more, or 3.8 times the minimum. Every number in that comparison came from one model and one set of scores, so the loss was created entirely by the choice of objective. The AUC of 0.8804 is the right number to quote when comparing two models, because it does not depend on the threshold; the expected cost is the right number to quote when choosing where to set one. F1 peaks at 0.45 too, which is not a coincidence: with a rare positive class and an expensive miss, F1 is a much better proxy for the decision than accuracy is.
Verification ledger
Every figure the examples print, restated at full precision with the independent route that confirmed it.
| Quantity | Value | Second route |
|---|---|---|
| WE1 window a₁ | 0.942583 | matrix ordinary least squares agrees to 2.2 × 10⁻¹⁶ |
| WE1 window a₀ | 0.568912 (×10⁻⁴) | same |
| WE1 h₅₀₁ | 0.0011432713 | σ 0.03381229, VaR ₹15,73,183.20 at z 2.326348 |
| WE1 full-sample a₁ | 0.212654, t 4.8037 | Engle LM 22.1407 against χ²(1) 3.8415 |
| WE1 model-implied σ (full sample) | 1.3114% | sample σ 1.3114%, agree to 4 significant figures |
| WE2 HML/VAL correlation | 0.9834 | VIFs 34.6060 and 35.8395 |
| WE2 ridge at λ = 10 | 3.339768, −0.082611, 1.030374, 0.907899 | library ridge agrees to 2.2 × 10⁻¹⁵ |
| WE2 LASSO at λ = 0.20 | 4.166888, 0, 1.848514, 0 | library LASSO agrees to 2.0 × 10⁻¹⁵ |
| WE2 CV minimum | λ = 0.20, mean squared error 7.178447 | one-standard-error threshold 7.853166 admits λ = 0.50 |
| WE3 linear DW | 0.400641 | ρ̂ 0.799679, three sign runs in twenty residuals |
| WE3 log-linear DW | 1.850029 | ρ̂ 0.074986, nine sign runs |
| WE3 quarterly growth | 6.4565% | e^0.062567 − 1; annual 28.4367% |
| WE3 Q21 forecast | ₹142.3819 crore naive, ₹142.4531 smeared | linear model ₹129.5195 crore, gap 9.93% |
| WE4 b₁ | 0.784421, t 9.1624 | four residual autocorrelation t-statistics all below 1.4 |
| WE4 mean-reverting level | 21.849928% | chained and closed-form forecasts agree exactly at eight steps |
| WE5 average-linkage merge heights | 0.38, 0.38, 0.415, 0.45, 0.5833, 0.735, 0.79, 0.838, 0.9183 | library agglomerative clustering returns the identical sequence |
| WE6 out-of-sample RMSE | trend 1.150164, AR(1) 0.466447 | ratio 2.4658; AR out-of-sample equals trend in-sample to three decimals |
| WE7 AUC | 0.880445 | trapezoid, library routine and the rank identity agree to 1.1 × 10⁻¹⁶ |
| WE7 cost-minimising threshold | 0.45 at ₹40,30,000 | accuracy-maximising 0.70 at ₹1,54,20,000 |
Practice set
Work each problem fully before reading its solution. A calculator is assumed. Numeric answers within about ±1% score as correct unless the problem states otherwise, and every entity is synthetic.
P1 (guided). Fit a linear trend by hand. A synthetic Indian firm reports EBITDA of ₹12.0, 13.1, 13.6, 15.0, 15.4, 16.9, 17.2 and 18.4 crore over eight quarters. Compute b₀ and b₁, the R², and the forecasts for quarters 9 and 10.
Solution. With t = 1 to 8, t̄ = 4.5 and ȳ = 15.2000. The centred sums are S_tt = 42.0000 and S_ty = 37.8000, so b1 = 37.8000 / 42.0000 = 0.90000000 ₹ crore a quarter and b0 = 15.2000 - 0.9000 x 4.5 = 11.15000000. The sum of squared residuals is 0.4000 against a total sum of squares of 34.4200, so R² = 0.988379, and the residual standard deviation is 0.258199. The standard error of b₁ is 0.039841, giving t = 22.59. Forecasts: ₹19.25 crore at t = 9 and ₹20.15 crore at t = 10.
P2 (guided). Read a Durbin-Watson statistic. A trend regression on 20 quarterly observations reports a residual sum of squares of 96.4 and a sum of squared first differences of residuals of 58.1. Compute the statistic, the implied ρ̂, and the verdict against d_L = 1.20 and d_U = 1.41.
Solution. DW = 58.1 / 96.4 = 0.60269710. Using DW ≈ 2(1 − ρ̂), rho_hat = 1 - 0.6027/2 = 0.69865145. Since 0.6027 is below d_L = 1.20, reject the null of no positive autocorrelation at the 5% level. On a trend model that is a specification verdict: try the log-linear form, and if it also fails, model the series' own past instead of calendar time.
P3 (guided). Iterate an AR(1). An estimated AR(1) has b₀ = 1.62 and b₁ = 0.76, and the last observation is 9.85. Give the mean-reverting level, the forecasts one, two and three periods ahead, and the half-life.
Solution. Level = 1.62 / (1 - 0.76) = 6.75000000. Chaining: 1.62 + 0.76 x 9.85 = 9.10600000; then 1.62 + 0.76 x 9.106 = 8.54056000; then 1.62 + 0.76 x 8.54056 = 8.11082560. The closed form μ + b₁^k(x_T − μ) returns the identical three figures, which is the check. Half-life = ln(0.5)/ln(0.76) = 2.525707 periods, so a shock is half gone in two and a half periods and 95% gone in eleven.
P4. Forecast a conditional variance and price it. An ARCH(1) fitted to a US equity's daily residuals gives a₀ = 0.00004 and a₁ = 0.38. Today's residual is −2.1%. Compute tomorrow's conditional variance and standard deviation, the 95% one-day value at risk on a $5,000,000 position, the two-day-ahead variance, and the model's implied unconditional standard deviation.
Solution. h = 0.00004 + 0.38 x (-0.021)^2 = 0.00004 + 0.00016758 = 0.00020758, so σ = 1.4408%. At z = 1.644854, VaR = 1.644854 × 0.014408 × 5,000,000 = $118,492. Two days ahead, h = 0.00004 + 0.38 x 0.00020758 = 0.00011888, σ = 1.0903%. The unconditional variance is 0.00004 / (1 - 0.38) = 0.00006452, a daily standard deviation of 0.8032%, so today's shock has left the market at 1.79 times its normal volatility, and by the second session ahead the model has already closed 62% of the variance gap.
P5. Read a GARCH(1,1) output. A fitted GARCH(1,1) reports ω = 0.0000032, α = 0.07 and β = 0.90. Today's variance is 0.00025 and today's residual is −1.9%. Give persistence, the long-run variance and its annualised volatility, the half-life, and tomorrow's forecast.
Solution. Persistence = 0.07 + 0.90 = 0.9700, safely below 1. Long-run variance = 0.0000032 / 0.03 = 0.00010667, a daily standard deviation of 1.0328% and an annualised 16.3951% at √252. Half-life = ln(0.5)/ln(0.97) = 22.7566 trading days. Tomorrow: 0.0000032 + 0.07 x 0.000361 + 0.90 x 0.00025 = 0.00025347, σ = 1.5921%. The gap to the long-run variance is 0.00014680 and it takes about 23 sessions to halve, so the market is 54% above its long-run volatility and will stay materially above it for a month.
P6. Ridge and LASSO on the same orthonormal design. Fifty observations, standardised and orthogonal predictors, ordinary coefficients 2.40, −1.20 and 0.35. Apply ridge at λ = 25, then the LASSO soft threshold at λ = 0.50, 1.30 and 2.50, and say what each family did.
Solution. With Z′Z = nI the ridge closed form collapses to a single factor n/(n + lambda) = 50/75 = 0.66666667, so the ridge coefficients are 1.600000, −0.800000 and 0.233333. The sum of absolute coefficients falls from 3.9500 to 2.633333, a third shrunk away, and nothing reached zero. The LASSO rule is b_j = sign(b_j) x max(|b_j| - lambda, 0). At λ = 0.50: 1.90, −0.70, 0, since 0.35 − 0.50 is negative. At λ = 1.30: 1.10, 0, 0. At λ = 2.50: 0, 0, 0, the intercept-only model. Ridge kept all three at every penalty and LASSO returned two, then one, then none. That progression is the coefficient path, and reading it is how you see which predictors survive pressure.
P7. Nearest neighbours, with and without scaling. Six firms are described by revenue growth in percent and net debt to EBITDA, with a label of 1 for "downgraded within a year":
| Row | Growth % | Net debt / EBITDA | Label |
|---|---|---|---|
| 1 | 26.0 | 3.40 | 1 |
| 2 | 22.0 | 3.10 | 1 |
| 3 | 24.0 | 2.90 | 1 |
| 4 | 9.0 | 0.60 | 0 |
| 5 | 12.0 | 0.90 | 0 |
| 6 | 7.0 | 0.45 | 0 |
Classify a query firm at growth 18.0 and net debt to EBITDA 0.70, using k = 3 and Euclidean distance, first on the raw features and then after standardising each feature by its sample standard deviation.
Solution. Raw distances are 8.443341, 4.664762, 6.390618, 9.000556, 6.003332 and 11.002841. The three nearest are rows 2, 5 and 3, whose labels are 1, 0 and 1, so the vote is 1. Standardising with means (16.666667, 1.891667) and standard deviations (8.286535, 1.377104) puts the query at (0.160904, −0.865342), and the distances become 2.185436, 1.808402, 1.753982, 1.088524, 0.738488 and 1.339811. The three nearest are now rows 5, 4 and 6, all labelled 0, so the vote is 0. Growth runs over a range of 19 and leverage over a range of 2.95, so the raw distance was almost entirely a growth calculation and the leverage variable was decorative. Standardising is not a refinement here; it is the difference between two opposite answers.
P8. Choose a split with the Gini index. A node holds 40 companies, 16 of which outperformed. Split A sends 18 left with 12 outperformers and 22 right with 4. Split B sends 25 left with 12 outperformers and 15 right with 4. Which split does CART take?
Solution. The parent's Gini is 1 - 0.40^2 - 0.60^2 = 0.48000000. Split A: left Gini 1 - (12/18)^2 - (6/18)^2 = 0.44444444, right 1 - (4/22)^2 - (18/22)^2 = 0.29752066, weighted (18 x 0.4444 + 22 x 0.2975)/40 = 0.36363636, gain 0.11636364. Split B: left 0.49920000, right 0.39111111, weighted 0.45866667, gain 0.02133333. Split A wins by a factor of 5.5. Split B moves 25 rows into a node that is still almost evenly divided, so it has bought volume without buying separation.
P9. Two linkages, two answers. Four assets have the distance matrix below. Build the agglomerative tree under single linkage and under complete linkage, and give the two-cluster solution from each.
| A | B | C | D | |
|---|---|---|---|---|
| A | 0 | 0.20 | 0.55 | 0.85 |
| B | 0.20 | 0 | 0.35 | 0.75 |
| C | 0.55 | 0.35 | 0 | 0.40 |
| D | 0.85 | 0.75 | 0.40 | 0 |
Solution. Single linkage merges A+B at 0.20, then (A,B)+C at 0.35 because the smallest cross-pair is B to C, then (A,B,C)+D at 0.40. Its two-cluster solution is {A, B, C} and {D}. Complete linkage merges A+B at 0.20, then C+D at 0.40, because (A,B) to C measured by the largest cross-pair is 0.55, then the two pairs at 0.85. Its two-cluster solution is {A, B} and {C, D}. Identical data, identical algorithm, different rule for measuring cluster-to-cluster distance, and C changes sides. Single linkage chained C onto the A-B group through one short link; complete linkage refused because C's farthest link into that group was 0.55.
P10. Score a rare-event classifier. A fraud screen on 1,000 transactions with 40 genuine frauds returns 34 true positives, 96 false positives, 6 false negatives and 864 true negatives. Compute accuracy, precision, recall and F1, and compare against the do-nothing baseline.
Solution. Accuracy = (34 + 864)/1000 = 0.898000. Precision = 34/130 = 0.261538. Recall = 34/40 = 0.850000. F1 = 2 x 0.261538 x 0.850000 / 1.111538 = 0.400000. A model that flags nothing is 960/1000 = 0.960000 accurate, so on accuracy alone this screen looks 6.2 points worse than doing nothing while catching 85% of the fraud. Three of every four flags are false alarms, which is the operational cost, and whether the trade is worth making depends on the cost of a review against the cost of a missed fraud.
P11. One forward pass. A network takes inputs (0.60, −0.40) into two ReLU hidden units with weight matrix [[1.2, −0.8], [0.5, 0.9]] and biases (0.10, −0.20), then into one sigmoid output with weights (1.5, −1.1) and bias 0.30. Compute the output. Then compute it again with identity activations and say what that reveals.
Solution. Hidden pre-activations: 1.2(0.60) + (-0.8)(-0.40) + 0.10 = 1.140000 and 0.5(0.60) + 0.9(-0.40) - 0.20 = -0.260000. ReLU passes 1.140000 and clips the second to 0, so the second unit contributes nothing on this input. Output pre-activation: 1.5(1.14) - 1.1(0) + 0.30 = 2.010000, and sigmoid(2.01) = 0.88184302. With identity activations the pre-activation is 2.296000 and the output is 0.90854522, but the important point is structural: the whole network collapses to the single linear map with weights (1.25, −2.19) and intercept 0.670000. Without a non-linearity, depth buys nothing at all.
P12. Rank two models honestly. Four held-out quarters come in at 8.40, 8.15, 8.62 and 8.30. A trend model forecast 8.72, 8.88, 9.04 and 9.20; an AR(1) forecast 8.36, 8.33, 8.31 and 8.30. The trend model had the lower in-sample RMSE. Score both and state the verdict.
Solution. Trend errors are −0.32, −0.73, −0.42 and −0.90, summing to 1.621700 squared, so RMSE = 0.636730, with a mean error of −0.5925 that is almost as large as the RMSE. AR(1) errors are +0.04, −0.18, +0.31 and 0.00, summing to 0.130100 squared, so RMSE = 0.180347, with a mean error of +0.0425. The ratio is 3.53 to 1 in the AR(1)'s favour. The trend's mean error being 93% of its RMSE is the diagnostic worth naming: the errors are almost all bias in one direction, which is the signature of an extrapolation that kept climbing after the series stopped. The in-sample ranking is not evidence and should not appear in the recommendation except as a warning.
Applied mini-project
Twelve series, two models each, and one honest count of everything you fitted. You are handed twelve quarterly series, six Indian and six US, each 16 quarters of a percentage measure (an operating margin, a gross margin or a return on capital). Fit a linear trend and an AR(1) to each, compare them out of sample, and write one page.
| Series | Q1 to Q16 |
|---|---|
| IN-1 Sundaram Auto Ancillaries | 13.40 14.41 15.25 17.22 16.99 16.36 15.89 16.92 16.99 17.93 17.83 17.11 16.33 17.03 16.29 15.96 |
| IN-2 Nilgiri Tea Estates | 12.90 11.41 10.74 9.71 10.20 9.58 10.59 11.95 12.03 11.78 11.41 11.79 10.88 10.60 11.11 10.59 |
| IN-3 Godavari Speciality Chem | 9.58 9.63 9.51 10.37 10.60 9.60 11.42 11.91 11.97 11.20 12.85 12.21 13.42 13.79 14.37 13.66 |
| IN-4 Malabar Logistics | 5.10 5.14 5.75 6.63 6.27 6.22 6.91 6.88 7.05 6.87 7.74 7.64 6.84 7.69 7.63 7.63 |
| IN-5 Vindhya Cement | 12.73 13.25 14.67 12.68 14.18 14.22 12.30 12.47 12.62 11.85 12.33 11.53 11.14 10.81 9.95 10.86 |
| IN-6 Chenab Hydro Power | 22.00 20.81 20.91 22.75 21.59 23.78 20.36 20.86 20.69 23.31 23.39 20.10 19.50 21.31 20.37 21.88 |
| US-1 Bitterroot Foods | 12.50 11.67 12.61 12.43 12.92 12.87 14.56 12.78 12.79 12.84 12.20 12.24 11.83 12.58 12.79 12.81 |
| US-2 Allegheny Fasteners | 20.84 21.74 22.59 22.78 22.40 23.24 22.96 23.10 24.06 24.85 25.05 26.25 25.04 25.70 25.86 27.27 |
| US-3 Kettle River Software | 26.80 29.33 29.60 30.70 32.09 32.68 32.14 32.19 30.86 30.43 31.90 32.85 31.59 32.11 32.16 29.84 |
| US-4 Sandhill Utilities | 18.30 17.76 16.95 16.84 18.29 17.97 17.73 17.67 17.95 17.20 16.42 16.57 17.87 17.75 17.33 18.11 |
| US-5 Del Norte Retail | 27.66 26.59 26.30 24.42 25.65 24.67 25.19 23.41 23.25 22.49 22.08 22.62 22.57 20.83 22.69 21.28 |
| US-6 Bighorn Medical Devices | 20.40 21.54 22.25 22.19 22.62 22.70 23.74 24.13 25.10 25.15 25.47 25.78 25.43 25.51 25.19 25.21 |
Artefact 1, twelve pairs of fits (2 tests). Fit both models on quarters 1 to 12 only. Fit the trend on quarters 2 to 12 so that both models are predicting the same eleven target observations. Report b₀, b₁, the standard error and t-statistic on b₁, the R², the in-sample RMSE and the Durbin-Watson statistic for each fit. Test 1: the AR(1)'s chained forecast and its closed form μ + b₁^k(x_T − μ) agree to at least eight decimals on every series. Test 2: every series' in-sample RMSE is computed on the same eleven observations for both models, and you show that it is.
Artefact 2, the out-of-sample scoreboard (2 tests). Forecast quarters 13 to 16 with each model, using one-step-ahead forecasts for the AR(1) and saying that you did, because the multi-step chained alternative is a different and harder question. Report both models' out-of-sample RMSE for all twelve series in one table. Test 3: the errors you report reconstruct the RMSE you report. Test 4: the mean error sits beside every RMSE, so a model whose errors are all one sign is visible.
Artefact 3, the flip list (1 test). Name every series on which the better in-sample model loses out of sample. For each one, give the in-sample and out-of-sample RMSE for both models, the ratio, and one sentence on the mechanism. Test 5: for each named series, the AR(1)'s mean-reverting level is inside the range of the last four actual observations, or you explain why not.
Artefact 4, the model count (1 test). State how many specifications you actually ran across the twelve series, counting every variant you fitted and discarded: a log transform tried and dropped, an AR(2) checked, a window shortened. Test 6: the count is a single integer, larger than 24, and it appears in the write-up rather than in a footnote.
Deliverable. One page carrying the two summary tables, the flip list with its mechanisms, the honest model count, and a closing paragraph naming the one series you are least confident about and the single additional quarter of data that would resolve it.
Rubric (18 points). Passing needs 14, with no zero on any row.
| # | Criterion | 0 | 1 | 2 | 3 |
|---|---|---|---|---|---|
| 1 | Both models fitted on identical target observations (Tests 1 to 2) | not done or not shown | done for some series | done for all twelve, shown | done, shown, with the chain-rule identity check printed |
| 2 | Out-of-sample scoreboard (Tests 3 to 4) | absent | RMSE only | RMSE reconstructs from stated errors | plus mean error beside every RMSE |
| 3 | Flip list correct and complete (Test 5) | absent or wrong | one of the three flips found | two found | all three found, each with a mechanism and the level check |
| 4 | Durbin-Watson reported and used | absent | reported | reported and read against the bounds | read, and used to change a model choice |
| 5 | Honest model count (Test 6) | absent | vague | an integer, stated | an integer, stated, with the discarded variants listed |
| 6 | Closing judgement | absent | restates the tables | names the weakest series | names it, with the exact next observation that would resolve it |
Any artefact whose test fails scores zero on its row, however well the page is written. The reason is the whole point of the exercise: a forecast comparison that was not run on identical target observations is not a comparison, and a model count that was rounded down is the one number in the deliverable that nobody else can check.
Reading & resources
Volatility models:
- Robert F. Engle, Autoregressive Conditional Heteroscedasticity with Estimates of the Variance of United Kingdom Inflation (Econometrica, 1982), the original ARCH paper and still the clearest statement of the idea. [Paid/library] [Advanced]
- Tim Bollerslev, Generalized Autoregressive Conditional Heteroskedasticity (Journal of Econometrics, 1986), the one extra term that made the family usable. [Paid/library] [Advanced]
- John C. Hull, Options, Futures, and Other Derivatives, the volatility-estimation chapter, for GARCH maximum likelihood and the term-structure-of-volatility argument in a practitioner's notation. [Paid] [Intermediate]
- The
archPython package documentation, for what a fitted GARCH output actually contains and how to read its standard errors. [Free] [Intermediate]
Penalised regression and statistical learning:
- Gareth James, Daniela Witten, Trevor Hastie and Robert Tibshirani, An Introduction to Statistical Learning, the standard first treatment of ridge, LASSO, trees, ensembles and cross-validation, with the coefficient-path figures this node's tables reproduce numerically. Freely downloadable from the authors. [Free] [Beginner to Intermediate]
- Trevor Hastie, Robert Tibshirani and Jerome Friedman, The Elements of Statistical Learning, the same material at research depth, including the bias-variance decomposition and the ensemble-variance identity. Freely downloadable from the authors. [Free] [Advanced]
- Robert Tibshirani, Regression Shrinkage and Selection via the Lasso (Journal of the Royal Statistical Society, 1996), for what the L1 penalty was designed to do. [Paid/library] [Advanced]
- Hui Zou and Trevor Hastie, Regularization and Variable Selection via the Elastic Net (JRSS, 2005), for why correlated groups need a mixed penalty. [Paid/library] [Advanced]
Trees, ensembles and evaluation:
- Leo Breiman, Jerome Friedman, Richard Olshen and Charles Stone, Classification and Regression Trees (1984), the source of CART, cost-complexity pruning and the impurity criteria. [Paid] [Advanced]
- Leo Breiman, Random Forests (Machine Learning, 2001), including the out-of-bag estimate and the variance argument for feature subsampling. [Free] [Advanced]
- Tom Fawcett, An Introduction to ROC Analysis (Pattern Recognition Letters, 2006), the clearest short treatment of ROC curves, AUC and the rank interpretation. [Free] [Intermediate]
Finance-specific discipline:
- Marcos López de Prado, Advances in Financial Machine Learning, for why standard cross-validation leaks on financial panels and what purging and embargoing do about it. [Paid] [Advanced]
- CFA Institute Level II Quantitative Methods, the readings on time-series analysis, machine learning and big-data projects, for the exam-form vocabulary and the project pipeline in its examinable shape. [Paid] [Intermediate]
Primary-source anchors for the data you will use:
- NSE and BSE historical index and equity data, and the RBI Database on the Indian Economy, for the Indian series behind any real version of these exercises. [Free] [Beginner to Advanced]
- CRSP, Fama-French factor libraries at Dartmouth, and FRED, for the US return and factor series a penalised regression is usually run on. [Free to Paid] [Intermediate]
Do the following rather than only reading. Take one real index, compute daily returns for the last 500 sessions, and run the squared-residual regression by hand on the last twenty days and by machine on all of them. Then compare a₀/(1 − a₁) against the sample variance you compute directly. Twenty minutes of watching a significant-looking coefficient produce an unconditional variance twice the sample's will teach you more about small-sample estimation than any chapter.
Teach it back & journal
Feynman prompt. Find a colleague who reports risk with a single historical standard deviation and walk them through one day of the midcap series. Give them the twenty squared residuals and have them compute the six sums themselves, then the slope of 0.9426, then the conditional standard deviation of 3.3812% against the unconditional 1.3114%. Make them state the value at risk both ways on a ₹2 crore position, out loud, so the ₹9,63,026 gap is a number they produced rather than one you showed them. Then hand them the full-sample coefficients, make them redo it, and ask which of the two answers they would have signed.
The second half is the harder conversation. Show them the four-factor table where two predictors correlate at 0.98 and ask which of the two factors matters. When they say neither is significant, show them that the sum was estimated to within 2% of the truth. Then show the resampling count, where the LASSO kept one twin 342 times out of 400 and the other 15 times, and ask them to write the sentence they would put in a client note. If the sentence names the sample, the λ and how λ was chosen, the idea has installed.
Journal prompt. For two weeks, every time you meet a fitted model in a broker note, a vendor deck or a colleague's spreadsheet, write down four things before you use the output. Name the complexity dial and the value it was set to, say how that value was chosen and whether any held-out data was involved, count the specifications tried before this one reached you, and name one error the model could make that its reported metric would not reveal.
Then answer in writing at the end of the fortnight. How many models arrived with the specification count attached? How many reported an out-of-sample number rather than a fit? How many clustering or classification results named their choices, which for a clustering means the distance, the linkage and the cut height, and for a classifier means the threshold and the base rate?
Finish with a paragraph about your own work. The mini-project asks for an integer, the count of every specification you ran, and that integer is the one number in the deliverable nobody else can verify. Write down what would tempt you to round it down, what you will do to make the honest count easy to produce, and which of this branch's checks you are most likely to skip when a deadline is close. Then write down what specifically will be wrong in the output when you skip it.
This module's flashcards and mastery quiz are wired into the app: see the node's Quiz and Reviews.