Class: Quant::Settings::Indicators

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

Overview

Indicator settings provide a way to configure the default settings for indicators. Many of the indicators are built in adaptive measuring of the dominant cycle and these settings provide a way to configure your choices for the indicators. The default values come from various papers and books on the subject of technical analysis by John Ehlers where he variously suggests a minimum period of 8 or 10 and a max period of 48.

The half period is the average of the max_period and min_period. It is read-only and always computed relative to ‘min_period` and `max_period`.

The micro period comes from Ehler’s writings on Swami charts and auto-correlation computations, which is a period of 3 bars. It is useful enough in various indicators to be its own setting.

The dominant cycle kind is the kind of dominant cycle to use in the indicator. The default is :supplied_period which means the period is supplied by the caller (defaulting to the half_period config value). It is not adaptive when configured this way. The other kinds are adaptive and are computed from the series data. The choices are:

  • :supplied_period - The period is supplied externally by the caller; not adaptive (see SuppliedPeriod doc for the four canonical supply modes: fixed, manual, configured, external). Default.

  • :band_pass - The zero crossings of the band pass filter are used to compute the dominant cycle

  • :auto_correlation_reversal - The dominant cycle is computed from the auto-correlation of the series.

  • :homodyne - The dominant cycle is computed from the homodyne discriminator.

  • :differential - The dominant cycle is computed from the differential discriminator.

  • :phase_accumulator - The dominant cycle is computed from the phase accumulator.

  • :half_period - Deprecated alias for :supplied_period; removed in 0.9.0. Resolver emits a one-time warning per Settings::Indicators instance when this symbol is used.

All of the above are adaptive and are computed from the series data and are described in John Ehlers’ books and published papers.

Pivot kinds are started as the classic pivot points and then expanded to include other kinds of bands that follow along with price action such as Donchian channels, Fibonacci bands, Bollinger bands, Keltner bands, etc. The choices are as follows:

  • :pivot - Classic pivot points

  • :donchian - Donchian channels

  • :fibbonacci - Fibonacci bands

  • :woodie - Woodie’s pivot points

  • :classic - Classic pivot points

  • :camarilla - Camarilla pivot points

  • :demark - Demark pivot points

  • :murrey - Murrey math pivot points

  • :keltner - Keltner bands

  • :bollinger - Bollinger bands

  • :guppy - Guppy bands

  • :atr - ATR bands

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**settings) ⇒ Indicators

Returns a new instance of Indicators.



60
61
62
63
64
65
66
67
68
69
# File 'lib/quant/settings/indicators.rb', line 60

def initialize(**settings)
  @max_period = settings[:max_period] || Settings::MAX_PERIOD
  @min_period = settings[:min_period] || Settings::MIN_PERIOD
  @half_period = settings[:half_period] || compute_half_period
  @micro_period = settings[:micro_period] || Settings::MICRO_PERIOD

  @dominant_cycle_indicator_class = nil
  @dominant_cycle_kind = settings[:dominant_cycle_kind] || Settings::DOMINANT_CYCLE_KINDS.first
  @pivot_kind = settings[:pivot_kind] || Settings::PIVOT_KINDS.first
end

Instance Attribute Details

#dominant_cycle_kindObject

Returns the value of attribute dominant_cycle_kind.



58
59
60
# File 'lib/quant/settings/indicators.rb', line 58

def dominant_cycle_kind
  @dominant_cycle_kind
end

#half_periodObject (readonly)

Returns the value of attribute half_period.



57
58
59
# File 'lib/quant/settings/indicators.rb', line 57

def half_period
  @half_period
end

#max_periodObject

Returns the value of attribute max_period.



57
58
59
# File 'lib/quant/settings/indicators.rb', line 57

def max_period
  @max_period
end

#micro_periodObject

Returns the value of attribute micro_period.



58
59
60
# File 'lib/quant/settings/indicators.rb', line 58

def micro_period
  @micro_period
end

#min_periodObject

Returns the value of attribute min_period.



57
58
59
# File 'lib/quant/settings/indicators.rb', line 57

def min_period
  @min_period
end

#pivot_kindObject

Returns the value of attribute pivot_kind.



58
59
60
# File 'lib/quant/settings/indicators.rb', line 58

def pivot_kind
  @pivot_kind
end

Class Method Details

.defaultsObject

Returns an instance of the settings for indicators configured with defaults derived from defined constants in the Quant::Settings module.



53
54
55
# File 'lib/quant/settings/indicators.rb', line 53

def self.defaults
  new
end

Instance Method Details

#apply_settings(**settings) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/quant/settings/indicators.rb', line 71

def apply_settings(**settings)
  @max_period = settings.fetch(:max_period, @max_period)
  @min_period = settings.fetch(:min_period, @min_period)
  compute_half_period
  @micro_period = settings.fetch(:micro_period, @micro_period)
  @dominant_cycle_indicator_class = nil
  @dominant_cycle_kind = settings.fetch(:dominant_cycle_kind, @dominant_cycle_kind)
  @pivot_kind = settings.fetch(:pivot_kind, @pivot_kind)
end

#compute_half_periodObject



89
90
91
# File 'lib/quant/settings/indicators.rb', line 89

def compute_half_period
  @half_period = (max_period + min_period) / 2
end

#dominant_cycle_indicator_classObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/quant/settings/indicators.rb', line 93

def dominant_cycle_indicator_class
  return @dominant_cycle_indicator_class if @dominant_cycle_indicator_class

  resolved_kind = Settings::DEPRECATED_DOMINANT_CYCLE_KIND_ALIASES[dominant_cycle_kind] || dominant_cycle_kind
  if resolved_kind != dominant_cycle_kind
    @dc_kind_deprecation_warned ||= begin
      warn "[DEPRECATION] dominant_cycle_kind: :#{dominant_cycle_kind} is renamed to " \
           ":#{resolved_kind} (scheduled for removal in quantitative 0.9.0). " \
           "See Quant::Indicators::DominantCycles::SuppliedPeriod doc §Migration."
      true
    end
  end

  base_class_name = resolved_kind.to_s.split("_").map(&:capitalize).join
  class_name = "Quant::Indicators::DominantCycles::#{base_class_name}"

  @dominant_cycle_indicator_class = Object.const_get(class_name)
end