📦 SQA::PatternMatcher¶
Description
PatternMatcher - Find similar historical patterns
Provides methods for: - Pattern similarity search (nearest-neighbor) - Shape-based pattern matching - Predict future moves based on similar past patterns - Pattern clustering
Uses techniques: - Euclidean distance - Dynamic Time Warping (DTW) - Pearson correlation
🔨 Instance Methods¶
#stock()¶
Returns the value of attribute stock.
Source Location
#prices()¶
Returns the value of attribute prices.
Source Location
#initialize(stock:)¶
Initialize pattern matcher
Parameters
| Name | Type | Description |
|---|---|---|
stock |
SQA::Stock |
Stock object |
Returns
Type: PatternMatcher
a new instance of PatternMatcher
Source Location
#find_similar(lookback: = 10, num_matches: = 5, method: = :euclidean, normalize: = true)¶
Find similar historical patterns to current pattern
Parameters
| Name | Type | Description |
|---|---|---|
lookback |
Integer |
Pattern length (days) |
num_matches |
Integer |
Number of similar patterns to find |
method |
Symbol |
Distance method (:euclidean, :dtw, :correlation) |
normalize |
Boolean |
Normalize patterns before comparison |
Returns
Type: Array<Hash>
Similar patterns with metadata
Source Location
#forecast(lookback: = 10, forecast_periods: = 5, num_matches: = 10)¶
Predict future price movement based on similar patterns
Parameters
| Name | Type | Description |
|---|---|---|
lookback |
Integer |
Pattern length |
forecast_periods |
Integer |
Periods to forecast |
num_matches |
Integer |
Number of similar patterns to use |
Returns
Type: Hash
Forecast with confidence intervals
Source Location
#detect_chart_pattern(pattern_type)¶
Detect chart patterns (head & shoulders, double top, etc.)
Parameters
| Name | Type | Description |
|---|---|---|
pattern_type |
Symbol |
Pattern to detect |
Returns
Type: Array<Hash>
Detected patterns
Source Location
#cluster_patterns(pattern_length: = 10, num_clusters: = 5)¶
Cluster patterns by similarity
Parameters
| Name | Type | Description |
|---|---|---|
pattern_length |
Integer |
Length of patterns |
num_clusters |
Integer |
Number of clusters |
Returns
Type: Array<Array<Hash>>
Clusters of similar patterns
Source Location
#pattern_quality(pattern)¶
Calculate pattern strength/quality
Parameters
| Name | Type | Description |
|---|---|---|
pattern |
Array<Float> |
Price pattern |
Returns
Type: Hash
Pattern quality metrics
Source Location
📝 Attributes¶
👁️ stock read-only¶
Returns the value of attribute stock.
👁️ prices read-only¶
Returns the value of attribute prices.