Quant interview toolkit · unequal probability sampling

Estimating a desk total from a deliberately thinned trade log

3 min readstatisticssamplingexpectation

A replay system retains every large execution but only one in ten small executions, selected by independent coin flips. The ledger tells you how many executions occurred. The retained payloads tell you their individual processing costs. Can you reconstruct the desk’s total cost without pretending every retained execution represents the same number of trades?

A rare sampled trade gets a larger weight

Horvitz–Thompson weight

An observed trade included with probability π represents 1/π similar design-weighted trades.

Make each trade pay its own way in expectation

Treat the day’s NN costs yiy_i as fixed. Let IiI_i indicate retention, with known inclusion probability πi>0\pi_i>0. Trade ii contributes Iiyi/πiI_i y_i/\pi_i to the estimate. Averaging over the logger’s random choices gives E[Iiyi/πi]=yiE[I_i y_i/\pi_i]=y_i. Adding up yields the Horvitz–Thompson estimator

T^=∑i:Ii=1yiπi,E[T^]=∑iyi=T.\hat T=\sum_{i:I_i=1}\frac{y_i}{\pi_i},\qquad E[\hat T]=\sum_i y_i=T.

The expectation calculation needs the correct marginal probability for each record. It does not require independent retention. For example, an exact quota and a sequence of independent coin flips can give the same marginal retention rate but different uncertainty.

A four-ticket ledger you can inspect in full

Two large executions cost 40 and 60 units and are always logged. Two small executions cost 3 and 7 units and each is retained independently with probability 0.1. The true total is 110. Here are all possible estimates:

Small tickets retainedProbabilityEstimated total
Neither0.81100
Only the 30.09130
Only the 70.09170
Both0.01200

The expected estimate is 81+11.7+15.3+2=11081+11.7+15.3+2=110. Most days with this same ledger and fresh retention coins would produce 100. The occasional large estimate compensates. An unbiased reconstruction can be quite far from the realized ledger on an individual day.

For independent retention, variances add:

Var⁡(T^)=∑iyi21−πiπi.\operatorname{Var}(\hat T)=\sum_i y_i^2\frac{1-\pi_i}{\pi_i}.

The two small tickets contribute 9(32+72)=5229(3^2+7^2)=522, giving a standard deviation of about 22.85 cost units. If the logger sometimes keeps an entire batch together, covariance terms enter. Knowing only the per-ticket probabilities then suffices for the expectation but generally leaves the variance undetermined.

Two different denominators

To estimate mean cost per execution when N=4N=4 is known, divide T^\hat T by four. Its expected value is 110/4=27.5110/4=27.5. If NN is missing, one option is to estimate the count by the same weighting trick, N^=∑Ii/πi\hat N=\sum I_i/\pi_i, then report T^/N^\hat T/\hat N. This produces a weighted average of the observed costs, but expectation does not pass through a random denominator.

For the four rows above the ratio estimates are 100/2100/2, 130/12130/12, 170/12170/12 and 200/22200/22. Their probability-weighted mean is about 42.84. In the common first row the inferred desk consists entirely of the two expensive executions. The estimated total and count are each unbiased and their ratio still has substantial bias in this small example.

Check which probability the logger actually recorded

Suppose a ticket first passes the intended 10% sampling gate and then its payload survives an independent 80% delivery gate. Its chance of appearing in the analyst’s file is 0.10(0.80)=0.080.10(0.80)=0.08. A weight of ten would recover only 80% of that ticket’s cost in expectation. If delivery failures depend on payload size in an unknown way, the intended sampling probability alone cannot repair the loss. A class that is never logged has no positive inclusion probability to invert.

Practice

Sampling designKeep the two large tickets and select exactly one of the two small tickets by fair coin. What are the possible estimates?
Show answer

Each small ticket has inclusion probability one half. The total estimate is either 100+2(3)=106100+2(3)=106 or 100+2(7)=114100+2(7)=114, each with probability one half. Its mean is 110 and its variance is 16. Selecting exactly one creates negative dependence between the two inclusion indicators.

UnitsWhat happens if you cap the inverse weight at five under the original 10% scheme?
Show answer

Each small ticket contributes only 0.1(5)yi=0.5yi0.1(5)y_i=0.5y_i on average. The expected total drops to 105. Weight capping trades away some of the design’s expectation guarantee for smaller swings in the estimate.