Class: Quant::Indicators::Pivots::Pivot

Inherits:
Indicator
  • Object
show all
Defined in:
lib/quant/indicators/pivots/pivot.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, #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

#averaging_periodObject



65
66
67
# File 'lib/quant/indicators/pivots/pivot.rb', line 65

def averaging_period
  min_period
end

#band?(band) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/quant/indicators/pivots/pivot.rb', line 57

def band?(band)
  p0.key?(band)
end

#computeObject



77
78
79
80
81
82
# File 'lib/quant/indicators/pivots/pivot.rb', line 77

def compute
  compute_extents
  compute_value
  compute_midpoint
  compute_bands
end

#compute_bandsObject



92
93
94
# File 'lib/quant/indicators/pivots/pivot.rb', line 92

def compute_bands
  # No-op -- override in subclasses
end

#compute_extentsObject



96
97
98
99
100
101
102
103
104
105
# File 'lib/quant/indicators/pivots/pivot.rb', line 96

def compute_extents
  period_midpoints.tap do |midpoints|
    p0.highest = midpoints.max
    p0.lowest = midpoints.min
    p0.range = p0.high_price - p0.low_price
    p0.avg_low = three_pole_super_smooth(:low_price, previous: :avg_low, period: averaging_period)
    p0.avg_high = three_pole_super_smooth(:high_price, previous: :avg_high, period: averaging_period)
    p0.avg_range = three_pole_super_smooth(:range, previous: :avg_range, period: averaging_period)
  end
end

#compute_midpointObject



84
85
86
# File 'lib/quant/indicators/pivots/pivot.rb', line 84

def compute_midpoint
  p0.midpoint = p0.input
end

#compute_valueObject



88
89
90
# File 'lib/quant/indicators/pivots/pivot.rb', line 88

def compute_value
  # No-op -- override in subclasses
end

#periodObject



61
62
63
# File 'lib/quant/indicators/pivots/pivot.rb', line 61

def period
  adaptive_period
end

#period_midpointsObject



69
70
71
# File 'lib/quant/indicators/pivots/pivot.rb', line 69

def period_midpoints
  period_points(period).map(&:midpoint)
end

#points_classObject



53
54
55
# File 'lib/quant/indicators/pivots/pivot.rb', line 53

def points_class
  Quant::Indicators::Pivots::PivotPoint
end

#smoothed_average_midpointObject



73
74
75
# File 'lib/quant/indicators/pivots/pivot.rb', line 73

def smoothed_average_midpoint
  three_pole_super_smooth :input, previous: :midpoint, period: averaging_period
end