Class: DhanHQ::Analysis::BiasAggregator
- Inherits:
-
Object
- Object
- DhanHQ::Analysis::BiasAggregator
- Defined in:
- lib/dhanhq/analysis/helpers/bias_aggregator.rb
Overview
Aggregates indicator scores across timeframes into a single bias and confidence score
Constant Summary collapse
- DEFAULT_WEIGHTS =
{ m1: 0.1, m5: 0.2, m15: 0.25, m25: 0.15, m60: 0.3 }.freeze
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(indicators, config = {}) ⇒ BiasAggregator
constructor
A new instance of BiasAggregator.
Constructor Details
#initialize(indicators, config = {}) ⇒ BiasAggregator
Returns a new instance of BiasAggregator.
9 10 11 12 13 14 |
# File 'lib/dhanhq/analysis/helpers/bias_aggregator.rb', line 9 def initialize(indicators, config = {}) @indicators = indicators || {} @weights = config[:timeframe_weights] || DEFAULT_WEIGHTS @min_adx = (config[:min_adx_for_trend] || 22).to_f @strong_adx = (config[:strong_adx] || 35).to_f end |
Instance Method Details
#call ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dhanhq/analysis/helpers/bias_aggregator.rb', line 16 def call score = 0.0 wsum = 0.0 refs = [] notes = [] @weights.each do |tf, w| next unless @indicators[tf] s = score_tf(@indicators[tf]) next if s.nil? score += s * w wsum += w refs << tf end avg = wsum.zero? ? 0.5 : (score / wsum) bias = if avg > 0.55 :bullish elsif avg < 0.45 :bearish else :neutral end { bias: bias, confidence: avg.round(2), refs: refs, notes: notes } end |