Tools

Randomness Calculator

Explore investment return randomness with Markov chain analysis of daily, monthly, or annual returns. Compare transition probabilities and Up/Down streak lengths with fair coin flips, using chi-square, runs, and shuffle tests to assess whether the observed sequence is consistent with randomness.

The Markov Chain

A Markov chain is a mathematical model of a sequence of events in which the probability of the next event depends only on the current state — not on anything that came before. Here the states are simply Up and Down months for the selected investment, and the chain measures how likely the market is to stay in its current state or switch. If tomorrow's direction were truly independent of today's, every transition probability would sit near 50% — a fair coin. This calculator computes those probabilities from the actual sequence of Ups and Downs and runs several statistical tests to see whether the market's memory is distinguishable from chance. For the origin, methodology, and surprising applications of Markov chains, please watch this video by Veritasium.

Reading the state transition diagram

Each circle is a state: U means the day's return exceeded the median return of the selected period, D means it fell below. The arrows are transitions from one day to the next, and the numbers on them are transition probabilities — the observed likelihood of moving from one state to the other (or staying put).

If tomorrow's direction were independent of today's, every arrow would read about 50% — a fair coin. The measured probabilities hover within about a point of 50%, statistically indistinguishable from chance: yesterday's winner tells you almost nothing about today. That is the Markov chain sequence test in a picture.

Glossary

Markov chain
A model of a system that moves between states where the probability of the next state depends only on the current state — not on the longer history.
State (Up / Down)
Each trading day is classified Up if its return exceeds the median return of the selected period, or Down if it falls below.
Median return
The middle daily return of the selected period — half of the days are above it, half below. Splitting at the median makes Up and Down equally likely, like the two sides of a fair coin.
Median / mean computed over
The selected window: calculates the median or mean using only returns between your Starting and Ending dates. Changing those dates can change the threshold used to classify returns as Up or Down. Full history: calculates the threshold using all available history loaded for the selected investment and return frequency, including returns outside your chosen dates. This keeps a common threshold when comparing different date ranges with the same data settings. In both cases, the transitions and statistical tests still analyze only your selected date range. Switching scope can change the Up/Down classifications and results without changing the selected dates.
Transition probability
P(next | current): the observed likelihood of moving from yesterday’s state to today’s. For example, P(Up | Down) is the share of Down days that were followed by an Up day.
Tie
A day whose return exactly equals the median. The tie rule decides whether it counts as Up (the default), Down, or is excluded with the transition bridged from the prior day to the next.
Significance level (α)
The evidence bar for declaring memory: a test flags memory when its p-value falls below α. Raising α flags weaker evidence (and mislabels a truly fair coin more often); lowering it demands stronger proof. A detection at level α corresponds to 100% − α confidence. Currently set to 5%: tests fail when p < 0.05 (|z| > 1.96).
Wilson confidence interval
A range around each measured probability expressing statistical uncertainty at the chosen confidence level. If 50% lies inside the interval, the measured value is consistent with a fair coin.
Chi-square (χ²) test
Compares the observed transition counts with the counts a memoryless fair coin would produce. A p-value at or above the chosen significance level (α) means no statistically detectable memory.
Run (streak) length
The number of days in a row spent in the same state before it flips. A run of 1 is a single day flanked by the opposite state on both sides. A fair coin halves the expected count with each extra day — shown on the runs chart as the Coin: Heads and Coin: Tails bars beside the observed Up and Down runs.
Fair coin (memoryless)
A process where each outcome is 50/50 and independent of all previous outcomes. It is the benchmark the market’s Up/Down sequence is tested against.
Threshold (median / mean / zero)
The dividing line between Up and Down. The median (default) splits the days 50/50 like a fair coin; the mean is the average return; zero classifies every positive day as Up — the intuitive reading, but it makes Up days more common than Down days in a rising market.
Find longest 50/50 period
Sets the date range whose transition counts are nearest 25% each and whose P(next | current) values are nearest 50% — the longest range that rounds to exactly 50.00% wins.
Find longest random period
Sets the longest date range in which the fair coin (χ²), runs (Wald–Wolfowitz), and shuffle tests all pass at the chosen significance level (α), using the current threshold, tie rule, and scope. When several ranges tie for longest, the most recent wins. The shuffle test is randomized, so its p-value can differ slightly between runs.
Runs test (Wald–Wolfowitz)
Counts how many maximal same-state streaks (runs) the sequence contains and compares that with the number a random ordering would produce. Too few runs means streaky (trending) behavior; too many means zig-zagging. A p-value at or above the significance level means the ordering is consistent with randomness.
Rolling runs test
The Wald–Wolfowitz z-score recomputed over a sliding window that advances one period at a time. A z-score below the negative critical value means that window was streakier (fewer runs) than a fair coin at the chosen confidence; above the positive critical value means it was choppier (more runs). Inside the shaded band, the ordering is consistent with randomness — one full-period verdict can hide episodes of each.
Higher-order Markov test
Instead of conditioning on yesterday alone, condition on the last 2 or 3 states (e.g. Up-Up vs Down-Up) and test whether any longer pattern predicts the next move better than chance. A p-value at or above the significance level means even the longer memory adds no predictive power.
Longest streak context
The longest observed run of consecutive Up (or Down) periods, compared with the exact probability that a fair coin flipped the same number of times produces a streak at least that long. Long streaks feel meaningful but are usually well within what pure chance produces.
Conditional returns
The average next-period return following an Up period versus following a Down period. If yesterday’s direction carried useful information, these averages would differ significantly; a Welch t-test p-value at or above the significance level means knowing yesterday’s direction would not have improved expected returns.
Shuffle (permutation) test
The actual Up/Down sequence is reshuffled 1,000 times, destroying any day-to-day ordering while keeping the same mix of Ups and Downs. The p-value is the share of reshuffles whose transition structure is at least as extreme as the real sequence — at or above the significance level means the real ordering is indistinguishable from a random shuffle of itself.

Disclosures