Class: Quant::IndicatorsSources

Inherits:
Object
  • Object
show all
Defined in:
lib/quant/indicators_sources.rb

Overview

IndicatorSources pairs a collection of Quant::Indicators::Indicator with an input source. This allows us to only compute indicators for the sources that are referenced at run-time. Any source explicitly used at run-time will have its indicator computed and only those indicators will be computed.

Constant Summary collapse

ALL_SOURCES =
PRICE_SOURCES = %i[price open_price high_price low_price close_price].freeze,
  VOLUME_SOURCES = %i[volume base_volume target_volume].freeze,
  COMPUTED_SOURCES = %i[oc2 hl2 hlc3 ohlc4].freeze
].flatten.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(series:) ⇒ IndicatorsSources

Returns a new instance of IndicatorsSources.



17
18
19
20
# File 'lib/quant/indicators_sources.rb', line 17

def initialize(series:)
  @series = series
  @sources = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



42
43
44
45
46
# File 'lib/quant/indicators_sources.rb', line 42

def method_missing(method_name, *args, &block)
  return super unless respond_to_missing?(method_name)

  oc2.send(method_name, *args, &block)
end

Instance Attribute Details

#seriesObject (readonly)

Returns the value of attribute series.



15
16
17
# File 'lib/quant/indicators_sources.rb', line 15

def series
  @series
end

Instance Method Details

#<<(tick) ⇒ Object



28
29
30
# File 'lib/quant/indicators_sources.rb', line 28

def <<(tick)
  @sources.each_value { |indicator| indicator << tick }
end

#[](source) ⇒ Object



22
23
24
25
26
# File 'lib/quant/indicators_sources.rb', line 22

def [](source)
  raise invalid_source_error(source:) unless ALL_SOURCES.include?(source)

  @sources[source] ||= IndicatorsSource.new(series:, source:)
end

#respond_to_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/quant/indicators_sources.rb', line 38

def respond_to_missing?(method, *)
  oc2.respond_to?(method)
end