Back To Top

March 21, 2025

The Market Isn’t Always Random - Spot It with Return Direction Tests

A sign-based framework to detect non-random behavior in stock returns using binary return patterns over rolling windows

Most people assume markets are random. After all, that’s what the Chicago School teaches — and what much of modern finance is built on.

But some of the world’s top hedge funds and investors quietly disagree. And when you test return patterns, the data sometimes disagrees too.

If we analyze direction of returns, not their size, you can detect subtle inefficiencies — windows where price movements reject randomness. 

It’s a simple shift in perspective with surprising results. In this article, we’ll use discuss a framework to flag non-random behavior.

Figure - Non-random behaviour in stock prices (OPTIMIZED)

1. The Random Walk Assumption Isn’t Always Right

Price movements are typically modeled as a random walk. Today’s price reflects all known information and tomorrow’s move is unpredictable.

Efficient Market Hypothesis argues that trying to spot patterns is pointless. Prices follow a stochastic path, and the only free lunch is diversification.

But markets don’t always behave that cleanly.

Academic theory vs. observed behavior

The Random Walk Hypothesis gained traction after the 1965 work of economist Eugene Fama, who formalized the EMH. 

Later, in 1973, Burton Malkiel’s A Random Walk Down Wall Street popularized the idea for investors, arguing that “a blindfolded monkey” would do as well as a professional.

But since then, empirical research has poked holes in the theory. Studies have documented:

Empirically, Markets are not perfectly efficient — at least not all the time.

Market behavior during stress

During financial crises, prices don’t bounce randomly — they cascade. Panic selling and institutional flows create streaks of similar return signs, which a true random walk wouldn’t produce. 

These patterns reflect real-world feedback loops, not just ‘noise’.

Top Investors Know Markets Aren’t Fully Efficient

Even some of the most successful investors outright reject EMH.

Jim Simons, founder of Renaissance Technologies, built the most profitable hedge fund in history by exploiting repeatable patterns in price movements. His take on EMH?

“Of course markets aren’t random. If they were, I wouldn’t be here.”
 — 
Jim Simons, in an interview with Numberphile

Warren Buffett has also criticized EMH for decades, pointing to consistent outperformance by value investors as empirical evidence that inefficiencies do exist.

“I’d be a bum on the street with a tin cup if the markets were always efficient.”
 — 
Warren Buffett, Berkshire Hathaway Annual Meeting

George Soros goes even further, arguing that market prices often reflect biased perceptions rather than objective fundamentals — what he calls “reflexivity.”

When the smartest money in the world treats market inefficiencies as an opportunity — not a fantasy — it’s worth asking:

Even if its very difficult, can we detect when markets become temporarily predictable?

2. The Binary Return Direction Framework

This framework transforms daily returns into a binary signal. The idea is to focus on direction rather than magnitude. We start by computing daily returns as:

formula 1. returns calculation

where Pt​ is the closing price on day t. We then use a 60‑day rolling window to analyze these returns.

Within each window, we convert returns into binary values. A return greater than zero becomes 1. A non-positive return becomes 0. This simplifies the series to focus on the direction of change.

formula 2. binary classification of returns

Next, we count the number of runs. A run is a sequence of consecutive identical signals. We use the formula:

formula 3. counting runs

Here, I(⋅) is an indicator function that equals 1 when the condition is true and 0 otherwise.

We then compute the expected number of runs:

formula 4. expected number of runs when random

where n1​ is the count of positive signals and n2​ is the count of non-positive signals.

The standard deviation is given by:

formula 5. standard deviation

With these, we calculate the Z statistic:

formula 6. z statistic for number of runs

Finally, the two-tailed p-value is computed as:

formula 7. pvalue for runs

where Φ is the cumulative distribution function of the standard normal distribution.

If p<0.05, we flag the window as non-random. This suggests that during that period, the return directions do not follow a random pattern.

3. Python Implementation

3.1 Rolling Runs Test Analysis

We now apply the Runs Test across a 60-day rolling window to test for non-random behavior.

ASML stock prices are used as an example. They’re pulled via the yfinance library.

Each window is transformed into a binary return sequence:

  • 1 for a positive return
  • 0 for zero or negative

We then calculate the number of runs — sequences of identical signs — and compare it to the expected count under randomness. 

From this, we derive a Z-score and p-value. If the p-value drops below 0.05, we flag the window as statistically inefficient.

The plot highlights periods of directional inefficiency by overlaying test results directly onto the price and p-value timelines.

				
					import yfinance as yf
import numpy as np
import pandas as pd
import scipy.stats as stats
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.patches as mpatches
from statsmodels.tsa.stattools import adfuller
				
			
				
					# Global parameters
stock_symbol = 'ASML'
start_date = '2020-01-01'
end_date = '2025-12-31'
rolling_window = 60  # days

# Use a dark background style.
plt.style.use('dark_background')
				
			
Prev Post

Momentum or Reversion? Detecting Predictability Zones

Next Post

Trump Token Surge: Can Meme Coins Skyrocket Following Recent Endorsements?

post-bars
Mail Icon

Newsletter

Get Every Weekly Update & Insights

[mc4wp_form id=]

Leave a Comment