A quantitative trading–oriented time series analysis framework designed to systematically extract, identify, expand, and statistically validate recurring market and trade setup patterns from financial price series, returns, indicators, and derived trading signals. This system is designed to work on price, returns, indicators, or derived trade signals and enables: .
- Automated feature engineering for trading windows
- Discovery of repeating market patterns (setups)
- Expansion of patterns using similarity & DTW
- Statistical validation and visual inspection of trade structures
Built for quants, algo traders, researchers, and market microstructure analysis.
In trading context, this framework helps us answer:
- Do certain price movements repeat before profitable trades❓
- How often does a specific setup reappear❓
- Are these patterns time-scaled versions of the same market behavior❓
- How stable is a trade pattern statistically❓
It treats trade setups as patterns and discovers them directly from historical price series.
A structured set of analytical tools designed to transform raw market data into discoverable, interpretable, and reusable trade patterns.
Transforms raw market data into structured trade contexts using a sliding window approach.
- The price series is split into overlapping windows of fixed length
- Each window represents a potential trade setup at that point in time
- Features are computed only from past data within the window (no leakage)
- OHLC / price series
- Returns and log-returns
- Volatility segments
- Indicator-based signals (RSI, MACD, etc.)
- Converts time series into tabular ML-ready data
- Enables supervised / unsupervised learning on trade setups
- Aligns naturally with how traders reason about entries
Output: one row per trade window with engineered features
Automatically extracts hundreds of statistically meaningful features from each trade window.
- Momentum & trend statistics
- Volatility structure
- Autocorrelation & lag behavior
- Entropy & complexity (market regime indicators)
- Feature generation scales with window size
- Prevents unnecessary feature explosion
- Automatically disables invalid statistics for short windows
- minimal → fast prototyping and quick experiments
- efficient → default for trading ML models
- comprehensive → research-grade pattern analysis
Output: Eliminates manual indicator engineering
Output: Captures market structure beyond classic indicators
Discovers repeating price action patterns directly from historical data using
STUMPY (Matrix Profile).
- Bullish and bearish trade setups
- Consolidation and breakout structures
- Mean-reversion and pullback patterns
- Searches for similar subsequences across the entire price history
- Groups recurring structures into Trade Pattern objects
- Each pattern contains multiple historical occurrences (instances)
Output: Patterns are discovered data-driven, not rule-based.
Output: No predefined candle patterns required
Once a core trade pattern is found, the framework can expand it to uncover more opportunities.
Finds same-length trade setups using Euclidean similarity.
Use cases
- Fixed-horizon strategies
- Candle-pattern style systems
- High-confidence, tightly controlled setups
Output: Preserves timing and structure.
Output: Expands pattern frequency conservatively
Finds time-warped versions of the same trade using Dynamic Time Warping (DTW).
- Fast vs slow breakouts
- Accelerated vs delayed reversals
- Compressed or stretched market moves
- Real markets rarely move at fixed speeds
- DTW captures the shape of a trade, not its exact timing
Output: Enables scale-invariant pattern discovery.
Output: Crucial for live-market robustness.
Provides both static and interactive tools to visually validate discovered trade patterns.
- Entry-to-exit price shapes
- Pattern overlap and clustering
- Frequency, stability, and consistency
- Zoom and pan across the full price series
- Hover to inspect individual pattern instances
- Priority handling for overlapping patterns
- Toggle pattern types (base / similarity / DTW)
Output: Bridges quantitative analysis with trader intuition
Output: Makes pattern quality easy to validate visually
This framework is designed to run locally on your machine for research, experimentation, and strategy development.
python -m venv trade-pattern-env
source trade-pattern-env/bin/activate # macOS / Linux
trade-pattern-env\Scripts\activate # WindowsNote : Using a virtual environment avoids dependency conflicts and keeps experiments isolated.
pip install numpy==2.0.2
pip install pandas==2.2.2
pip install matplotlib==3.10.0
pip install bokeh==3.7.3
pip install pathos==0.3.4
pip install stumpy==1.13.0
pip install tsfresh==0.21.1The codebase mirrors the natural workflow of quantitative trade research:
Time-Series-Pattern-Mining-Using-TSFresh
│
├── trade_features/ # Feature engineering layer
│ ├── sliding_windows
│ ├── TsFreshConfigurator
│ ├── extract_windowed_features
│
├── trade_patterns/ # Pattern discovery layer
│ ├── find_patterns
│ ├── Pattern
│ ├── Instance
│
├── pattern_expansion/ # Pattern generalization layer
│ ├── extend_instances # same-horizon trade setups
│ ├── extend_dtw_instances # time-warped trade setups
│
├── visualization/ # Analysis & validation tools
│ ├── price_overlay
│ ├── pattern_shapes
│ ├── interactive_market_view
│
└── examples/ # Example scripts & experiments- Why this structure❓
- Modify feature engineering independently
- Swap pattern discovery logic
- Experiment with different expansion strategies
- Validate results visually before strategy deployment
Convert raw price data into feature-rich trade windows.
features = extract_windowed_features(
time_series=price_series,
window_size=20,
preset="efficient",
lags="minimal"
)Interpretation
- Each row → one trade context window
- First column → reference price (potential trade entry)
- Remaining columns → engineered market features
Output is immediately usable for ML models or pattern mining.
Identify repeating trade setups in historical data.
patterns = find_patterns(
time_series=features["ts"],
lengths=[7, 10, 20],
min_repeats=5
)Each Pattern represents:
- A recurring trade structure
- Multiple historical occurrences
- Quantified similarity between instances
This step reveals what the market tends to repeat.
Similarity-Based Expansion
- Find additional same-length trade setups.
pattern.extend_instances(tolerance=-0.3)Discover time-warped versions of the same trade.
pattern.extend_dtw_instances(
tolerance=-0.3,
length_range=(0.3, 5.0),
distance_metric="pattern"
)Inspect quantitative stability and consistency.
pattern.statisticsIncludes:
- Number of occurrences
- Distance stability (robustness)
- DTW alignment metrics
- Time-scale variability
These metrics help decide whether a pattern is tradable or noise.

pattern.show()
pattern_copy.show()
pattern_copy.show()
Visually inspect discovered trade setups before using them in a strategy.
pattern.show() # interactive market view
pattern.show_shape() # canonical trade shape
pattern.show_instances() # overlay of all trade setupsTypical Use Cases
- Manual strategy validation
- Pattern sanity checks
- Combining trader intuition with quantitative rigor
This framework is designed for real-world quantitative trading and market research.
Common use cases include:
- Alpha discovery — uncover repeatable market behaviors
- Strategy validation — test if setups are structurally consistent
- Pattern-based entries — identify recurring trade setups
- Market regime detection — distinguish trending vs ranging behavior
- Signal confirmation — validate indicators with structural patterns
- Trade clustering — group similar market movements
- Feature generation for ML models — convert price action into ML-ready features
-
Larger windows → exponential feature growth
Use longer windows only when justified by research goals. -
DTW is computationally expensive
Apply Dynamic Time Warping selectively on high-quality candidate patterns.
- Start with small windows and the efficient preset
- Identify strong, stable patterns
- Expand patterns conservatively
- Validate results visually and statistically
Markets repeat — but never exactly.
This framework focuses on structure and behavior, not exact price levels.
By avoiding naive technical indicators and exact matching, it enables robust trade pattern discovery that generalizes across time and market conditions.

