quantitative 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/quant/dominant_cycles_source.rb +1 -32
  4. data/lib/quant/indicators/adx.rb +2 -5
  5. data/lib/quant/indicators/atr.rb +2 -0
  6. data/lib/quant/indicators/cci.rb +2 -0
  7. data/lib/quant/indicators/decycler.rb +2 -0
  8. data/lib/quant/indicators/dominant_cycles/acr.rb +2 -0
  9. data/lib/quant/indicators/dominant_cycles/band_pass.rb +2 -0
  10. data/lib/quant/indicators/dominant_cycles/differential.rb +2 -0
  11. data/lib/quant/indicators/dominant_cycles/half_period.rb +2 -0
  12. data/lib/quant/indicators/dominant_cycles/homodyne.rb +2 -0
  13. data/lib/quant/indicators/dominant_cycles/phase_accumulator.rb +2 -0
  14. data/lib/quant/indicators/ema.rb +67 -0
  15. data/lib/quant/indicators/frama.rb +1 -0
  16. data/lib/quant/indicators/indicator.rb +17 -57
  17. data/lib/quant/indicators/indicator_point.rb +11 -0
  18. data/lib/quant/indicators/mama.rb +2 -0
  19. data/lib/quant/indicators/mesa.rb +3 -4
  20. data/lib/quant/indicators/ping.rb +2 -0
  21. data/lib/quant/indicators/pivots/atr.rb +11 -16
  22. data/lib/quant/indicators/pivots/bollinger.rb +10 -25
  23. data/lib/quant/indicators/pivots/camarilla.rb +30 -31
  24. data/lib/quant/indicators/pivots/classic.rb +3 -1
  25. data/lib/quant/indicators/pivots/demark.rb +5 -3
  26. data/lib/quant/indicators/pivots/donchian.rb +20 -23
  27. data/lib/quant/indicators/pivots/fibbonacci.rb +12 -9
  28. data/lib/quant/indicators/pivots/guppy.rb +3 -1
  29. data/lib/quant/indicators/pivots/keltner.rb +11 -19
  30. data/lib/quant/indicators/pivots/murrey.rb +8 -13
  31. data/lib/quant/indicators/pivots/pivot.rb +109 -0
  32. data/lib/quant/indicators/pivots/traditional.rb +2 -0
  33. data/lib/quant/indicators/pivots/woodie.rb +2 -0
  34. data/lib/quant/indicators/rocket_rsi.rb +57 -0
  35. data/lib/quant/indicators/roofing.rb +59 -0
  36. data/lib/quant/indicators/rsi.rb +67 -0
  37. data/lib/quant/indicators/snr.rb +64 -0
  38. data/lib/quant/indicators_registry.rb +63 -0
  39. data/lib/quant/indicators_source.rb +14 -9
  40. data/lib/quant/pivots_source.rb +1 -13
  41. data/lib/quant/version.rb +1 -1
  42. data/lib/quantitative.rb +10 -3
  43. metadata +9 -3
  44. data/lib/quant/indicators/pivot.rb +0 -107
@@ -16,13 +16,18 @@ module Quant
16
16
  # By design, the {Quant::Indicators::Indicator} class holds the {Quant::Ticks::Tick} instance
17
17
  # alongside the indicator's computed values for that tick.
18
18
  class IndicatorsSource
19
+ include IndicatorsRegistry
20
+
19
21
  attr_reader :series, :source, :dominant_cycles, :pivots
20
22
 
21
23
  def initialize(series:, source:)
22
24
  @series = series
23
25
  @source = source
26
+
24
27
  @indicators = {}
25
28
  @ordered_indicators = []
29
+ define_indicator_accessors(indicator_source: self)
30
+
26
31
  @dominant_cycles = DominantCyclesSource.new(indicator_source: self)
27
32
  @pivots = PivotsSource.new(indicator_source: self)
28
33
  end
@@ -35,20 +40,19 @@ module Quant
35
40
  @ordered_indicators.each { |indicator| indicator << tick }
36
41
  end
37
42
 
38
- def adx; indicator(Indicators::Adx) end
39
- def atr; indicator(Indicators::Atr) end
40
- def cci; indicator(Indicators::Cci) end
41
- def decycler; indicator(Indicators::Decycler) end
42
- def frama; indicator(Indicators::Frama) end
43
- def mama; indicator(Indicators::Mama) end
44
- def mesa; indicator(Indicators::Mesa) end
45
- def ping; indicator(Indicators::Ping) end
46
-
47
43
  # Attaches a given Indicator class and defines the method for
48
44
  # accessing it using the given name. Indicators take care of
49
45
  # computing their values when first attached to a populated
50
46
  # series.
51
47
  #
48
+ # NOTE: You can also use the `register` method on the indicator class to
49
+ # accomplish the same thing. `attach` lets you inject a custom indicator
50
+ # at run-time when you have an instance of {Quant::IndicatorsSource} while
51
+ # the `register` method is used to define the indicator at load-time.
52
+ #
53
+ # NOTE Calling `attach` also registers the indicator with the framework, so
54
+ # you only have to `attach` once.
55
+ #
52
56
  # The indicators shipped with the library are all wired into the framework, thus
53
57
  # this method should be used for custom indicators not shipped with the library.
54
58
  #
@@ -57,6 +61,7 @@ module Quant
57
61
  # @example
58
62
  # series.indicators.oc2.attach(name: :foo, indicator_class: Indicators::Foo)
59
63
  def attach(name:, indicator_class:)
64
+ self.class.register(name:, indicator_class:)
60
65
  define_singleton_method(name) { indicator(indicator_class) }
61
66
  end
62
67
 
@@ -4,21 +4,9 @@ module Quant
4
4
  class PivotsSource
5
5
  def initialize(indicator_source:)
6
6
  @indicator_source = indicator_source
7
+ indicator_source.define_indicator_accessors(indicator_source: self)
7
8
  end
8
9
 
9
- def atr; indicator(Indicators::Pivots::Atr) end
10
- def bollinger; indicator(Indicators::Pivots::Bollinger) end
11
- def camarilla; indicator(Indicators::Pivots::Camarilla) end
12
- def classic; indicator(Indicators::Pivots::Classic) end
13
- def demark; indicator(Indicators::Pivots::Demark) end
14
- def donchian; indicator(Indicators::Pivots::Donchian) end
15
- def fibbonacci; indicator(Indicators::Pivots::Fibbonacci) end
16
- def guppy; indicator(Indicators::Pivots::Guppy) end
17
- def keltner; indicator(Indicators::Pivots::Keltner) end
18
- def murrey; indicator(Indicators::Pivots::Murrey) end
19
- def traditional; indicator(Indicators::Pivots::Traditional) end
20
- def woodie; indicator(Indicators::Pivots::Woodie) end
21
-
22
10
  private
23
11
 
24
12
  def indicator(indicator_class)
data/lib/quant/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Quant
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.3"
5
5
  end
data/lib/quantitative.rb CHANGED
@@ -18,6 +18,7 @@ module Quant
18
18
  include Config
19
19
  include Experimental
20
20
  end
21
+ Quantitative = Quant
21
22
 
22
23
  # Configure Zeitwerk to autoload the Quant module.
23
24
  loader = Zeitwerk::Loader.for_gem
@@ -29,6 +30,12 @@ loader.inflector.inflect "version" => "VERSION"
29
30
  loader.setup
30
31
 
31
32
  # Refinements aren't autoloaded by Zeitwerk, so we need to require them manually.
32
- %w(refinements).each do |sub_folder|
33
- Dir.glob(File.join(quant_folder, sub_folder, "**/*.rb")).each { |fn| require fn }
34
- end
33
+ # %w(refinements).each do |sub_folder|
34
+ # Dir.glob(File.join(quant_folder, sub_folder, "**/*.rb")).each { |fn| require fn }
35
+ # end
36
+
37
+ refinements_folder = File.join(quant_folder, "refinements")
38
+ indicators_folder = File.join(quant_folder, "indicators")
39
+
40
+ loader.eager_load_dir(refinements_folder)
41
+ loader.eager_load_dir(indicators_folder)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quantitative
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Lang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-01 00:00:00.000000000 Z
11
+ date: 2024-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -77,13 +77,13 @@ files:
77
77
  - lib/quant/indicators/dominant_cycles/half_period.rb
78
78
  - lib/quant/indicators/dominant_cycles/homodyne.rb
79
79
  - lib/quant/indicators/dominant_cycles/phase_accumulator.rb
80
+ - lib/quant/indicators/ema.rb
80
81
  - lib/quant/indicators/frama.rb
81
82
  - lib/quant/indicators/indicator.rb
82
83
  - lib/quant/indicators/indicator_point.rb
83
84
  - lib/quant/indicators/mama.rb
84
85
  - lib/quant/indicators/mesa.rb
85
86
  - lib/quant/indicators/ping.rb
86
- - lib/quant/indicators/pivot.rb
87
87
  - lib/quant/indicators/pivots/atr.rb
88
88
  - lib/quant/indicators/pivots/bollinger.rb
89
89
  - lib/quant/indicators/pivots/camarilla.rb
@@ -94,8 +94,14 @@ files:
94
94
  - lib/quant/indicators/pivots/guppy.rb
95
95
  - lib/quant/indicators/pivots/keltner.rb
96
96
  - lib/quant/indicators/pivots/murrey.rb
97
+ - lib/quant/indicators/pivots/pivot.rb
97
98
  - lib/quant/indicators/pivots/traditional.rb
98
99
  - lib/quant/indicators/pivots/woodie.rb
100
+ - lib/quant/indicators/rocket_rsi.rb
101
+ - lib/quant/indicators/roofing.rb
102
+ - lib/quant/indicators/rsi.rb
103
+ - lib/quant/indicators/snr.rb
104
+ - lib/quant/indicators_registry.rb
99
105
  - lib/quant/indicators_source.rb
100
106
  - lib/quant/indicators_sources.rb
101
107
  - lib/quant/interval.rb
@@ -1,107 +0,0 @@
1
- module Quant
2
- module Indicators
3
- class PivotPoint < IndicatorPoint
4
- attribute :high_price
5
- attribute :avg_high, default: :high_price
6
- attribute :highest, default: :input
7
-
8
- attribute :low_price
9
- attribute :avg_low, default: :low_price
10
- attribute :lowest, default: :input
11
-
12
- attribute :range, default: 0.0
13
- attribute :avg_range, default: 0.0
14
- attribute :std_dev, default: 0.0
15
-
16
- def bands
17
- @bands ||= { 0 => input }
18
- end
19
-
20
- def [](band)
21
- bands[band]
22
- end
23
-
24
- def []=(band, value)
25
- bands[band] = value
26
- end
27
-
28
- def key?(band)
29
- bands.key?(band)
30
- end
31
-
32
- def midpoint
33
- bands[0]
34
- end
35
- alias :h0 :midpoint
36
- alias :l0 :midpoint
37
-
38
- def midpoint=(value)
39
- bands[0] = value
40
- end
41
- alias :h0= :midpoint=
42
- alias :l0= :midpoint=
43
-
44
- (1..8).each do |band|
45
- define_method("h#{band}") { bands[band] }
46
- define_method("h#{band}=") { |value| bands[band] = value }
47
-
48
- define_method("l#{band}") { bands[-band] }
49
- define_method("l#{band}=") { |value| bands[-band] = value }
50
- end
51
- end
52
-
53
- class Pivot < Indicator
54
- def points_class
55
- Quant::Indicators::PivotPoint
56
- end
57
-
58
- def band?(band)
59
- p0.key?(band)
60
- end
61
-
62
- def period
63
- dc_period
64
- end
65
-
66
- def averaging_period
67
- min_period
68
- end
69
-
70
- def period_midpoints
71
- period_points(period).map(&:midpoint)
72
- end
73
-
74
- def compute
75
- compute_extents
76
- compute_value
77
- compute_midpoint
78
- compute_bands
79
- end
80
-
81
- def compute_midpoint
82
- p0.midpoint = p0.input
83
- end
84
-
85
- def compute_value
86
- # No-op -- override in subclasses
87
- end
88
-
89
- def compute_bands
90
- # No-op -- override in subclasses
91
- end
92
-
93
- def compute_extents
94
- period_midpoints.tap do |midpoints|
95
- p0.high_price = t0.high_price
96
- p0.low_price = t0.low_price
97
- p0.highest = midpoints.max
98
- p0.lowest = midpoints.min
99
- p0.range = p0.high_price - p0.low_price
100
- p0.avg_low = super_smoother(:low_price, previous: :avg_low, period: averaging_period)
101
- p0.avg_high = super_smoother(:high_price, previous: :avg_high, period: averaging_period)
102
- p0.avg_range = super_smoother(:range, previous: :avg_range, period: averaging_period)
103
- end
104
- end
105
- end
106
- end
107
- end