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.
22 23 24 25 26 27 28 29 |
# File 'lib/quant/indicators_source.rb', line 22 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.
20 21 22 |
# File 'lib/quant/indicators_source.rb', line 20 def dominant_cycles @dominant_cycles end |
#pivots ⇒ Object (readonly)
Returns the value of attribute pivots.
20 21 22 |
# File 'lib/quant/indicators_source.rb', line 20 def pivots @pivots end |
#series ⇒ Object (readonly)
Returns the value of attribute series.
20 21 22 |
# File 'lib/quant/indicators_source.rb', line 20 def series @series end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
20 21 22 |
# File 'lib/quant/indicators_source.rb', line 20 def source @source end |
Instance Method Details
#<<(tick) ⇒ Object
35 36 37 |
# File 'lib/quant/indicators_source.rb', line 35 def <<(tick) @ordered_indicators.each { |indicator| indicator << tick } end |
#[](indicator_class) ⇒ Object
31 32 33 |
# File 'lib/quant/indicators_source.rb', line 31 def [](indicator_class) indicator(indicator_class) end |
#adx ⇒ Object
39 |
# File 'lib/quant/indicators_source.rb', line 39 def adx; indicator(Indicators::Adx) end |
#atr ⇒ Object
40 |
# File 'lib/quant/indicators_source.rb', line 40 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.
60 61 62 |
# File 'lib/quant/indicators_source.rb', line 60 def attach(name:, indicator_class:) define_singleton_method(name) { indicator(indicator_class) } end |
#cci ⇒ Object
41 |
# File 'lib/quant/indicators_source.rb', line 41 def cci; indicator(Indicators::Cci) end |
#decycler ⇒ Object
42 |
# File 'lib/quant/indicators_source.rb', line 42 def decycler; indicator(Indicators::Decycler) end |
#dominant_cycle ⇒ Object
64 65 66 |
# File 'lib/quant/indicators_source.rb', line 64 def dominant_cycle indicator(dominant_cycle_indicator_class) end |
#frama ⇒ Object
43 |
# File 'lib/quant/indicators_source.rb', line 43 def frama; indicator(Indicators::Frama) end |
#mama ⇒ Object
44 |
# File 'lib/quant/indicators_source.rb', line 44 def mama; indicator(Indicators::Mama) end |
#mesa ⇒ Object
45 |
# File 'lib/quant/indicators_source.rb', line 45 def mesa; indicator(Indicators::Mesa) end |
#ping ⇒ Object
46 |
# File 'lib/quant/indicators_source.rb', line 46 def ping; indicator(Indicators::Ping) end |