Class: Quant::Indicators::DominantCycles::BandPass
- Inherits:
-
DominantCycle
- Object
- Indicator
- DominantCycle
- Quant::Indicators::DominantCycles::BandPass
- Defined in:
- lib/quant/indicators/dominant_cycles/band_pass.rb
Overview
The band-pass dominant cycle passes signals within a certain frequency range, and attenuates signals outside that range. The trend component of the signal is revoved, leaving only the cyclical component. Then we count number of iterations between zero crossings and this is the ‘period` of the dominant cycle.
Constant Summary
Constants inherited from Indicator
Constants included from Mixins::UniversalFilters
Instance Attribute Summary
Attributes inherited from DominantCycle
Attributes inherited from Indicator
#p0, #p1, #p2, #p3, #series, #source, #t0, #t1, #t2, #t3
Instance Method Summary collapse
- #bandwidth ⇒ Object
- #compute ⇒ Object
- #compute_band_pass ⇒ Object
- #compute_high_pass ⇒ Object
- #compute_period ⇒ Object
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_indicator_class, #dominant_cycle_period, #points_class, #priority
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
Methods included from Mixins::SuperSmoother
#three_pole_super_smooth, #two_pole_super_smooth
Methods included from Mixins::HilbertTransform
Methods included from Mixins::ExponentialMovingAverage
Methods included from Mixins::SimpleMovingAverage
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
#bandwidth ⇒ Object
25 26 27 |
# File 'lib/quant/indicators/dominant_cycles/band_pass.rb', line 25 def bandwidth 0.75 end |
#compute ⇒ Object
79 80 81 82 83 |
# File 'lib/quant/indicators/dominant_cycles/band_pass.rb', line 79 def compute compute_high_pass compute_band_pass compute_period end |
#compute_band_pass ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/quant/indicators/dominant_cycles/band_pass.rb', line 53 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_pass ⇒ Object
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;
48 49 50 51 |
# File 'lib/quant/indicators/dominant_cycles/band_pass.rb', line 48 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_period ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/quant/indicators/dominant_cycles/band_pass.rb', line 65 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 |