By Blake Rayfield

Using 10-K Filings Instead of Past Returns to Cluster Portfolios: Text-Based Hierarchical Risk Parity (TB-HRP)

Why historical return correlations break down for thinly traded stocks and recent IPOs, and how swapping in SEC Form 10-K text distances stabilizes Hierarchical Risk Parity in Python.

fintech
portfolio-optimization
nlp
python
hierarchical-risk-parity

Mean-Variance Optimization (Markowitz, 1952) is notoriously fragile out of sample. Small estimation errors in expected returns or the covariance matrix can trigger wild swings in portfolio weights and high turnover. Marcos López de Prado’s Hierarchical Risk Parity (HRP, 2016) solved much of that instability by replacing matrix inversion with three clean steps: hierarchical tree clustering, quasi-diagonalization, and recursive bisection.

Even so, standard HRP still has a blind spot: it builds the asset hierarchy entirely from historical return correlations.

When you allocate across liquid S&P 500 names with decades of clean price history, return correlations are usually informative. When you move into thinly traded equities, recent IPOs, or alternative assets—where trading history is short, sparse, or distorted by idiosyncratic shocks—historical correlations become noisy fast.

In my paper, “Text based hierarchical risk parity (TBHRP)” (Financial Markets and Portfolio Management, 40(3), 375–392, 2026), I test a straightforward modification: keep HRP’s quasi-diagonalization and recursive bisection, but build the Stage 1 clustering distance matrix from corporate text (SEC Form 10-K filings) instead of past returns.


Why 10-K Text Works for Portfolio Clustering

Public firms are legally required to describe their business models, risk factors, supply chains, and competitive landscape in annual Form 10-K filings. Compared to trailing return windows, 10-K disclosures offer three practical advantages for clustering:

  1. Forward-looking economic structure: Firms that share customers, input costs, or regulatory exposure describe similar risks in their filings—often before those links show up cleanly in trailing return correlations.
  2. Stability through idiosyncratic shocks: A single-day price dislocation (such as Meta’s ~19% earnings drop in July 2018) can warp return-based correlation trees overnight, whereas the underlying business description remains anchored in economic reality.
  3. Coverage where price history is thin: A newly public company or illiquid small-cap stock may have less than a year of trading data, yet still files a rich, standardized 10-K.

How TB-HRP Works in Python

The core change happens in Stage 1 (Tree Clustering). Instead of converting a return correlation matrix into a distance metric, we vectorize each firm’s 10-K text, compute pairwise cosine distances, and cluster using average linkage (which balances the chaining behavior of single linkage against the compactness of Ward linkage).

Below is a minimal, reproducible Python illustration of the TB-HRP pipeline using scikit-learn and scipy (full replication scripts using sec-api.io and sample inputs are in bkrayfield/TBHRP):

import numpy as np
import pandas as pd
from scipy.cluster.hierarchy import linkage, leaves_list
from scipy.spatial.distance import squareform
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_distances

def build_text_linkage(filings: dict[str, str], method: str = "average"):
    """Build a hierarchical clustering tree from firm 10-K text disclosures."""
    tickers = list(filings.keys())
    vectorizer = TfidfVectorizer(
        stop_words="english",
        max_features=5000,
        ngram_range=(1, 2),
        sublinear_tf=True,
    )
    tfidf_matrix = vectorizer.fit_transform([filings[t] for t in tickers])

    # Pairwise cosine distance in [0, 1], then condensed form for SciPy
    dist_matrix = cosine_distances(tfidf_matrix)
    np.fill_diagonal(dist_matrix, 0.0)
    condensed_dist = squareform(dist_matrix, checks=False)

    link = linkage(condensed_dist, method=method)
    ordered_tickers = [tickers[i] for i in leaves_list(link)]
    return link, ordered_tickers

def get_cluster_var(cov: pd.DataFrame, tickers: list[str]) -> float:
    """Inverse-variance portfolio variance for a cluster of assets."""
    sub_cov = cov.loc[tickers, tickers]
    ivp = 1.0 / np.diag(sub_cov)
    ivp /= ivp.sum()
    return float(ivp @ sub_cov.values @ ivp)

def recursive_bisection(cov: pd.DataFrame, ordered_tickers: list[str]) -> pd.Series:
    """Allocate weights top-down along the text-derived hierarchy."""
    weights = pd.Series(1.0, index=ordered_tickers)
    clusters = [ordered_tickers]

    while clusters:
        next_clusters = []
        for cluster in clusters:
            if len(cluster) <= 1:
                continue
            split = len(cluster) // 2
            left, right = cluster[:split], cluster[split:]
            var_left = get_cluster_var(cov, left)
            var_right = get_cluster_var(cov, right)
            alpha = 1.0 - var_left / (var_left + var_right)
            weights[left] *= alpha
            weights[right] *= (1.0 - alpha)
            next_clusters.extend([left, right])
        clusters = next_clusters

    return weights

In practice, once ordered_tickers is produced from 10-K cosine distances, recursive_bisection allocates risk down the tree using each cluster’s inverse-variance portfolio variance—keeping the mathematical simplicity of HRP while grounding the hierarchy in fundamental text similarity.


What the Empirical Tests Show

Because realistic corporate filings cannot be simulated the way synthetic Gaussian returns can, I evaluate TB-HRP on real market data by generating 10,000 random portfolios across two contrasting equity universes:

  1. Large, liquid equities (S&P 500): TB-HRP performs solidly and consistently both in-sample and out-of-sample, broadly matching or slightly improving on traditional return-based clustering where price histories are already deep.
  2. Thinly traded stocks and recent IPOs (CRSP): Restricting the universe to firms with less than 1 million in annual trading volume and/or less than one year of trading history is where TB-HRP separates itself. Because return-based correlations are noisy or incomplete for these firms, clustering on 10-K disclosures produces more stable weights and stronger out-of-sample risk-adjusted consistency—allowing portfolios to include illiquid or newly listed names that traditional covariance-based optimizers routinely distort or exclude.

Code, Paper, and Further Reading

  • Published Paper: Rayfield, B. (2026). “Text based hierarchical risk parity (TBHRP).” Financial Markets and Portfolio Management, 40(3), 375–392. DOI: 10.1007/s11408-025-00491-8
  • GitHub & Archived Release: Full replication code, Sample_Input/, and Examples/ are available at bkrayfield/TBHRP (MIT License) and archived on Zenodo (DOI: 10.5281/zenodo.24670063).
  • Applied Python for Finance & Business: If you want a broader hands-on guide to constrained optimization, probability, statistics, and NLP in Python, see my book Applied Math with Python (Wiley, 2026).