Quant interview toolkit · random permutations

How many record highs should a shuffled year produce?

Shuffle 252 distinct daily trading volumes into a random order. Read through the year and circle a volume every time it exceeds everything seen so far. The first day always gets a circle. Roughly how many more should you expect? The answer needs neither the volumes themselves nor a model for their tails.

Expected records grow like a harmonic sum

Expected record highs

For distinct values in a uniformly random permutation, position k sets a record with chance 1/k.

Condition on where the biggest value lands

Let IjI_j equal one when observation jj is a new high. Within the first jj observations, each position is equally likely to hold the largest. Hence P(Ij=1)=1/jP(I_j=1)=1/j. The number of records is Rn=∑j=1nIjR_n=\sum_{j=1}^n I_j, giving

E[Rn]=∑j=1n1j=Hn.E[R_n]=\sum_{j=1}^n \frac1j=H_n.

With 252 observations that is about 6.11 records, including the first. Doubling a long sample adds only about log⁡2\log 2 records in expectation because every day in the added block has to beat a long history. This argument needs uniform relative order and no ties. Independent draws from any continuous distribution supply those conditions, as does a uniform shuffle of a fixed set of distinct values.

Why two successive record indicators can be independent

A record today sets a high hurdle for tomorrow. How could the two indicators be independent? The answer depends on what you learned. Observing today’s numerical high supplies a threshold. Observing only its rank among preceding days supplies much less information.

To prove independence, write UjU_j for the rank of day jj among the first jj days, counting from the smallest. For example, the sequence of values 40,10,3040,10,30 has insertion ranks 1,1,21,1,2. Knowing these ranks reconstructs the ordering of the day labels. Start with day 1, insert day 2 at position 1, and insert day 3 at position 2. The sorted order of labels is then day 2, day 3, day 1.

There are 1⋅2⋯n=n!1\cdot2\cdots n=n! valid rank sequences, in one-to-one correspondence with the n!n! permutations. Every sequence therefore has probability 1/n!=∏j=1n(1/j)1/n!=\prod_{j=1}^n(1/j). Each UjU_j is uniform on its own range, independently of the others. Since Ij=1I_j=1 exactly when Uj=jU_j=j, the indicators are independent too.

Beyond the average

Independence gives the variance immediately:

Var⁡(Rn)=∑j=1n1j(1−1j).\operatorname{Var}(R_n)=\sum_{j=1}^n\frac1j\left(1-\frac1j\right).

For 252 days the standard deviation is about 2.11 records. For a small sample you can also compute exact probabilities. Each new day leaves the count unchanged with probability 1−1/j1-1/j, or increases it by one with probability 1/j1/j. Start with all the probability at zero records before day one.

def record_probabilities(n):
    probabilities = [1.0]
    for day in range(1, n + 1):
        updated = [0.0] * (day + 1)
        for count, mass in enumerate(probabilities):
            updated[count] += mass * (1 - 1 / day)
            updated[count + 1] += mass / day
        probabilities = updated
    return probabilities

For three days, the probabilities for one, two and three records are 1/3,1/2,1/61/3,1/2,1/6. One record means the largest observation appeared first. Three means the entire sequence was increasing. These two extremes give a quick check on the recurrence.

Which market series did you shuffle?

Randomly permuting observed daily volumes builds a reference distribution for the effect of ordering, conditional on the chosen values. A genuine trend or changing liquidity can violate uniform ordering. Ties also matter if the measurement has been rounded. A strict new high excludes ties. Random tie-breaking creates records in the artificially ordered tied values.

Applying the calculation directly to cumulative price levels introduces a different issue. Even if daily increments are independent and have identical continuous distributions, adjacent levels share their preceding increments. Their relative order generally lacks permutation symmetry. Specify the data being shuffled before using six records as a benchmark.

Practice

Block probabilityFor a uniform shuffle of 100 distinct observations, what is the probability that days 51 through 100 contain no record?
Show answer

Exactly one half. The largest observation must land somewhere in the first 50 days. Equivalently, independence gives ∏j=51100(1−1/j)=50/100\prod_{j=51}^{100}(1-1/j)=50/100.

Dependence checkWhat happens if you copy each daily value twice consecutively and count strict record highs?
Show answer

The second copy never breaks a record. The record count on the doubled sequence equals the original count. Treating all positions as a uniform ordering of distinct values would overstate its mean.