Class: Quant::Indicators::Indicator
- Inherits:
-
Object
- Object
- Quant::Indicators::Indicator
- Includes:
- Enumerable, Mixins::Filters, Mixins::FisherTransform, Mixins::Functions, Mixins::HilbertTransform, Mixins::MovingAverages, Mixins::Stochastic, Mixins::SuperSmoother
- Defined in:
- lib/quant/indicators/indicator.rb
Direct Known Subclasses
Constant Summary
Constants included from Mixins::UniversalFilters
Instance Attribute Summary collapse
-
#p0 ⇒ Object
readonly
Returns the value of attribute p0.
-
#p1 ⇒ Object
readonly
Returns the value of attribute p1.
-
#p2 ⇒ Object
readonly
Returns the value of attribute p2.
-
#p3 ⇒ Object
readonly
Returns the value of attribute p3.
-
#series ⇒ Object
readonly
include Mixins::Direction.
-
#source ⇒ Object
readonly
include Mixins::Direction.
-
#t0 ⇒ Object
readonly
Returns the value of attribute t0.
-
#t1 ⇒ Object
readonly
Returns the value of attribute t1.
-
#t2 ⇒ Object
readonly
Returns the value of attribute t2.
-
#t3 ⇒ Object
readonly
Returns the value of attribute t3.
Instance Method Summary collapse
- #<<(tick) ⇒ Object
- #[](index) ⇒ Object
- #compute ⇒ Object
- #dominant_cycle_kind ⇒ Object
- #each(&block) ⇒ Object
- #half_period ⇒ Object
- #indicator_name ⇒ Object
-
#initialize(series:, source:) ⇒ Indicator
constructor
A new instance of Indicator.
-
#input ⇒ Numeric
The input is the value derived from the source for the indicator for the current tick.
- #inspect ⇒ Object
- #max_period ⇒ Object
- #micro_period ⇒ Object
- #min_period ⇒ Object
- #p(offset) ⇒ Object
- #pivot_kind ⇒ Object
- #points_class ⇒ Object
- #size ⇒ Object
- #t(offset) ⇒ Object
- #ticks ⇒ Object
- #values ⇒ Object
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
#initialize(series:, source:) ⇒ Indicator
Returns a new instance of Indicator.
18 19 20 21 22 23 |
# File 'lib/quant/indicators/indicator.rb', line 18 def initialize(series:, source:) @series = series @source = source @points = {} series.each { |tick| self << tick } end |
Instance Attribute Details
#p0 ⇒ Object (readonly)
Returns the value of attribute p0.
65 66 67 |
# File 'lib/quant/indicators/indicator.rb', line 65 def p0 @p0 end |
#p1 ⇒ Object (readonly)
Returns the value of attribute p1.
65 66 67 |
# File 'lib/quant/indicators/indicator.rb', line 65 def p1 @p1 end |
#p2 ⇒ Object (readonly)
Returns the value of attribute p2.
65 66 67 |
# File 'lib/quant/indicators/indicator.rb', line 65 def p2 @p2 end |
#p3 ⇒ Object (readonly)
Returns the value of attribute p3.
65 66 67 |
# File 'lib/quant/indicators/indicator.rb', line 65 def p3 @p3 end |
#series ⇒ Object (readonly)
include Mixins::Direction
16 17 18 |
# File 'lib/quant/indicators/indicator.rb', line 16 def series @series end |
#source ⇒ Object (readonly)
include Mixins::Direction
16 17 18 |
# File 'lib/quant/indicators/indicator.rb', line 16 def source @source end |
#t0 ⇒ Object (readonly)
Returns the value of attribute t0.
66 67 68 |
# File 'lib/quant/indicators/indicator.rb', line 66 def t0 @t0 end |
#t1 ⇒ Object (readonly)
Returns the value of attribute t1.
66 67 68 |
# File 'lib/quant/indicators/indicator.rb', line 66 def t1 @t1 end |
#t2 ⇒ Object (readonly)
Returns the value of attribute t2.
66 67 68 |
# File 'lib/quant/indicators/indicator.rb', line 66 def t2 @t2 end |
#t3 ⇒ Object (readonly)
Returns the value of attribute t3.
66 67 68 |
# File 'lib/quant/indicators/indicator.rb', line 66 def t3 @t3 end |
Instance Method Details
#<<(tick) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/quant/indicators/indicator.rb', line 68 def <<(tick) @t0 = tick @p0 = points_class.new(indicator: self, tick:, source:) @points[tick] = @p0 @p1 = values[-2] || @p0 @p2 = values[-3] || @p1 @p3 = values[-4] || @p2 @t1 = ticks[-2] || @t0 @t2 = ticks[-3] || @t1 @t3 = ticks[-4] || @t2 compute end |
#[](index) ⇒ Object
53 54 55 |
# File 'lib/quant/indicators/indicator.rb', line 53 def [](index) values[index] end |
#compute ⇒ Object
92 93 94 |
# File 'lib/quant/indicators/indicator.rb', line 92 def compute raise NotImplementedError end |
#dominant_cycle_kind ⇒ Object
41 42 43 |
# File 'lib/quant/indicators/indicator.rb', line 41 def dominant_cycle_kind Quant.config.indicators.dominant_cycle_kind end |
#each(&block) ⇒ Object
84 85 86 |
# File 'lib/quant/indicators/indicator.rb', line 84 def each(&block) @points.each_value(&block) end |
#half_period ⇒ Object
33 34 35 |
# File 'lib/quant/indicators/indicator.rb', line 33 def half_period Quant.config.indicators.half_period end |
#indicator_name ⇒ Object
96 97 98 |
# File 'lib/quant/indicators/indicator.rb', line 96 def indicator_name self.class.name.split("::").last end |
#input ⇒ Numeric
The input is the value derived from the source for the indicator for the current tick. For example, if the source is :oc2, then the input is the value of the current tick’s (open + close) / 2
131 132 133 |
# File 'lib/quant/indicators/indicator.rb', line 131 def input t0.send(source) end |
#inspect ⇒ Object
88 89 90 |
# File 'lib/quant/indicators/indicator.rb', line 88 def inspect "#<#{self.class.name} symbol=#{series.symbol} source=#{source} ticks=#{ticks.size}>" end |
#max_period ⇒ Object
29 30 31 |
# File 'lib/quant/indicators/indicator.rb', line 29 def max_period Quant.config.indicators.max_period end |
#micro_period ⇒ Object
37 38 39 |
# File 'lib/quant/indicators/indicator.rb', line 37 def micro_period Quant.config.indicators.micro_period end |
#min_period ⇒ Object
25 26 27 |
# File 'lib/quant/indicators/indicator.rb', line 25 def min_period Quant.config.indicators.min_period end |
#p(offset) ⇒ Object
108 109 110 111 112 113 |
# File 'lib/quant/indicators/indicator.rb', line 108 def p(offset) raise ArgumentError, "offset must be a positive value" if offset < 0 index = offset + 1 values[[-index, -size].max] end |
#pivot_kind ⇒ Object
45 46 47 |
# File 'lib/quant/indicators/indicator.rb', line 45 def pivot_kind Quant.config.indicators.pivot_kind end |
#points_class ⇒ Object
100 101 102 |
# File 'lib/quant/indicators/indicator.rb', line 100 def points_class Object.const_get "Quant::Indicators::#{indicator_name}Point" end |
#size ⇒ Object
61 62 63 |
# File 'lib/quant/indicators/indicator.rb', line 61 def size @points.size end |
#t(offset) ⇒ Object
119 120 121 122 123 124 |
# File 'lib/quant/indicators/indicator.rb', line 119 def t(offset) raise ArgumentError, "offset must be a positive value" if offset < 0 index = offset + 1 ticks[[-index, -size].max] end |
#ticks ⇒ Object
49 50 51 |
# File 'lib/quant/indicators/indicator.rb', line 49 def ticks @points.keys end |
#values ⇒ Object
57 58 59 |
# File 'lib/quant/indicators/indicator.rb', line 57 def values @points.values end |