Class: Quant::Indicators::DominantCycles::BandPass

Inherits:
DominantCycle show all
Defined in:
lib/quant/indicators/dominant_cycles/band_pass.rb

Constant Summary

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 DominantCycle

#compute_input_data_points, #compute_mean_period, #compute_phase, #compute_quadrature_components, #compute_smooth_period, #constrain_period_bars, #constrain_period_magnitude_change, #dominant_cycle_period, #period_points, #points_class

Methods inherited from Indicator

#<<, #[], #dominant_cycle_kind, #each, #half_period, #indicator_name, #initialize, #input, #inspect, #max_period, #micro_period, #min_period, #p, #pivot_kind, #points_class, #size, #t, #ticks, #values

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

#bandwidthObject



18
19
20
# File 'lib/quant/indicators/dominant_cycles/band_pass.rb', line 18

def bandwidth
  0.75
end

#computeObject



72
73
74
75
76
# File 'lib/quant/indicators/dominant_cycles/band_pass.rb', line 72

def compute
  compute_high_pass
  compute_band_pass
  compute_period
end

#compute_band_passObject



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/quant/indicators/dominant_cycles/band_pass.rb', line 46

def compute_band_pass
  radians = deg2rad(360.0 / max_period)
  beta = Math.cos(radians)
  gamma = 1.0 / Math.cos(bandwidth * radians)
  alpha = gamma - Math.sqrt(gamma**2 - 1.0)

  a = 0.5 * (1 - alpha) * (p0.hp - p2.hp)
  b = beta * (1 + alpha) * p1.bp
  c = alpha * p2.bp
  p0.bp = a + b - c
end

#compute_high_passObject

Peak = .991*Peak; If AbsValue(BP) > If Peak <> 0 Then DC = DC; If DC < 6 Then DC counter = counter If Real Crosses Over 0 or Real Crosses Under 0 Then Begin

DC = 2*counter;
If 2*counter > 1.25*DC[1] Then DC = 1.25*DC[1];
If 2*counter < .8*DC[1] Then DC = .8*DC[1];
counter = 0;

End;



41
42
43
44
# File 'lib/quant/indicators/dominant_cycles/band_pass.rb', line 41

def compute_high_pass
  alpha = period_to_alpha(max_period, k: 0.25 * bandwidth)
  p0.hp = (1 + alpha / 2) * (p0.input - p1.input) + (1 - alpha) * p1.hp
end

#compute_periodObject



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/quant/indicators/dominant_cycles/band_pass.rb', line 58

def compute_period
  p0.peak = [0.991 * p1.peak, p0.bp.abs].max
  p0.real = p0.bp / p0.peak unless p0.peak.zero?
  p0.counter = p1.counter + 1
  p0.period = [p1.period, min_period].max.to_i
  p0.crosses = (p0.real > 0.0 && p1.real < 0.0) || (p0.real < 0.0 && p1.real > 0.0)
  if (p0.real >= 0.0 && p1.real < 0.0) || (p0.real <= 0.0 && p1.real > 0.0)
    p0.period = [2 * p0.counter, 1.25 * p1.period].min.to_i
    p0.period = [p0.period, 0.8 * p1.period].max.to_i
    p0.counter = 0
  end
  p0.direction = p0.real > (p1.real + p2.real + p3.real) / 3.0 ? :up : :down
end