Class: Quant::IndicatorsSource

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_cyclesObject (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

#pivotsObject (readonly)

Returns the value of attribute pivots.



19
20
21
# File 'lib/quant/indicators_source.rb', line 19

def pivots
  @pivots
end

#seriesObject (readonly)

Returns the value of attribute series.



19
20
21
# File 'lib/quant/indicators_source.rb', line 19

def series
  @series
end

#sourceObject (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

#adxObject



38
# File 'lib/quant/indicators_source.rb', line 38

def adx; indicator(Indicators::Adx) end

#atrObject



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.

Examples:

series.indicators.oc2.attach(name: :foo, indicator_class: Indicators::Foo)

Parameters:

  • name (Symbol)

    The name of the method to define for accessing the indicator.

  • indicator_class (Class)

    The class of the indicator to attach.



59
60
61
# File 'lib/quant/indicators_source.rb', line 59

def attach(name:, indicator_class:)
  define_singleton_method(name) { indicator(indicator_class) }
end

#cciObject



40
# File 'lib/quant/indicators_source.rb', line 40

def cci; indicator(Indicators::Cci) end

#decyclerObject



41
# File 'lib/quant/indicators_source.rb', line 41

def decycler; indicator(Indicators::Decycler) end

#dominant_cycleObject



63
64
65
# File 'lib/quant/indicators_source.rb', line 63

def dominant_cycle
  indicator(dominant_cycle_indicator_class)
end

#framaObject



42
# File 'lib/quant/indicators_source.rb', line 42

def frama; indicator(Indicators::Frama) end

#mamaObject



43
# File 'lib/quant/indicators_source.rb', line 43

def mama; indicator(Indicators::Mama) end

#mesaObject



44
# File 'lib/quant/indicators_source.rb', line 44

def mesa; indicator(Indicators::Mesa) end

#pingObject



45
# File 'lib/quant/indicators_source.rb', line 45

def ping; indicator(Indicators::Ping) end