Why the last missing market state takes so long to appear
A market-data test needs at least one example of each of ten message types. The first few types appear almost immediately. Nine are present before lunch. The team assumes the tenth will arrive just as quickly. Coupon collector mathematics explains why the final missing type is often the slowest part of the job, even when all types are equally common.
Decompose the wait into stages
Imagine independent observations, each equally likely to be any of types. After distinct types have been seen, a new observation is a previously unseen type with probability . The number of observations needed to advance from types to has a geometric distribution with mean . Add these stage waits from zero observed types through :
is the th harmonic number. For ten equally likely message types, , so expected full coverage is about 29.3 observations. That is nearly three times the naive ten-observation minimum. The final stage alone, moving from nine types to ten, has success probability each observation and expected wait ten. If the type you lack is genuinely rare, the wait can be much longer.
The expectation does not say that a sample of 30 is guaranteed to contain every type. At the moment you have one type missing, the probability of still missing it after another independent observations is . For , after another 20 observations that probability is . Long waits are a natural feature of the tail.
Coverage at a fixed sample size
If you collect exactly observations, let indicate that type has appeared. Type is absent with probability , so linearity of expectation gives
At , this is types. This statement is easier than the full distribution of coverage, and it is often sufficient for planning an exploratory dataset. It also explains a common visual impression: many types appear early, then progress slows. The expected number missing after is .
To bound the chance that at least one type is still missing, use a union bound over the missing-type events:
This is conservative because missing-type events are not independent, but it gives a simple sample-size target. To make the upper bound at most , it is sufficient to take . For ten types and a 5% target, this bound asks for about 53 observations. It is a guarantee under the equal-probability independent model, not an exact 95th percentile.
Unequal types change the question
Market states and message types are rarely equiprobable. If type has probability , its probability of being absent after independent draws is , and the expected number of distinct types is . A type with has expected waiting time 1,000 draws for its first appearance by itself. The equal-type formula should not be used to promise complete coverage when one category is much rarer than the rest.
Random sampling may not even be the right strategy for a test suite. If you can deliberately construct a valid example of each type, stratified collection can cover the taxonomy much faster. Random arrivals remain relevant when you need to know how long a passive live monitor might wait before it has seen all cases. The distinction is between coverage by design and coverage by chance.
Define the categories before counting
In a real data audit, classification rules matter. Are a cancel and a cancel-replace one type or two? Does a message count if required fields are corrupted? Do simultaneous messages in one market event count as independent draws? The formula assumes a fixed list of mutually exclusive categories and independent observations from an unchanging distribution. Bursty activity, market hours and regime shifts violate that assumption. A dataset can also contain all ten types but only one example of a crucial rare type; presence is a much weaker requirement than estimating that type’s behavior precisely.
For the related problem of estimating a rare failure rate after zero observed failures, see the rule of three. Coupon collector asks how long until every category appears; rare-event inference asks what an absence tells us about its rate. They are two views of the same thin-data problem.
One sighting is not a test sample
Suppose the tenth message type finally appears on observation 29. The collector has achieved nominal coverage, but a parser tested once on that type has almost no evidence about how it handles variations of the message. If a message type contains optional fields, different order sizes or several venue-specific encodings, “seen once” is an especially weak criterion. A coverage plan should distinguish a first sighting, a minimum number of examples, and a target confidence for an error rate.
For a rare type with appearance probability , the number of examples in independent draws is binomial with mean . If , even 1,000 draws give only one expected example, and the probability of zero examples is . Counting total feed messages without stratifying by type can conceal how little evidence exists for the cases the test most needs. Deliberate sampling is often cheaper than waiting for the passive collector to provide adequate rare-category coverage.
Watch coverage slow as the rarest gaps remain
Every observation is an independent draw from equally likely types. The curve is expected coverage, not a guarantee of full coverage.
Practice
Last categoryWith 20 equally likely message types and exactly one still unseen, how many additional independent messages do you expect to wait?Show answer
The missing type appears with probability on each draw. The geometric mean waiting time is 20 additional observations.
Expected coverageAfter 20 independent draws from 20 equally likely types, how many types do you expect to have seen?Show answer
. Twenty draws do not imply twenty distinct categories because repeats consume observations.