stock-embeddings
Train vector embeddings of stocks from their price history. Give the library a dict of
{ticker: prices}, and it builds a stock-similarity graph from return correlations and
embeds every stock into a dense vector — stocks that move together (and belong to similar
businesses) end up close in embedding space.
from stock_embeddings import train_embeddings
data = {"AAPL": aapl_prices, "MSFT": msft_prices, "XOM": xom_prices, ...}
embeddings = train_embeddings(data) # -> {"AAPL": [64 floats], "MSFT": [...], ...}
Full documentation: docs.stockscore.live
Summary
stock-embeddings turns raw price panels into a {ticker: vector} dictionary using the
pipeline from our research on correlation-graph stock embeddings:
prices -> returns -> correlation matrix -> graph -> embedding -> {ticker: vector}
Every stage is configurable with sane defaults: co-movement removal (market-neutral residuals, cross-sectional demeaning, spectral/RMT cleaning), graph construction (threshold + Forced Connectivity repair, MST, kNN), and the embedding family itself (Node2Vec, Laplacian Eigenmaps, NetMF, or raw-feature baselines).
Why this is useful
- Semantic stock similarity. Embedding-space neighbours capture economic similarity (sector, industry, business model) that raw correlation misses, because the graph + random walks propagate relationships beyond direct pairwise correlation.
- Ready-made features. The vectors are a compact, dense feature representation for downstream ML: sector classification, clustering, peer selection, retrieval, or risk models.
- Turnkey. One function call, no data plumbing, no graph code, no tuning required — defaults come from a seed-averaged, significance-tested research benchmark.
- Honest and reproducible. All randomness is seeded; alternative embedding families and no-embedding baselines are built in, so you can verify the embedding actually adds value on your data.
Setup
Requires Python 3.10+.
pip install stock-embeddings
Or from source:
git clone https://github.com/tomaszrymaszewski/stock_embeddings.git
cd stock_embeddings
pip install .
Quick start
import pandas as pd
from stock_embeddings import train_embeddings
# Any dict of ticker -> prices works: pandas Series (optionally with a
# DatetimeIndex), lists, or numpy arrays.
prices = pd.read_csv("prices.csv", index_col=0, parse_dates=True)
data = {ticker: prices[ticker].dropna() for ticker in prices.columns}
embeddings = train_embeddings(data)
# Nearest neighbours of a stock:
from stock_embeddings import fit
result = fit(data)
result.most_similar("AAPL", k=10) # [("MSFT", 0.98), ("AMZN", 0.97), ...]
result.to_dataframe() # embeddings as a DataFrame
Usage
Every parameter has a default; pass only what you want to change:
embeddings = train_embeddings(
data,
dimensions=32, # embedding size (default 64)
embedder="spectral", # node2vec | spectral | netmf | raw_corr | raw_returns
graph_filtering="knn", # threshold | mst | knn | signed_knn
knn_k=10,
market_neutral=True, # regress out the market factor before building the graph
spectral_clean="market", # remove the market eigenmode from the correlation matrix
seed=42,
)
Use fit() instead of train_embeddings() to get the full TrainResult — embeddings,
the returns matrix actually used, the similarity graph, and the resolved config — plus
helpers like to_dataframe() and most_similar().
See the documentation for the complete parameter reference and guides.
Research
This library implements the method developed in our paper Stock Embeddings from Return-Correlation Graphs, which benchmarks how well correlation-graph embeddings recover the GICS classification of stocks against honest baselines (raw correlation, MST, kNN, PMFG), with seed-averaged, significance-tested results. Read the paper for how we got here — the method choices, the defaults shipped in this library, and what the embeddings can and cannot do.
License
MIT — see LICENSE.
Metadata
Release files for stock-embeddings 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| stock_embeddings-0.1.0.tar.gz | 17.9 kB | With provenance | Details for stock_embeddings-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stock_embeddings-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for stock_embeddings-0.1.0-py3-none-any.whl |
Total release size: 35.0 kB
Release files / stock_embeddings-0.1.0.tar.gz
| Download URL | stock_embeddings-0.1.0.tar.gz |
|---|---|
| Size | 17.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
de4bb4c14d72355b18b1a78f4ef31e8989b39b22db5c5af1101848f8e10faf72
|
|
BLAKE2b-256 checksum How to use checksums |
6835b2b7f1ca9b7055ef984730713e74c0572090f51f5efa4da367f2e50b0e14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.
Transparency logRelease files / stock_embeddings-0.1.0-py3-none-any.whl
| Download URL | stock_embeddings-0.1.0-py3-none-any.whl |
|---|---|
| Size | 17.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
270b70bc2b8c0b25a95779eba4292783e449525c04c52f6d22c44bc6bfe85ba2
|
|
BLAKE2b-256 checksum How to use checksums |
f6cf6587734d2bab095c344c5b2ff40d53fa8b16dac2f8c119efe7e339014d81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.
Transparency logSecurity for stock-embeddings 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for stock_embeddings-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.