Contrastive Learning of Asset Embeddings from Financial Time Series

Rian Dolphin, Barry Smyth, Ruihai DongarXiv 2024

TL;DR

This paper introduces a novel contrastive learning framework designed to generate high-quality "asset embeddings" from noisy financial time series data. By using a statistical sampling strategy based on hypothesis testing, the authors successfully capture complex, non-linear relationships between stocks, significantly outperforming traditional baselines in industry classification and risk-hedging tasks.

What Problem Does This Paper Address?

In the world of finance, understanding how different assets (like stocks) relate to one another is fundamental for portfolio management, risk assessment, and sector classification. However, financial markets are notoriously "noisy" and stochastic. Traditional methods often rely on simple linear measures like Pearson correlation or hand-crafted features, which frequently fail to capture the intricate, time-varying, and non-linear dependencies present in market data.

While "representation learning" (creating dense vector embeddings) has revolutionized fields like computer vision and NLP, applying it to financial time series is tricky. The challenge lies in defining what makes two assets "similar" enough to be a "positive pair" in a self-supervised learning setup without falling into the trap of spurious, noise-driven correlations.

Methods

The authors propose a framework that learns asset embeddings by looking at how often assets behave similarly across many small "subwindows" of time.

  1. Co-occurrence Matrix: For every sliding window of returns, they identify the top-$k$ most similar assets for each "anchor" asset. They count these occurrences across all windows to build a co-occurrence matrix.
  2. Statistical Sampling Strategy: This is the paper's core innovation. Instead of just picking the most frequent co-occurrences as positive samples, they use a hypothesis test of proportions. They calculate a $p$-value for every pair of assets to determine if their co-occurrence is significantly higher (positive sample) or lower (negative sample) than what would be expected by random chance.

    Figure 2: Example sampling regions based on the computed test statistic. The negative sampling region is much larger than the positive sampling region to promote diverse nega- tives and prevent degenerate solutions.
  3. Contrastive Loss Functions: They experimented with three different loss functions to pull similar assets together and push dissimilar ones apart: Individual Sigmoid, Aggregate Sigmoid, and a Hybrid Sigmoid-Softmax.

  4. Regularization: To ensure the embeddings are well-behaved, they apply a custom regularization term that encourages the vectors to distribute uniformly on a unit hypersphere.

Datasets

The study uses a real-world financial dataset consisting of daily returns for 611 U.S. stocks spanning nearly two decades (2000 to 2018).

  • Evaluation Labels: The assets are categorized into 11 sectors based on the Global Industry Classification Standard (GICS).
  • Availability: The authors have made this dataset publicly available on GitHub.

Key Insights and Ideas

  • Hypothesis Testing as a Denoising Filter: By using $p$-values to select training pairs, the model ignores "accidental" similarities that occur due to market noise, focusing instead on statistically significant relationships.
  • Asymmetric Sampling for Diversity: As shown in Figure 2, the negative sampling region is much larger than the positive one. This design choice is crucial; it prevents "degenerate solutions" (where the model learns to map everything to the same point) by forcing the model to distinguish the anchor from a wide variety of dissimilar assets.
  • Capturing "Hidden" Relationships: One of the most interesting findings is that the embeddings capture nuanced similarities that rigid industry labels miss. For example, the model identified that Procter & Gamble (officially in "Basic Industries") is highly similar to companies in "Consumer Non-Durables" like PepsiCo and Colgate-Palmolive. This suggests the embeddings reflect actual market behavior rather than just administrative categories.

Key Results

The proposed method consistently outperformed traditional time-series classification methods and previous state-of-the-art asset embedding techniques.

  • Industry Sector Classification: Using the Sigmoid-Softmax loss, the model achieved an F1-score of 0.69 and 69% accuracy, a significant jump from the 60-66% range of previous specialized baselines.

    Table 1: Comparison of sector classification performance.
  • Portfolio Hedging: In a task designed to minimize risk by picking a "hedge" asset, the Individual Sigmoid embeddings led to an average out-of-sample volatility of 19.1%. For comparison, the standard Pearson correlation baseline resulted in 23.8% volatility.

    Figure 4: Distribution of realized volatility for portfolios constructed using our individual sigmoid loss approach and the Pearson correlation baseline.
  • Visual Validation: t-SNE visualizations (Figure 3) show that stocks from the same sectors naturally cluster together in the embedding space, confirming that the model is learning meaningful semantic structures from raw price data.

Limitations and Future Work

The authors acknowledge a primary limitation: scalability. Calculating pairwise similarities across many sliding windows can become computationally expensive as the number of assets or the length of the time series grows.

To address this, they suggest future work could leverage GPU-accelerated similarity search algorithms (like those used for time-series motifs) which can handle quadrillions of comparisons. Additionally, they believe this framework is highly adaptable and could be applied to non-financial time series domains where noise and non-linear relationships are also prevalent.

Summary updated

BibTeX
@misc{dolphin2024contrastive,
  author = {Rian Dolphin and Barry Smyth and Ruihai Dong},
  title = {{Contrastive Learning of Asset Embeddings from Financial Time Series}},
  year = {2024},
  eprint = {2407.18645},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.18645},
}
Figure