Class: SQA::StrategyGenerator::PatternContext

Inherits:
Object
  • Object
show all
Defined in:
lib/sqa/strategy_generator.rb

Overview

Pattern Context - metadata about when/where pattern is valid

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePatternContext



96
97
98
99
100
101
102
103
104
105
# File 'lib/sqa/strategy_generator.rb', line 96

def initialize
  @market_regime = nil        # :bull, :bear, :sideways
  @valid_months = []          # [10, 11, 12, 1] for Q4/Q1
  @valid_quarters = []        # [1, 4] for Q1/Q4
  @discovered_period = nil    # "2020-01-01 to 2022-12-31"
  @validation_period = nil    # "2023-01-01 to 2024-11-08"
  @stability_score = nil      # 0.0-1.0, how consistent over time
  @sector = nil               # :technology, :finance, etc.
  @volatility_regime = nil    # :low, :medium, :high
end

Instance Attribute Details

#discovered_periodObject

Returns the value of attribute discovered_period.



92
93
94
# File 'lib/sqa/strategy_generator.rb', line 92

def discovered_period
  @discovered_period
end

#market_regimeObject

Returns the value of attribute market_regime.



92
93
94
# File 'lib/sqa/strategy_generator.rb', line 92

def market_regime
  @market_regime
end

#sectorObject

Returns the value of attribute sector.



92
93
94
# File 'lib/sqa/strategy_generator.rb', line 92

def sector
  @sector
end

#stability_scoreObject

Returns the value of attribute stability_score.



92
93
94
# File 'lib/sqa/strategy_generator.rb', line 92

def stability_score
  @stability_score
end

#valid_monthsObject

Returns the value of attribute valid_months.



92
93
94
# File 'lib/sqa/strategy_generator.rb', line 92

def valid_months
  @valid_months
end

#valid_quartersObject

Returns the value of attribute valid_quarters.



92
93
94
# File 'lib/sqa/strategy_generator.rb', line 92

def valid_quarters
  @valid_quarters
end

#validation_periodObject

Returns the value of attribute validation_period.



92
93
94
# File 'lib/sqa/strategy_generator.rb', line 92

def validation_period
  @validation_period
end

#volatility_regimeObject

Returns the value of attribute volatility_regime.



92
93
94
# File 'lib/sqa/strategy_generator.rb', line 92

def volatility_regime
  @volatility_regime
end

Instance Method Details

#summaryObject



111
112
113
114
115
116
117
118
# File 'lib/sqa/strategy_generator.rb', line 111

def summary
  parts = []
  parts << @market_regime.to_s if @market_regime
  parts << "months:#{@valid_months.join(',')}" if @valid_months.any?
  parts << "Q#{@valid_quarters.join(',')}" if @valid_quarters.any?
  parts << @sector.to_s if @sector
  parts.join(' ')
end

#valid?Boolean



107
108
109
# File 'lib/sqa/strategy_generator.rb', line 107

def valid?
  @market_regime || @valid_months.any? || @sector
end

#valid_for?(date: nil, regime: nil, sector: nil) ⇒ Boolean

Check if pattern is valid for given date and conditions



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/sqa/strategy_generator.rb', line 121

def valid_for?(date: nil, regime: nil, sector: nil)
  # Check market regime
  return false if @market_regime && regime && @market_regime != regime

  # Check sector
  return false if @sector && sector && @sector != sector

  # Check calendar constraints
  if date
    return false if @valid_months.any? && !@valid_months.include?(date.month)

    quarter = ((date.month - 1) / 3) + 1
    return false if @valid_quarters.any? && !@valid_quarters.include?(quarter)
  end

  true
end