Class: Quant::Indicators::Indicator
- Inherits:
-
Object
- Object
- Quant::Indicators::Indicator
- Includes:
- Enumerable
- Defined in:
- lib/quant/indicators/indicator.rb
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::TrendMethods include Mixins::Trig include Mixins::WeightedAverage include Mixins::HilbertTransform include Mixins::SuperSmoother include Mixins::Stochastic include Mixins::FisherTransform include Mixins::HighPassFilter include Mixins::Direction include Mixins::Filters.
-
#source ⇒ Object
readonly
# include Mixins::TrendMethods include Mixins::Trig include Mixins::WeightedAverage include Mixins::HilbertTransform include Mixins::SuperSmoother include Mixins::Stochastic include Mixins::FisherTransform include Mixins::HighPassFilter include Mixins::Direction include Mixins::Filters.
-
#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
- #compute ⇒ Object
- #each(&block) ⇒ 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
- #p(offset) ⇒ Object
- #points_class ⇒ Object
- #size ⇒ Object
- #t(offset) ⇒ Object
- #ticks ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(series:, source:) ⇒ Indicator
Returns a new instance of Indicator.
19 20 21 22 23 24 |
# File 'lib/quant/indicators/indicator.rb', line 19 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.
38 39 40 |
# File 'lib/quant/indicators/indicator.rb', line 38 def p0 @p0 end |
#p1 ⇒ Object (readonly)
Returns the value of attribute p1.
38 39 40 |
# File 'lib/quant/indicators/indicator.rb', line 38 def p1 @p1 end |
#p2 ⇒ Object (readonly)
Returns the value of attribute p2.
38 39 40 |
# File 'lib/quant/indicators/indicator.rb', line 38 def p2 @p2 end |
#p3 ⇒ Object (readonly)
Returns the value of attribute p3.
38 39 40 |
# File 'lib/quant/indicators/indicator.rb', line 38 def p3 @p3 end |
#series ⇒ Object (readonly)
# include Mixins::TrendMethods include Mixins::Trig include Mixins::WeightedAverage include Mixins::HilbertTransform include Mixins::SuperSmoother include Mixins::Stochastic include Mixins::FisherTransform include Mixins::HighPassFilter include Mixins::Direction include Mixins::Filters
17 18 19 |
# File 'lib/quant/indicators/indicator.rb', line 17 def series @series end |
#source ⇒ Object (readonly)
# include Mixins::TrendMethods include Mixins::Trig include Mixins::WeightedAverage include Mixins::HilbertTransform include Mixins::SuperSmoother include Mixins::Stochastic include Mixins::FisherTransform include Mixins::HighPassFilter include Mixins::Direction include Mixins::Filters
17 18 19 |
# File 'lib/quant/indicators/indicator.rb', line 17 def source @source end |
#t0 ⇒ Object (readonly)
Returns the value of attribute t0.
39 40 41 |
# File 'lib/quant/indicators/indicator.rb', line 39 def t0 @t0 end |
#t1 ⇒ Object (readonly)
Returns the value of attribute t1.
39 40 41 |
# File 'lib/quant/indicators/indicator.rb', line 39 def t1 @t1 end |
#t2 ⇒ Object (readonly)
Returns the value of attribute t2.
39 40 41 |
# File 'lib/quant/indicators/indicator.rb', line 39 def t2 @t2 end |
#t3 ⇒ Object (readonly)
Returns the value of attribute t3.
39 40 41 |
# File 'lib/quant/indicators/indicator.rb', line 39 def t3 @t3 end |
Instance Method Details
#<<(tick) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/quant/indicators/indicator.rb', line 41 def <<(tick) @t0 = tick @p0 = points_class.new(tick: tick, source: 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 |
#compute ⇒ Object
65 66 67 |
# File 'lib/quant/indicators/indicator.rb', line 65 def compute raise NotImplementedError end |
#each(&block) ⇒ Object
57 58 59 |
# File 'lib/quant/indicators/indicator.rb', line 57 def each(&block) @points.each_value(&block) end |
#indicator_name ⇒ Object
69 70 71 |
# File 'lib/quant/indicators/indicator.rb', line 69 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
104 105 106 |
# File 'lib/quant/indicators/indicator.rb', line 104 def input t0.send(source) end |
#inspect ⇒ Object
61 62 63 |
# File 'lib/quant/indicators/indicator.rb', line 61 def inspect "#<#{self.class.name} symbol=#{series.symbol} source=#{source} #{points.size} ticks>" end |
#p(offset) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/quant/indicators/indicator.rb', line 81 def p(offset) raise ArgumentError, "offset must be a positive value" if offset < 0 index = offset + 1 values[[-index, -size].max] end |
#points_class ⇒ Object
73 74 75 |
# File 'lib/quant/indicators/indicator.rb', line 73 def points_class Object.const_get "Quant::Indicators::#{indicator_name}Point" end |
#size ⇒ Object
34 35 36 |
# File 'lib/quant/indicators/indicator.rb', line 34 def size @points.size end |
#t(offset) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/quant/indicators/indicator.rb', line 92 def t(offset) raise ArgumentError, "offset must be a positive value" if offset < 0 index = offset + 1 ticks[[-index, -size].max] end |
#ticks ⇒ Object
26 27 28 |
# File 'lib/quant/indicators/indicator.rb', line 26 def ticks @points.keys end |
#values ⇒ Object
30 31 32 |
# File 'lib/quant/indicators/indicator.rb', line 30 def values @points.values end |