Thursday 3 September 2026

Quant interview

Waiting for a quiet window in the order flow

medium · Poisson processes and inter-arrival times

Orders hit your book according to a homogeneous Poisson process of rate λ per minute. You want to slip a large order in during a lull — a time interval of length τ (minutes) during which no order arrives. Define T to be the first time at which such a lull completes: formally, the smallest t for which the interval [t−τ,t] contains no arrival. Let N be the number of orders that arrive strictly before the lull completes (i.e. in [0,T−τ)).

  1. Find 𝔼[N], the expected number of orders you see before the first qualifying lull.
  2. Find 𝔼[T], the expected time until the lull completes.
  3. Evaluate both for λ=6 per minute and τ=20 seconds.
Solution

The one idea that cracks it

Do not try to integrate over configurations of arrivals in [0,T]. Condition on the first inter-arrival time X1~Exp(λ) and exploit the memorylessness (strong Markov / independent increments) of the Poisson process:

This renewal-at-each-arrival is the step a candidate skips. Everything below is just executing it.

Part 1: expected number of orders

Let p=ℙ(X1<τ)=1−e−λτ. Conditioning on the first arrival:

𝔼[N]=p(1+𝔼[N])+(1−p)·0.

The 1 counts the order that just arrived; the 𝔼[N] is the independent restart. Solving,

𝔼[N]=p1−p=1−e−λτe−λτ=eλτ−1.

Equivalently: N is geometric, counting "short" gaps (each with success probability 1−p=e−λτ of being the terminating long gap), so 𝔼[N]=1−e−λτe−λτ.

Part 2: expected time

Let m=𝔼[T]. Condition on X1 again. If X1=x≥τ the lull completes at τ; if x<τ we have burned time x and restart, so T=x+T′ with T′ an independent copy:

m=τe−λτ+∫0τ(x+m)λe−λxdx.

Use ∫0τλe−λxdx=1−e−λτ and, by parts,

∫0τxλe−λxdx=1−e−λτλ−τe−λτ.

Substituting, the ±τe−λτ terms cancel:

m=1−e−λτλ+m(1−e−λτ).

Hence me−λτ=1−e−λτλ, giving

𝔼[T]=eλτ−1λ.

Note the clean relation 𝔼[T]=𝔼[N]/λ. That is not a coincidence: the wasted "short" gaps sum to (eλτ−1)/λ−τ in expectation, and adding the final τ recovers 𝔼[T]; the τ's cancel exactly.

Part 3: numbers

Here λτ=6×13=2, so eλτ=e2≈7.389.

Quantity Formula Value
𝔼[N] e2−1 ≈6.39 orders
𝔼[T] (e2−1)/6 min ≈1.065 min

Closing note

The qualitative punchline worth internalizing: waiting for a fixed quiet window costs time that grows exponentially in λτ, not linearly. A tempting wrong answer is to reason "a gap of length τ is e−λτ-likely, and I get a fresh gap every 1/λ, so 𝔼[T]≈τeλτ" — right order of magnitude in the blow-up but the wrong constant; the exact answer is (eλτ−1)/λ.

Answers:  𝔼[N]=eλτ−1,𝔼[T]=eλτ−1λ, numerically  ≈6.39 orders and ≈1.065 minutes.

Statistics in machine learning

When leave-one-out inherits the AIC overfit rate

medium · Model selection: AIC, BIC and cross-validation bias

Let X1,…,Xn be i.i.d.\ N(μ,1) with σ2=1 known. Consider two nested candidate models for the mean:

For a fitted model define the Gaussian log-likelihood ℓ=−n2log(2π)−12∑i(Xi−μ^)2, and the criteria AIC=−2ℓ+2k and BIC=−2ℓ+klogn, each minimized over the two models. Write X¯=1n∑iXi, S=∑i(Xi−X¯)2, T=nX¯2.

(a) Show that AIC selects M1 iff T>2 and BIC selects M1 iff T>logn. Assuming the true mean is μ=0, give the exact probability that AIC overfits (selects M1) as a closed form, evaluate it numerically, and show the corresponding BIC probability tends to 0; give its leading-order rate in n.

(b) Now score the two models by leave-one-out cross-validation (LOOCV): for each i refit the mean on the other n−1 points and predict Xi, summing squared prediction errors. Compute both LOOCV scores in closed form and reduce the rule "LOOCV prefers M1" to an inequality in T and S.

(c) Under μ=0, give the exact probability that LOOCV overfits, in closed form, and identify its n→∞ limit. Compare the outcome to AIC and to BIC.

Solution

(a) The two decision rules

Under M1 the MLE is μ^=X¯, giving −2ℓ1=nlog(2π)+∑i(Xi−X¯)2=nlog(2π)+S. Under M0, μ^=0, so −2ℓ0=nlog(2π)+∑iXi2. Using the decomposition ∑iXi2=S+nX¯2=S+T,

−2ℓ0−(−2ℓ1)=(S+T)−S=T.

Thus AIC1<AIC0 iff −2ℓ1+2<−2ℓ0+0, i.e. T>2(k1−k0)=2. Likewise BIC selects M1 iff T>logn. The generic fact behind this: twice the fitted log-likelihood gap of a one-parameter extension equals the score/Wald statistic, here exactly T=nX¯2.

Distribution of T under μ=0. With μ=0, X¯~N(0,1/n), so T=nX¯2~χ12 exactly (no asymptotics needed here). Hence

Pr(AIC picks M1)=Pr(χ12>2)=2(1−Φ(2)).

Numerically 2≈1.4142, Φ(1.4142)≈0.92135, so the probability is 2(0.07865)≈0.1573. This does not shrink with n: AIC overfits by one parameter with probability ≈15.7% regardless of sample size.

For BIC, Pr(χ12>logn)→0. Using the chi-square tail Pr(χ12>x)=2(1−Φ(x))~2/(πx)e−x/2 with x=logn (so e−x/2=n−1/2),

Pr(BIC picks M1) ~ 2πlognn−1/2.

BIC is consistent: it discards the spurious parameter with probability →1.

(b) Exact LOOCV scores

For M0 the prediction is the constant 0 irrespective of which point is held out, so its LOOCV score is CV0=∑iXi2=S+T.

For M1, the held-out mean is μ^−i=nX¯−Xin−1. The one-line computation people miss is the residual identity:

Xi−μ^−i=Xi−nX¯−Xin−1=nXi−nX¯n−1=nn−1(Xi−X¯).

Therefore

CV1=∑i(Xi−μ^−i)2=n2(n−1)2S.

LOOCV prefers M1 iff CV1<CV0, i.e. n2(n−1)2S<S+T, which rearranges to

T>S·n2−(n−1)2(n−1)2=S·2n−1(n−1)2.

So LOOCV uses the same statistic T as AIC, but against a random, data-dependent threshold S2n−1(n−1)2 rather than the fixed value 2.

(c) Exact overfit probability of LOOCV

Under μ=0 we need Pr(T>S2n−1(n−1)2). Two facts make this exact:

  1. T=nX¯2~χ12 and S~χn−12;
  2. X¯ and S are independent — this is the key step (Cochran's theorem, or Basu: the ancillary S is independent of the complete sufficient X¯ in the normal family). Without it the ratio would not have an F distribution.

Hence T/1S/(n−1)~F1,n−1, and the event T>S2n−1(n−1)2 is

(n−1)TS>(n−1)·2n−1(n−1)2=2n−1n−1=2+1n−1.

Therefore

 Pr(LOOCV picks M1)=Pr(F1,n−1>2+1n−1). 

As n→∞, F1,n−1⇒χ12 and the threshold →2, so this probability →Pr(χ12>2)≈0.1573 — exactly the AIC overfit rate.

Conclusion. LOOCV is asymptotically equivalent to AIC here: both keep a spurious parameter with limiting probability ≈15.7%, and neither is consistent. BIC alone drives the overfit probability to 0 (at rate ~2/(πlogn)n−1/2). The slight finite-n conservatism of LOOCV — its expected threshold is 𝔼[S]2n−1(n−1)2=(n−1)2n−1(n−1)2=2+1n−1, just above AIC's 2 — vanishes as n→∞.

Closing note

The tempting wrong answer is to declare cross-validation "honest" and therefore consistent for model selection. It is honest as an estimator of prediction error, but choosing the model with the smallest CV error is a different task: the effective complexity penalty LOOCV imposes is O(1) per parameter, matching AIC, not the O(logn) needed for selection consistency. The F1,n−1 identity above makes the equivalence exact rather than merely asymptotic in spirit, and it rests entirely on the independence of X¯ and S.


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