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.



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

#pivotsObject (readonly)

Returns the value of attribute pivots.



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

def pivots
  @pivots
end

#seriesObject (readonly)

Returns the value of attribute series.



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

def series
  @series
end

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

#adxObject



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

def adx; indicator(Indicators::Adx) end

#atrObject



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.

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.



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

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

#cciObject



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

def cci; indicator(Indicators::Cci) end

#decyclerObject



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

def decycler; indicator(Indicators::Decycler) end

#dominant_cycleObject



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

def dominant_cycle
  indicator(dominant_cycle_indicator_class)
end

#framaObject



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

def frama; indicator(Indicators::Frama) end

#mamaObject



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

def mama; indicator(Indicators::Mama) end

#mesaObject



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

def mesa; indicator(Indicators::Mesa) end

#pingObject



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

def ping; indicator(Indicators::Ping) end