Class: Quant::IndicatorsSource
- Inherits:
-
Object
- Object
- Quant::IndicatorsSource
- Defined in:
- lib/quant/indicators_source.rb
Overview
IndicatorSource holds a collection of Quant::Indicators::Indicator for a given input source. This class ensures dominant cycle computations come before other indicators that depend on them.
The IndicatorSource class is responsible for lazily loading indicators so that not all indicators are always engaged and computing their values. If the indicator is never accessed, it’s never computed, saving valuable processing CPU cycles.
Indicators are generally built around the concept of a source input value and that source is designated by the source parameter when instantiating the IndicatorSource class.
By design, the Quant::Indicators::Indicator class holds the Ticks::Tick instance alongside the indicator’s computed values for that tick.
Instance Attribute Summary collapse
-
#dominant_cycles ⇒ Object
readonly
Returns the value of attribute dominant_cycles.
-
#pivots ⇒ Object
readonly
Returns the value of attribute pivots.
-
#series ⇒ Object
readonly
Returns the value of attribute series.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #<<(tick) ⇒ Object
- #[](indicator_class) ⇒ Object
- #adx ⇒ Object
- #atr ⇒ Object
-
#attach(name:, indicator_class:) ⇒ Object
Attaches a given Indicator class and defines the method for accessing it using the given name.
- #cci ⇒ Object
- #decycler ⇒ Object
- #dominant_cycle ⇒ Object
- #frama ⇒ Object
-
#initialize(series:, source:) ⇒ IndicatorsSource
constructor
A new instance of IndicatorsSource.
- #mama ⇒ Object
- #mesa ⇒ Object
- #ping ⇒ Object
Constructor Details
#initialize(series:, source:) ⇒ IndicatorsSource
Returns a new instance of IndicatorsSource.
21 22 23 24 25 26 27 28 |
# File 'lib/quant/indicators_source.rb', line 21 def initialize(series:, source:) @series = series @source = source @indicators = {} @ordered_indicators = [] @dominant_cycles = DominantCyclesSource.new(indicator_source: self) @pivots = PivotsSource.new(indicator_source: self) end |
Instance Attribute Details
#dominant_cycles ⇒ Object (readonly)
Returns the value of attribute dominant_cycles.
19 20 21 |
# File 'lib/quant/indicators_source.rb', line 19 def dominant_cycles @dominant_cycles end |
#pivots ⇒ Object (readonly)
Returns the value of attribute pivots.
19 20 21 |
# File 'lib/quant/indicators_source.rb', line 19 def pivots @pivots end |
#series ⇒ Object (readonly)
Returns the value of attribute series.
19 20 21 |
# File 'lib/quant/indicators_source.rb', line 19 def series @series end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
19 20 21 |
# File 'lib/quant/indicators_source.rb', line 19 def source @source end |
Instance Method Details
#<<(tick) ⇒ Object
34 35 36 |
# File 'lib/quant/indicators_source.rb', line 34 def <<(tick) @ordered_indicators.each { |indicator| indicator << tick } end |
#[](indicator_class) ⇒ Object
30 31 32 |
# File 'lib/quant/indicators_source.rb', line 30 def [](indicator_class) indicator(indicator_class) end |
#adx ⇒ Object
38 |
# File 'lib/quant/indicators_source.rb', line 38 def adx; indicator(Indicators::Adx) end |
#atr ⇒ Object
39 |
# File 'lib/quant/indicators_source.rb', line 39 def atr; indicator(Indicators::Atr) end |
#attach(name:, indicator_class:) ⇒ Object
Attaches a given Indicator class and defines the method for accessing it using the given name. Indicators take care of computing their values when first attached to a populated series.
The indicators shipped with the library are all wired into the framework, thus this method should be used for custom indicators not shipped with the library.
59 60 61 |
# File 'lib/quant/indicators_source.rb', line 59 def attach(name:, indicator_class:) define_singleton_method(name) { indicator(indicator_class) } end |
#cci ⇒ Object
40 |
# File 'lib/quant/indicators_source.rb', line 40 def cci; indicator(Indicators::Cci) end |
#decycler ⇒ Object
41 |
# File 'lib/quant/indicators_source.rb', line 41 def decycler; indicator(Indicators::Decycler) end |
#dominant_cycle ⇒ Object
63 64 65 |
# File 'lib/quant/indicators_source.rb', line 63 def dominant_cycle indicator(dominant_cycle_indicator_class) end |
#frama ⇒ Object
42 |
# File 'lib/quant/indicators_source.rb', line 42 def frama; indicator(Indicators::Frama) end |
#mama ⇒ Object
43 |
# File 'lib/quant/indicators_source.rb', line 43 def mama; indicator(Indicators::Mama) end |
#mesa ⇒ Object
44 |
# File 'lib/quant/indicators_source.rb', line 44 def mesa; indicator(Indicators::Mesa) end |
#ping ⇒ Object
45 |
# File 'lib/quant/indicators_source.rb', line 45 def ping; indicator(Indicators::Ping) end |