Topological Data Analysis (TDA)
Topological Data Analysis (TDA)
In Signal.Engine, Topological Data Analysis (TDA) serves as a high-dimensional "lens" that identifies market regime shifts which traditional indicators like RSI or MACD often miss. While the LSTM processes linear sequences, the TDA module analyzes the shape of the price action point cloud to detect structural instabilities (e.g., "market fragility") before they manifest as large price swings.
Persistence Homology & Market Regimes
The system utilizes Persistence Homology to analyze time-series data. It treats a window of prices (typically the last 50 candles) as a point cloud in high-dimensional space using Takens’ Embedding. By calculating the birth and death of "holes" (topological features) within this cloud, the system can quantify:
- Market Circularity: Highly cyclical, range-bound behavior.
- Structural Voids: Sudden "hollows" in price distribution often preceding high-volatility breakouts.
- Persistence Landscapes: Statistical summaries of these shapes that are fed into the RL Brain as auxiliary features.
TDA Feature Extraction
The TDA pipeline is integrated into the data preprocessing layer. It transforms raw price windows into topological signatures that indicate the "complexity" of the current trend.
Configuration Interface
TDA parameters are configured within the HybridBrain initialization or the environment settings.
| Parameter | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| embedding_dimension | int | 3 | Dimensions for Takens' delay embedding. |
| embedding_time_delay | int | 1 | Lag between coordinates in the embedding. |
| homology_dimensions | tuple | (0, 1) | The types of holes to track (0: clusters, 1: loops). |
| persistence_metric | str | "bottleneck" | Metric used to calculate distances between persistence diagrams. |
Usage Example: Extracting Topological Signatures
You can use the internal TDAEncoder to extract topological features for custom analysis or to debug the "Brain's" reasoning.
from src.brain.features.tda_encoder import TDAEncoder
import numpy as np
# Initialize the encoder
tda = TDAEncoder(window_size=50)
# Sample price sequence (50 candles)
price_data = np.random.rand(50)
# Generate Persistence Landscape features
# Returns a vector of topological summaries
topological_features = tda.transform(price_data)
print(f"Topological Feature Vector Shape: {topological_features.shape}")
# Example Output: (1, 100) - representing summarized topological persistence
Interpreting TDA in the Dashboard
In the Signal.Engine dashboard, TDA metrics are visualized through the "Market Mood" and "Rational" segments of a trade decision.
- High Persistence (H1): Indicates the market is forming a "loop" (consolidating). The agent may favor mean-reversion strategies.
- Topological Volatility: A sharp spike in the Bottleneck Distance between consecutive persistence diagrams. This usually triggers a
HIGH_VOLATILITYregime flag. - Betti Numbers: Displayed in the "Advanced Analytics" tab to show the number of connected components and holes detected in the current price action.
Integration with the Hybrid Brain
The TDA features are concatenated with the LSTM's latent space before being passed to the PPO (Reinforcement Learning) policy. This allows the agent to make decisions based on both:
- Temporal Patterns (LSTM: "What happened recently?")
- Topological Structure (TDA: "Is the current trend structurally sound or fragile?")
Note: TDA computation is CPU-intensive. By default, the system uses a vectorized
giotto-tdaimplementation to ensure live trading latency remains below 500ms per ticker scan.