In partnership with

Last Time the Market Was This Expensive, Investors Waited 14 Years to Break Even

In 1999, the S&P 500 peaked. Then it took 14 years to gradually recover by 2013.

Today? Goldman Sachs sounds crazy forecasting 3% returns for 2024 to 2034.

But we’re currently seeing the highest price for the S&P 500 compared to earnings since the dot-com boom.

So, maybe that’s why they’re not alone; Vanguard projects about 5%.

In fact, now just about everything seems priced near all time highs. Equities, gold, crypto, etc.

But billionaires have long diversified a slice of their portfolios with one asset class that is poised to rebound.

It’s post war and contemporary art.

Sounds crazy, but over 70,000 investors have followed suit since 2019—with Masterworks.

You can invest in shares of artworks featuring Banksy, Basquiat, Picasso, and more.

24 exits later, results speak for themselves: net annualized returns like 14.6%, 17.6%, and 17.8%.*

My subscribers can skip the waitlist.

*Investing involves risk. Past performance is not indicative of future returns. Important Reg A disclosures: masterworks.com/cd.

🚀 Your Algo Edge Just Leveled Up — Premium Plans Are Here!🚀

A year in, our Starter, Pro, and Elite Quant Plans are crushing it—members are live-trading bots and booking 1-on-1 wins. Now with annual + lifetime deals for max savings.

Every premium member gets: Full code from every article Private GitHub repos + templates 3–5 deep-dive paid articles/mo Early access + live strategy teardowns

Pick your edge:

  • Starter (€20/mo) → 1 paid article + public repos

  • Builder (€30/mo) → Full code + private repos (most popular)

  • Master (€50/mo) → Two 1-on-1 calls + custom bot built for you

Best deals: 📅 Annual: 2 months FREE 🔒 Lifetime: Own it forever + exclusive perks

First 50 annual/lifetime signups get a free 15-min audit. Don’t wait—the market won’t.

— AlgoEdge Insights Team

Imagine you’re a chef trying to figure out the secret ingredients in a stew without a recipe. You taste it, identify patterns, and group similar flavours together. That’s essentially what clustering algorithms do with data. It uncovers hidden patterns without being told what to look for. In finance, where markets twist and turn like a rollercoaster, clustering can help us spot market regimes — distinct periods where the market behaves in a certain way. Let’s dive into a new approach that’s shaking things up, and I’ll break it down with simple explanations and a sprinkle of code.

The clustering analysis on simulated stock returns

Beyond Bull and Bear: The Real Market Story

Most people know markets as either bull (prices zooming up) or bear (prices tumbling down). But that’s like saying the weather is just sunny or rainy — it’s too simple. Markets have moods — calm, wild, stuck in between. Clustering lets us find these subtler regimes by looking at data like stock prices, bonds, or commodities and grouping similar behaviours together.

The catch? Things get messy when you’re tracking multiple financial instruments (think stocks and bonds and oil prices). These assets don’t move independently — their relationships, like how much they wiggle together (correlation), shift over time. That’s where a new algorithm comes in, taking clustering to the next level.

A Smarter Way to Cluster Markets

In a recent paper, researchers unveiled a fresh twist on an old favourite: k-means clustering. If you’re new to this, k-means is like sorting marbles into jars based on their proximity to each other. Normally, it measures “closeness” using Euclidean distance — the straight-line distance between two points. But markets aren’t that straightforward.

Instead of Euclidean distance, this new approach uses either Wasserstein distance or Maximum Mean Discrepancy (MMD). Don’t worry — these sound fancy, but they’re better ways to compare distributions (think of them as the “shape” of the data, not just individual points). Financial data — like stock returns — lives in distributions, so these metrics capture the market’s quirks more effectively.

The full end-to-end workflow is available in a Google Colab notebook, exclusively for paid subscribers of my newsletter. Paid subscribers also gain access to the complete article, including the full code snippet in the Google Colab notebook, which is accessible below the paywall at the end of the article. Subscribe now to unlock these benefits

Here’s a quick Python snippet to give you a feel for traditional k-means versus this new vibe:

import numpy as np
from sklearn.cluster import KMeans

# Fake stock returns (2D: two stocks over time)
data = np.array([[1.2, 0.5], [1.1, 0.6], [-0.8, -1.0], [-0.9, -1.1]])

# Classic k-means with Euclidean distance
kmeans = KMeans(n_clusters=2, random_state=42)
labels = kmeans.fit_predict(data)
print("Regime labels:", labels)  # Output: [0 0 1 1]

In this toy example, k-means splits the data into two regimes. The new algorithm swaps Euclidean distance for Wasserstein or MMD, making it sharper at spotting shifts in how stocks move together, not just their raw values.

Does It Work? Testing the Waters

The researchers put their algorithm through its paces with two tests:

  1. Synthetic Data: They whipped up fake data with known regime switches — like a market flipping from steady to chaotic. The algorithm nailed it, spotting the changes like a pro.

  2. Real-World Data: They fed it S&P 500 data (think 500 big U.S. stocks). The result? It uncovered regimes you would miss just by eyeballing a chart — a quiet growth phase versus a jittery correction.

Picture this: a chart of the S&P 500 might look like a wiggly line, but the algorithm says, “Hey, from 2015 to 2018, things were steady; then 2020 hit, and chaos ruled.” That’s powerful.

The Year-End Moves No One’s Watching

Markets don’t wait — and year-end waits even less.

In the final stretch, money rotates, funds window-dress, tax-loss selling meets bottom-fishing, and “Santa Rally” chatter turns into real tape. Most people notice after the move.

Elite Trade Club is your morning shortcut: a curated selection of the setups that still matter this year — the headlines that move stocks, catalysts on deck, and where smart money is positioning before New Year’s. One read. Five minutes. Actionable clarity.

If you want to start 2026 from a stronger spot, finish 2025 prepared. Join 200K+ traders who open our premarket briefing, place their plan, and let the open come to them.

By joining, you’ll receive Elite Trade Club emails and select partner insights. See Privacy Policy.

Trading Smarter: Pairs Trading

One cool application is pairs trading. Imagine two stocks — like Coke and Pepsi — that usually move together. If they drift apart (Coke spikes, Pepsi dips), you bet they’ll snap back. Buy the cheap one, sell the expensive one, and profit when they realign. The trick is knowing when they’re likely to drift.

This algorithm spots regimes where correlations weaken or tighten. In a “stable” regime, Coke and Pepsi might stick close; in a “volatile” regime, they could diverge. Traders can pounce on those moments.

Here’s a simplified pairs trading idea in code:

import pandas as pd

# Fake price data for two stocks
dates = pd.date_range("2025-01-01", periods=4, freq="D")
stock_a = [100, 102, 101, 105]  # Coke
stock_b = [98, 99, 97, 102]     # Pepsi
df = pd.DataFrame({"A": stock_a, "B": stock_b}, index=dates)

# Correlation over a tiny window
corr = df["A"].corr(df["B"])
print("Correlation:", corr)  # Say, 0.95

# If correlation drops in a regime, look for divergence
spread = df["A"] - df["B"]
print("Spread:", spread)
# If spread widens (e.g., day 3: 4), trade!

In a setup, the algorithm flags the regime, and you’d refine this with more data.

Building Better Portfolios

Portfolios are like a balanced diet — you want assets that don’t all crash at once. By knowing the market’s regime, you can tweak your mix. In a “risky” regime, lean on bonds; load up on stocks in a “growth” regime. The result? Smoother returns, less stress.

I’ve identified a practical problem from the financial domain: identifying groups of stocks with similar price movement patterns for portfolio optimization or pairs trading. This is a well-documented use case in trading, often tackled with clustering techniques, as seen in resources like academic papers and trading blogs (e.g., discussions on stock clustering for pairs trading strategies).

Let’s break this down step-by-step, keeping it simple, and I’ll include Python code to make it actionable. We’ll assume the current date is February 20, 2025, and use clustering to solve this problem as if we’re working with fresh market data.

Problem Statement: A trader wants to group stocks from the S&P 500 based on their historical daily returns to identify cluster stocks that move similarly. This can help in:

  1. Pairs Trading: Finding pairs of stocks that diverge and converge predictably.

  2. Portfolio Diversification: Avoiding over-concentration in stocks with similar behaviour.

Why Clustering? Clustering is perfect here because it’s unsupervised — we don’t need predefined labels to group stocks. We’ll use their return patterns as features and let the algorithm uncover natural groupings.

Data Source: We’ll simulate S&P 500 stock returns for this example since real-time data requires APIs (like Yahoo Finance or Alpha Vantage). In practice, you’d fetch this data live, but I’ll create a synthetic dataset mimicking real stock behaviour.

Step 1: Define the Approach

We’ll use k-means clustering, a popular algorithm, to group stocks based on their daily returns (say, the last 30 days up to February 20, 2025). To make it more robust, we’ll:

  • Compute daily returns from price data.

  • Use correlation or raw returns as features.

  • Apply k-means with an optimal number of clusters determined by the elbow method.

For a twist, we could use the Wasserstein distance or MMD (as mentioned in the paper you provided). For simplicity and accessibility, we’ll stick with Euclidean distance in K-means. Which are widely used and effective for this task.

Step 2: Simulate the Data

Let’s create synthetic daily returns for 10 S&P 500 stocks over 30 days. In a real scenario, you’d replace this with actual data.

import numpy as np
import pandas as pd
from sklearn.cluster import KMeans
import matplotlib.pyplot as plt

# Set random seed for reproducibility
np.random.seed(42)

# Simulate daily returns for 10 stocks over 30 days (Feb 20, 2025, back 30 days)
stocks = ["AAPL", "MSFT", "GOOGL", "AMZN", "TSLA", "JPM", "BAC", "WMT", "KO", "PEP"]
n_days = 30
returns = np.random.normal(0, 0.01, (n_days, len(stocks)))  # Mean 0, volatility 0.01
returns += np.array([0.001, 0.002, 0.0015, 0.0025, 0.003, 0.0005, 0.0007, 0.001, 0.0012, 0.0013])  # Add trends

# Create DataFrame
df = pd.DataFrame(returns.T, index=stocks, columns=[f"Day_{i}" for i in range(1, n_days + 1)])
print("Sample Returns Data:")
print(df.head())

Output (Snippet):

         Day_1     Day_2     Day_3  ...
AAPL   0.0034   -0.0056   0.0078  ...
MSFT   0.0042    0.0013   0.0065  ...
GOOGL  0.0029   -0.0021   0.0043  ...
...

Each row is a stock, and each column is a day’s return. The slight trends simulate realistic stock behaviour.

Step 3: Apply K-Means Clustering

We’ll cluster stocks based on their return patterns. First, find the..

logo

Subscribe to our premium content to read the rest.

Become a paying subscriber to get access to this post and other subscriber-only content.

Upgrade

Keep Reading