Class: Quant::Indicators::Snr

Inherits:
Indicator show all
Defined in:
lib/quant/indicators/snr.rb

Constant Summary

Constants inherited from Indicator

Indicator::PRIORITIES

Constants included from Mixins::UniversalFilters

Mixins::UniversalFilters::K

Instance Attribute Summary

Attributes inherited from Indicator

#p0, #p1, #p2, #p3, #series, #source, #t0, #t1, #t2, #t3

Instance Method Summary collapse

Methods inherited from Indicator

#<<, #[], #adaptive_half_period, #adaptive_period, dependent_indicator_classes, depends_on, #dominant_cycle, #dominant_cycle_indicator_class, #dominant_cycle_kind, #each, #half_period, #indicator_name, #initialize, #input, #inspect, #max_period, #micro_period, #min_period, #p, #period_points, #pivot_kind, #points_class, #priority, register, #size, #t, #ticks, #values, #warmed_up?

Methods included from Mixins::FisherTransform

#fisher_transform, #inverse_fisher_transform, #relative_fisher_transform

Methods included from Mixins::Stochastic

#stochastic

Methods included from Mixins::SuperSmoother

#three_pole_super_smooth, #two_pole_super_smooth

Methods included from Mixins::HilbertTransform

#hilbert_transform

Methods included from Mixins::ExponentialMovingAverage

#exponential_moving_average

Methods included from Mixins::SimpleMovingAverage

#simple_moving_average

Methods included from Mixins::WeightedMovingAverage

#extended_weighted_moving_average, #weighted_moving_average

Methods included from Mixins::UniversalFilters

#universal_band_pass, #universal_ema, #universal_filter, #universal_one_pole_high_pass, #universal_one_pole_low_pass, #universal_two_pole_high_pass, #universal_two_pole_low_pass

Methods included from Mixins::ButterworthFilters

#three_pole_butterworth, #two_pole_butterworth

Methods included from Mixins::HighPassFilters

#high_pass_filter, #hpf2, #two_pole_high_pass_filter

Methods included from Mixins::Functions

#angle, #bars_to_alpha, #deg2rad, #period_to_alpha, #rad2deg

Constructor Details

This class inherits a constructor from Quant::Indicators::Indicator

Instance Method Details

#computeObject



57
58
59
60
61
# File 'lib/quant/indicators/snr.rb', line 57

def compute
  compute_values
  compute_noise
  compute_ratio
end

#compute_noiseObject



39
40
41
42
# File 'lib/quant/indicators/snr.rb', line 39

def compute_noise
  noise = (p0.input - p2.input).abs
  p0.noise = p1.noise.zero? ? noise : (0.1 * noise) + (0.9 * p1.noise)
end

#compute_ratioObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/quant/indicators/snr.rb', line 44

def compute_ratio
  # p0.ratio = 0.25 * (10 * Math.log(p0.i1**2 + p0.q1**2) / Math.log(10)) + 0.75 * p1.ratio
  # ratio = .25*(10 * Log(I1*I1 + Q1*Q1)/(Range*Range))/Log(10) + 6) + .75*ratio[1]
  if p0 == p1
    p0.signal = 0.0
    p0.ratio = 1.0
  else
    p0.signal = threshold + 10.0 * (Math.log((p0.i1**2 + p0.q1**2)/(p0.noise**2)) / Math.log(10))
    p0.ratio = (0.25 * p0.signal) + (0.75 * p1.ratio)
  end
  p0.state = p0.ratio >= threshold ? 1 : 0
end

#compute_valuesObject



32
33
34
35
36
37
# File 'lib/quant/indicators/snr.rb', line 32

def compute_values
  current_dominant_cycle.tap do |dc|
    p0.i1 = dc.i1
    p0.q1 = dc.q1
  end
end

#current_dominant_cycleObject



24
25
26
# File 'lib/quant/indicators/snr.rb', line 24

def current_dominant_cycle
  homodyne_dominant_cycle.points[t0]
end

#homodyne_dominant_cycleObject



20
21
22
# File 'lib/quant/indicators/snr.rb', line 20

def homodyne_dominant_cycle
  series.indicators[source].dominant_cycles.homodyne
end

#thresholdObject



28
29
30
# File 'lib/quant/indicators/snr.rb', line 28

def threshold
  @threshold ||= 10 * Math.log(0.5)**2
end