Thursday 27 August 2026

Quant interview

A run of exactly fifteen trades

easy · Combinatorial counting and pigeonhole arguments

A trader executes at least one trade on each of 30 consecutive trading days. Let ti≥1 be the (integer) number of trades on day i, for i=1,…,30.

(a) Suppose the total number of trades over the 30 days is at most 44. Prove that there is a block of consecutive days {i+1,i+2,…,j} on which she executes exactly 15 trades.

(b) Now drop the bound of 44. Exhibit a 30-day schedule (still at least one trade per day) on which no block of consecutive days totals exactly 15. What is the smallest possible total number of trades for such a schedule?

Solution

Part (a): the pigeonhole

Work with cumulative counts. Set a0=0 and ai=t1+⋯+ti. Because every ti≥1, the sequence is strictly increasing:

0=a0<a1<a2<⋯<a30≤44.

The number of trades on days i+1,…,j is exactly aj−ai, so we must produce a pair with aj−ai=15.

Consider the two families of integers

a1,a2,…,a30anda1+15,a2+15,…,a30+15.

That is 60 integers in total. Each lies in {1,2,…,59}: the first family because 1≤ai≤44, the second because 16≤ai+15≤59. Sixty integers into 59 boxes: by the pigeonhole principle two of them coincide.

The step a candidate skips is checking which two collide. The ai are pairwise distinct, and the ai+15 are pairwise distinct, so no collision happens inside a single family. The equal pair must therefore be cross-family:

aj=ai+15for some i<j,

and the days i+1,…,j total exactly 15 trades. ∎

Part (b): the sharp threshold

Avoiding a 15-block means choosing 0=a0<a1<⋯<a30=N (where N is the total) so that no two of these 31 values differ by exactly 15. Equivalently, we want a subset S⊆{0,1,…,N} with |S|=31, containing 0 and N, and free of any pair at distance 15.

Partition {0,1,…,N} by residue mod 15. Within one residue class the elements form a chain r,r+15,r+30,…, and "distance exactly 15" is precisely adjacency along this chain. A distance-15-free selection is thus an independent set in a path, whose maximum size for a path on L vertices is ⌈L/2⌉. Hence the largest distance-15-free subset of {0,…,N} has size ∑r⌈Lr/2⌉.

Write N+1=15q+s with 0≤s<15; then s residue classes have length q+1 and the other 15−s have length q, giving maximum free size

s⌈q+12⌉+(15−s)⌈q2⌉.

For N=59 we have N+1=60=15·4, so q=4, s=0, and the maximum free size is 15·2=30<31. The same computation gives ≤30 for every N≤59, so a 15-block is forced for all totals up to 59.

For N=60 we have N+1=61=15·4+1, so q=4, s=1, and the maximum free size is

1·⌈52⌉+14·⌈42⌉=3+28=31.

So N=60 is exactly the first total that permits a counterexample. An explicit one: take the cumulative set

{0,1,…,14}∪{30,31,…,44}∪{60},

which has 15+15+1=31 elements, none differing by 15. Its consecutive differences are the daily trade counts:

1,1,…,1⏟14,16,1,1,…,1⏟14,16,

i.e. 14 days of one trade, one day of 16, 14 more days of one trade, one final day of 16 — that is 30 days and 60 trades. Any window sum equals a difference of two cumulative values, and no two differ by 15, so no block totals 15.

Answer. (a) Such a 15-trade block must exist. (b) The smallest total permitting no 15-block is 60.

Closing note

The crude argument in (a) only certifies the conclusion up to a total of 2·30−15−1=44, and it is tempting to declare 44 the threshold and hunt for a counterexample at 45. There is none: the residue/independent-set count shows the true guarantee extends all the way to 59. The pigeonhole bound is correct but not tight — a useful reminder that surviving the pigeon count is sufficient, not necessary.

Statistics in machine learning

When observed and expected information part ways

medium · Generalized linear models and link functions

Let Y1,…,Yn be independent from a one-parameter exponential dispersion family, f(yi;θi,ϕ)=exp\{yiθi−b(θi)ϕ+c(yi,ϕ)\}, with b smooth and strictly convex, known dispersion ϕ>0, mean μi=b′(θi) and Var(Yi)=ϕb″(θi)=:ϕV(μi). Impose a GLM structure: fixed covariates xi∈ℝp, linear predictor ηi=xi⊤β, and a smooth invertible link g with g(μi)=ηi.

1. Show that the score for β is U(β)=1ϕ∑i=1nyi−μiV(μi)dμidηixi.

2. Now take the canonical link, i.e. θi=ηi. Compute the Hessian of the log-likelihood in β. Deduce that (i) the log-likelihood is concave, (ii) the observed information equals the Fisher information, and hence (iii) Newton–Raphson and Fisher scoring produce the same iteration.

3. Take Yi~Gamma, so V(μ)=μ2, together with the log link ηi=logμi (which is not canonical for the Gamma). - (a) Show that the observed information is J(β)=1ϕ∑iyiμixixi⊤ while the Fisher information is I(β)=1ϕ∑ixixi⊤ (in particular I does not depend on β). - (b) Take p=2 with intercept and one covariate, xi=(1,zi)⊤, and three observations with z=(−1,0,1). Suppose that at the MLE β^ the fitted ratios are yi/μ^i=(1.2,0.6,1.2). Verify these are consistent with the score equations, and compute the matrix J(β^)−I(β^).

Solution

1. The score

For a single observation, ℓi=1ϕ(yiθi−b(θi))+c(yi,ϕ), so ∂ℓi∂βj=1ϕ(yi−b′(θi))∂θi∂βj=1ϕ(yi−μi)∂θi∂βj. Chain the dependence θi↦μi↦ηi↦β. Since dμidθi=b″(θi)=V(μi), we have dθidμi=1V(μi), and ∂ηi∂βj=xij. Hence ∂θi∂βj=1V(μi)dμidηixij. Summing over i gives U(β)=1ϕ∑iyi−μiV(μi)dμidηixi. This is the standard GLM estimating equation: a covariate-weighted sum of residuals, with the weight 1V(μi)dμidηi absorbing both the variance and the link.

2. Canonical link: the Hessian loses its randomness

With θi=ηi=xi⊤β, ℓ(β)=1ϕ∑i(yixi⊤β−b(xi⊤β))+const. Differentiate once: U(β)=1ϕ∑i(yi−b′(ηi))xi=1ϕ∑i(yi−μi)xi (consistent with Part 1, since for the canonical link dμdη=b″=V). Differentiate again: ∇2ℓ(β)=−1ϕ∑ib″(ηi)xixi⊤.

The step a candidate can miss: the data yi have disappeared from the Hessian. Two consequences.

Newton–Raphson updates with the observed Hessian; Fisher scoring updates with the expected one. When the two coincide, so do the iterations. This is exactly the algebraic content of "the canonical link makes Fisher scoring the same as Newton–Raphson."

3. Gamma with log link: the two informations diverge

(a) Here V(μ)=μ2 and μi=eηi, so dμidηi=μi. Plugging into Part 1, U(β)=1ϕ∑iyi−μiμi2μixi=1ϕ∑i(yiμi−1)xi. Since yi/μi=yie−ηi, we have ∂(yi/μi)/∂βk=−yie−ηixik=−(yi/μi)xik, so ∇2ℓ(β)=−1ϕ∑iyiμixixi⊤,J(β)=1ϕ∑iyiμixixi⊤. Now the yi remain. Taking expectations, 𝔼[yi/μi]=1, so I(β)=1ϕ∑ixixi⊤, which depends only on the design — not on β at all, a pleasant surprise specific to the Gamma–log combination.

(b) Write ri:=yi/μ^i−1=(0.2,−0.4,0.2). The score equations U(β^)=0 read ∑irixi=0, i.e. ∑iri=0.2−0.4+0.2=0,∑iziri=(−1)(0.2)+0+(1)(0.2)=0. Both hold, so the configuration is a legitimate MLE.

The gap is J(β^)−I(β^)=1ϕ∑irixixi⊤,xixi⊤=(1zizizi2). Entrywise: the (1,1) entry is ∑iri=0; the (1,2) entry is ∑irizi=0 (these are exactly the two score equations); the (2,2) entry is ∑irizi2=(0.2)(1)+(−0.4)(0)+(0.2)(1)=0.4. Therefore J(β^)−I(β^)=1ϕ(0000.4) nonzero, so observed and expected information genuinely differ at the MLE.

Closing note

The instructive point is why the discrepancy survives at the optimum. The score equations force only the first-moment combinations ∑irixi to vanish; the informations differ through the second-moment combination ∑irixixi⊤, and the z2 direction is not among the constraints the score imposes. So the tempting reflex "observed information equals Fisher information at the MLE" is a canonical-link artifact (Part 2), not a general fact. For a non-canonical link the two coincide in expectation but not in realization, which is precisely why Fisher scoring and Newton–Raphson take different steps — and why standard-error formulas must state which information matrix they use.


Two new problems every morning at 8am · every day so far