Quant interview toolkit · order statistics

Five serial numbers and a missing ledger

Five surviving tickets carry IDs 12, 29, 43, 58 and 80. You know that the ledger numbered trades consecutively starting at 1 and that five distinct tickets were sampled uniformly. The highest ID tells you at least 80 tickets existed. What can it tell you about the missing upper end?

A sample maximum hints at unseen labels

Unbiased total estimate

Five labels sampled uniformly without replacement from 1,…,N; German-tank estimator (k+1)m/k−1.

Count the samples that fit below a ceiling

Call the ledger size NN, the sample size kk and the sample maximum MM. Each of the (Nk)\binom Nk possible subsets is equally likely. The event M≤mM\le m says that the entire sample fits among the first mm IDs. For k≤m≤Nk\le m\le N,

PN(M≤m)=(mk)(Nk),PN(M=m)=(m−1k−1)(Nk).P_N(M\le m)=\frac{\binom mk}{\binom Nk}, \qquad P_N(M=m)=\frac{\binom{m-1}{k-1}}{\binom Nk}.

For the second expression, reserve ID mm and take the other k−1k-1 tickets from the preceding m−1m-1. The same counting works whichever particular smaller IDs you saw. Indeed the likelihood of the observed five-ticket set is 1/(N5)1/\binom N5 for every candidate N≥80N\ge80, and zero below 80. It decreases as NN grows. Maximum likelihood therefore picks 80, a value that can only equal or underestimate the true endpoint.

The empty gaps have exchangeable sizes

Line up the sampled IDs. Count the unsampled IDs before the first ticket, between adjacent tickets, and after the last ticket. For our five observations the gap counts are

11,16,13,14,21,N−80.11,\quad16,\quad13,\quad14,\quad21,\quad N-80.

Their sum is N−kN-k. Every nonnegative vector of k+1k+1 gaps summing to N−kN-k corresponds to exactly one possible sample, by inserting a sampled ticket between consecutive gaps. Thus all such vectors are equally likely and every gap has the same expectation, (N−k)/(k+1)(N-k)/(k+1).

The final gap equals N−MN-M. Rearranging its expectation gives

E[M]=k(N+1)k+1,N^=k+1kM−1.E[M]=\frac{k(N+1)}{k+1},\qquad \widehat N=\frac{k+1}{k}M-1.

With k=5k=5 and M=80M=80, the unbiased estimate is 95. You can read the correction directly from the observed gaps. The first five contain 75 unsampled tickets in total. Use their average of 15 as the estimate of the last gap. Unbiasedness describes repeated sampling at a fixed NN. It does not assign probabilities to possible values of NN after observing these tickets.

How large a ledger would make 80 surprising?

Try a candidate of N=144N=144. The chance all five tickets would land among the first 80 is (805)/(1445)≈0.04998\binom{80}5/\binom{144}5\approx0.04998. For N=143N=143 it is about 0.05178. Larger candidates make a maximum this small increasingly unlikely.

A one-sided 95% confidence procedure rejects each candidate for which PN(M≤m)≤0.05P_N(M\le m)\le0.05. At the true NN, the rejection event is a lower tail of the discrete maximum distribution with probability at most 5%. For the observed maximum, the retained integers run from 80 through 143. The gap between a point estimate of 95 and an upper limit of 143 conveys what five tickets leave unresolved.

from math import comb

def upper_95(max_id, k):
    if not 1 <= k <= max_id:
        raise ValueError("incompatible sample size and maximum")
    numerator = comb(max_id, k)
    low, high = max_id, 2 * max_id
    while comb(high, k) < 20 * numerator:
        high *= 2
    while high - low > 1:
        mid = (low + high) // 2
        if comb(mid, k) < 20 * numerator:
            low = mid
        else:
            high = mid
    return low

print(upper_95(80, 5))  # 143

The comparison uses integers so that even a tail probability exactly equal to 5% gets the stated treatment.

Practice

Model checkThe desk assigns odd IDs to buys and even IDs to sells. Your five tickets came only from the sell archive. Can you use the same calculation?
Show answer

Even if the five sells were uniformly sampled, they are not a uniform sample of all IDs. If sell IDs run consecutively as 2, 4, 6 and so on, dividing by two creates a consecutive sequence for the sell population. Inferring the total trade count requires additional information about the buys.

Edge caseWhat does a single randomly sampled ticket with ID 80 imply?
Show answer

The unbiased estimate is 159 because a uniform integer on 1,…,N1,\ldots,N has mean (N+1)/2(N+1)/2. The same confidence procedure retains candidates up to 1,599. At 1,600 the probability of a ticket at or below 80 is exactly 5%.