Methods and Validation
How Homology describes market structure, finds similar periods and tests the comparison.
1. Question and Scope
How do relationships between assets change? When did a similar structure appear in the past? Does topology add information beyond correlations that retain asset names? Homology explores these questions using the same dataset for current structure and historical comparisons.
The workspace uses completed trading sessions. Validation steps through historical test dates and estimates the returns that followed, using earlier data for each comparison. The asset basket is fixed using today’s selection, so survivorship bias remains. These tests do not establish a tradable strategy.
2. Data and Window Convention
Choose 3–12 distinct assets, align their trading dates and use the same adjustment convention for open, high, low, close and volume (OHLCV). A selected window contains L completed prices and L−1 log returns, where 10 ≤ L ≤ 120. The rolling views use 20, 60 and 120 prices, corresponding to 19, 59 and 119 returns. Window lengths throughout the workspace count prices.
Completed daily bars load through the server-side Marketstack endpoint; the API key stays on the server. Imported CSV files are checked in your browser. Synthetic data is used only when you choose the demo and is clearly labelled. If an asset is missing a date, the affected window is unavailable. The calculation keeps the full basket rather than silently dropping assets or using different dates for different pairs.
Rolling calculations stop at the selected close. Historical replay uses the dataset loaded today, which may include later corrections by the provider. Checking that a session has ended does not prove that the same data was available at that historical date. Splits in unadjusted prices can affect every feature.
r_{t,i}=\log P_{t,i}-\log P_{t-1,i},\quad m=L-1
(2.1) Log returns
3. From Correlations to Distances
For each asset, limit extreme returns to four robust scales above or below the median, with a minimum scale of 10⁻⁶. Center and normalize this clipped series. A second channel ranks the original returns, gives tied values their average rank, then centers and normalizes the ranks. Topology cannot be calculated when a series is constant or numerically degenerate.
Both correlation matrices are Gram matrices of complete, normalized return vectors. Chord distance measures the Euclidean distance between their unit vectors and satisfies the triangle inequality. Two different assets can have identical vectors and zero distance, making this a pseudometric on labelled assets. The topology calculation uses these correlations without shrinkage toward the identity matrix.
c_i=\operatorname{med}(r_{\cdot,i}),\quad s_i=\max\{10^{-6},1.482602218505602\operatorname{med}|r_{\cdot,i}-c_i|\}
(3.1) Robust center and scale
\widetilde r_{t,i}=c_i+\operatorname{clip}(r_{t,i}-c_i,-4s_i,4s_i)
(3.2) Winsorization
z_i=\frac{\widetilde r_{\cdot,i}-\operatorname{mean}\widetilde r_{\cdot,i}}{\|\widetilde r_{\cdot,i}-\operatorname{mean}\widetilde r_{\cdot,i}\|_2},\quad \rho_{ij}=z_i^Tz_j
(3.3) Normalized vectors
d_{ij}=\sqrt{2(1-\rho_{ij})}=\|z_i-z_j\|_2\in[0,2]
(3.4) Chord distance
4. Vietoris–Rips Persistence
At threshold ε, include a simplex when every distance between its vertices is at most ε. The calculation builds vertices, edges and triangles; triangles fill loops. These are enough to compute H₀ and H₁. Boundary matrices are reduced over F₂. Simplices are ordered first by filtration value, then dimension, then vertex order.
Store finite classes only when their lifetime is positive. Exclude the single H₀ class that persists indefinitely from diagram matching. With three vertices, the Rips triangle fills as soon as the last edge appears, so there is no positive-lifetime H₁ class. Network nodes use a circular layout with asset labels; their positions do not represent distances.
\mathrm{VR}_\varepsilon(\mathcal U,d)=\{\sigma\subseteq\mathcal U:\max_{i,j\in\sigma}d_{ij}\le\varepsilon\}
(4.1) Filtration
D_k=\{(b_\ell,d_\ell):d_\ell>b_\ell,\ d_\ell<\infty\},\quad k\in\{0,1\}
(4.2) Finite diagrams
5. Comparing Persistence Diagrams
Compare diagrams using the order-two Wasserstein distance with the L∞ norm for point-to-point costs. Unmatched points are assigned to the diagonal at squared cost ((d−b)/2)². The exact assignment includes explicit copies of the diagonal. The older standalone Homology v0.10 used Euclidean point-to-point costs.
Divide each channel and dimension distance by √p. Linear and rank channels have fixed weights of 0.7 and 0.3; H₀ and H₁ have equal weights. These weights are chosen settings, not estimated probabilities. Diagram matching loses asset identity even though every comparison uses the same named assets.
W_{2,\infty}(D,E)^2=\min_\gamma\sum_{x\in D\cup\Delta}\|x-\gamma(x)\|_\infty^2
(5.1) Diagonal-aware matching
\delta^2=\sum_{c\in\{\mathrm{linear},\mathrm{rank}\}}\alpha_c\frac{W_{2,\infty}(D_{c,0},E_{c,0})^2+W_{2,\infty}(D_{c,1},E_{c,1})^2}{2p}
(5.2) Combined retrieval distance
6. Summaries and Changes Over Time
Energy, entropy, longest lifetime, barcodes and the first persistence landscape layer summarize each window. Lifetime measures how long a feature persists as the filtration threshold changes; it does not count calendar days. W₂ change compares consecutive diagrams at the same scale and channel. The first change and any change across a missing window are left blank. Acceleration is the difference between successive changes.
The rolling timeline ends at the selected close. Empty H₁ diagrams can have zero change while H₀ or named asset relationships change. Views at different scales reuse observations, so they cannot be treated as independent evidence.
\ell_j=d_j-b_j,\quad E=\sum_j\ell_j^2,\quad q_j=\frac{\ell_j}{\sum_a\ell_a},\quad S=-\sum_jq_j\log q_j
(6.1) Energy and entropy; S=0 for empty diagrams
\lambda_1(\varepsilon)=\max\bigl(0,\max_j\min(\varepsilon-b_j,d_j-\varepsilon)\bigr)
(6.2) First landscape layer
v_t=W_{2,\infty}(D_t,D_{t-1}),\qquad a_t=v_t-v_{t-1}
(6.3) Discrete structural change
7. Past-Only Historical Analogues
Historical candidates use the same window length and asset basket as the selection. Sample them every five trading sessions of the selected stock. For horizons of 5, 20 and 60 sessions, the candidate’s entire later-return period must finish before the selection begins. Build a separate eligible group for each horizon. Sort candidates by structural distance, then choose references greedily, keeping at least L+h sessions between them.
Later returns describe the selected stock; the geometry describes the whole asset basket. Read the distribution of outcomes, including both gains and losses. Structural distance measures difference. It is not a probability or a percentage similarity score.
e+h<s_q,\qquad R_{e,h}=100\left(\frac{P_{e+h}}{P_e}-1\right)
(7.1) Historical availability and outcome
8. Match Stability and Scoring Rules
Eight joint circular-block resamples, using a fixed random seed, perturb the query returns while keeping assets aligned. The block length is max(2,round(√(L−1))). Each horizon uses a fixed shortlist of up to 30 candidates. The original first three references are retained if the spacing rule places them outside that shortlist.
Measure how often the closest reference and reference set remain after resampling. These retention rates describe local sensitivity rather than confidence intervals. Short windows, too few references, tied distances, extensive clipping, too few valid resamples or retention below 0.5 weaken the evidence. Validation scores only test dates that pass the checks and are marked observed.
9. Validation and Ablation
At each historical test date, use a 30-price window to estimate the return over the next 20 sessions. Move to the next test date every 20 sessions. Retrieve up to six separated references and average their later returns. The past-only baseline averages separated historical 20-session returns whose outcomes were complete before the query began.
Run full H₀+H₁, H₀-only, H₁-only and labelled correlation-distance retrieval with identical availability, spacing and stability rules. For labelled correlation, compare the upper triangles of the chord-distance matrices using weighted RMS distance. H₀/H₁ ablations use the corresponding channel-weighted diagram distance. Report coverage for each method. Compare each pair on their shared scored dates; report the four-method intersection separately.
Report attempted, scored and withheld test dates, MAE and paired mean error differences. Fewer than ten scored dates provide too little evidence for a reliable forecasting conclusion. Ten is the display threshold, not a statistical guarantee. Comparisons on common dates apply only where every method passed its checks. Independent holdout data, other asset baskets and transaction costs still need further study.
\mathrm{MAE}_M=\frac1{|\mathcal T|}\sum_{t\in\mathcal T}|\widehat R_{M,t}-R_t|,\quad \Delta_M=\mathrm{MAE}_M-\mathrm{MAE}_{\mathrm{corr}}
(9.1) Common-origin error comparison
The primary comparison pairs full topology and labelled correlation on their shared scored dates. The four-method intersection is a separate ablation analysis. A zero-return baseline and past-only mean are evaluated on the same paired dates. Paired circular-block percentile bootstrap uses seed 1101, 2,000 resamples and block lengths 1, 2 and 3 scored origins. Intervals are withheld below 20 paired origins. Scored-origin blocks can span gaps in calendar time. These exploratory intervals condition on fixed settings and gating; they do not correct selection, repeated testing or regime changes.
10. Supporting Observations
The asset-relationship view keeps asset names and shrinks correlations toward the identity matrix for descriptive estimates. Basket risk assumes equal weights and reports each asset’s contribution to variance. Multiscale state, price paths, return distributions, candles and price-volume order help interpret the same data. The workspace does not combine them into a voting score.
11. Reproducibility and Review
Export research JSON to review or reproduce a calculation. It includes the loaded OHLCV data, SHA-256 fingerprint, selection, data source, adjustment convention, diagrams, reference groups, validation settings and paired records. The PDF records the research views. Changing the selection cancels earlier worker calculations. Numerical tests check exact complexes, diagram assignment, asset permutations, empty diagrams, future-data isolation and agreement on shared windows.
12. Reading Experiment Results
Results are calculated in your browser using the loaded data and selected dates. To share a specific experiment, run validation in the workspace and export research JSON. The export includes the data, paired errors, coverage and uncertainty intervals needed to review that run.
13. Network Curvature
Network curvature examines the two asset neighborhoods at each end of a link. It shares Homology’s window-local, winsorized linear and rank correlations without identity shrinkage. The graph uses distance sqrt(2(1 − ρ)), where ρ is 0.7 linear plus 0.3 rank correlation. Each asset selects its k nearest neighbors, and the undirected graph includes a link selected by either endpoint. All ties at the cutoff are included; a node can have more than k neighbors. The default is k = 2, with k = 1 and 3 shown as sensitivity checks.
Each neighborhood keeps half its probability mass at the center and shares half equally among its neighbors. Ollivier–Ricci curvature is κ(x,y) = 1 − W₁(mₓ,mᵧ) / dG(x,y). The transport ground cost is unweighted shortest-path distance in the sparse graph, so the denominator equals one on a displayed link. This differs from the correlation distance used by the Rips filtration. The solver uses residual minimum-cost flow, checks both marginals, and exports one optimal transport plan. An animated route is a visual explanation of that plan; the optimum need not be unique.
Negative curvature means neighborhood transport costs more than the distance between the centers. It does not by itself prove that the edge is a graph bridge or that market risk is high. The bridge label is computed separately by removing the edge and checking connectivity. Twelve fixed-seed joint circular-block resamples report edge presence and, conditional on presence, sign agreement and the 10th–90th curvature percentiles. These are sensitivity summaries, not confidence intervals. Missing edges stay missing. Adjacent-window comparison uses the immediately preceding complete window of the same length at k = 2.
The two-edge example requires a signed correlation gap no greater than 0.10 and a curvature gap of at least 0.10, selecting the largest qualifying curvature gap. These fixed rules choose an explanatory example. No example is shown when no pair qualifies. Curvature is an exploratory diagnostic and has not been added to the frozen return-retrieval experiment. Its predictive value remains untested. See Ollivier (2009) in References.
Independent numerical checks
Independent numerical checks passed.
Download verification resultsReferences
- Edelsbrunner, H., & Harer, J. (2010). Computational Topology: An Introduction. American Mathematical Society.
- Edelsbrunner, H., Letscher, D., & Zomorodian, A. (2002). Topological Persistence and Simplification. Discrete & Computational Geometry, 28, 511–533.
- Zomorodian, A., & Carlsson, G. (2005). Computing Persistent Homology. Discrete & Computational Geometry, 33(2), 249–274.
- Cohen-Steiner, D., Edelsbrunner, H., & Harer, J. (2007). Stability of Persistence Diagrams. Discrete & Computational Geometry, 37(1), 103–120.
- Ollivier, Y. (2009). Ricci Curvature of Markov Chains on Metric Spaces. Journal of Functional Analysis, 256(3), 810–864.
- Villani, C. (2009). Optimal Transport: Old and New. Grundlehren der mathematischen Wissenschaften, 338. Springer.
- Spearman, C. (1904). The Proof and Measurement of Association Between Two Things. The American Journal of Psychology, 15(1), 72–101.
- Ledoit, O., & Wolf, M. (2004). A Well-Conditioned Estimator for Large-Dimensional Covariance Matrices. Journal of Multivariate Analysis, 88(2), 365–411.
- Künsch, H. R. (1989). The Jackknife and the Bootstrap for General Stationary Observations. The Annals of Statistics, 17(3), 1217–1241.