quantitative 0.3.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/lib/quant/asset.rb +0 -2
- data/lib/quant/dominant_cycles_source.rb +1 -32
- data/lib/quant/experimental.rb +3 -1
- data/lib/quant/indicators/adx.rb +3 -10
- data/lib/quant/indicators/atr.rb +3 -4
- data/lib/quant/indicators/cci.rb +3 -1
- data/lib/quant/indicators/decycler.rb +3 -1
- data/lib/quant/indicators/dominant_cycles/acr.rb +5 -6
- data/lib/quant/indicators/dominant_cycles/band_pass.rb +4 -4
- data/lib/quant/indicators/dominant_cycles/differential.rb +4 -2
- data/lib/quant/indicators/dominant_cycles/dominant_cycle.rb +2 -4
- data/lib/quant/indicators/dominant_cycles/half_period.rb +4 -4
- data/lib/quant/indicators/dominant_cycles/homodyne.rb +4 -5
- data/lib/quant/indicators/dominant_cycles/phase_accumulator.rb +4 -4
- data/lib/quant/indicators/ema.rb +67 -0
- data/lib/quant/indicators/frama.rb +2 -1
- data/lib/quant/indicators/indicator.rb +5 -1
- data/lib/quant/indicators/indicator_point.rb +1 -1
- data/lib/quant/indicators/mama.rb +3 -1
- data/lib/quant/indicators/mesa.rb +4 -5
- data/lib/quant/indicators/ping.rb +3 -1
- data/lib/quant/indicators/pivots/atr.rb +3 -2
- data/lib/quant/indicators/pivots/bollinger.rb +4 -2
- data/lib/quant/indicators/pivots/camarilla.rb +3 -5
- data/lib/quant/indicators/pivots/classic.rb +4 -2
- data/lib/quant/indicators/pivots/demark.rb +4 -2
- data/lib/quant/indicators/pivots/donchian.rb +3 -2
- data/lib/quant/indicators/pivots/fibbonacci.rb +4 -2
- data/lib/quant/indicators/pivots/guppy.rb +5 -3
- data/lib/quant/indicators/pivots/keltner.rb +3 -2
- data/lib/quant/indicators/pivots/murrey.rb +4 -3
- data/lib/quant/indicators/pivots/pivot.rb +109 -0
- data/lib/quant/indicators/pivots/traditional.rb +4 -2
- data/lib/quant/indicators/pivots/woodie.rb +5 -3
- data/lib/quant/indicators/rocket_rsi.rb +57 -0
- data/lib/quant/indicators/roofing.rb +59 -0
- data/lib/quant/indicators/rsi.rb +67 -0
- data/lib/quant/indicators/snr.rb +64 -0
- data/lib/quant/indicators.rb +6 -0
- data/lib/quant/indicators_registry.rb +63 -0
- data/lib/quant/indicators_source.rb +14 -10
- data/lib/quant/mixins/filters.rb +0 -3
- data/lib/quant/mixins/moving_averages.rb +0 -3
- data/lib/quant/pivots_source.rb +1 -13
- data/lib/quant/ticks/ohlc.rb +0 -2
- data/lib/quant/ticks/spot.rb +0 -2
- data/lib/quant/version.rb +1 -1
- data/lib/quantitative.rb +29 -6
- metadata +25 -5
- data/lib/quant/indicators/pivot.rb +0 -107
- data/quantitative.gemspec +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8908c3b863d42be9e0c27fcce1dc57a7b0f0b2f4699cb559140eca1caa717223
|
4
|
+
data.tar.gz: 2fda3094ef0da147ed1aef5c5aa6b3020f3de426e885562dab714ed00d3bac43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a35fa3205f447fa5b43a52c7725b3ee3fe3c576c5663e2a5cb29fb67325ca11ee4bea24e80bc93510f7d0c22c5bce706fb809a0e8b9a73bfe00a831f28e875ca
|
7
|
+
data.tar.gz: 1f31136c06beacee9276208a2e9a6bdaebd4c60930ece409b552581dea19b27e38231680ab7699e985cf1040b12d4ac0819510bc748c364051033b3bcd0e4017
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
quantitative (0.3.
|
4
|
+
quantitative (0.3.2)
|
5
5
|
oj (~> 3.10)
|
6
|
+
zeitwerk (~> 2.6)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
@@ -126,6 +127,7 @@ GEM
|
|
126
127
|
unicode-display_width (2.5.0)
|
127
128
|
vernier (0.5.1)
|
128
129
|
yard (0.9.34)
|
130
|
+
zeitwerk (2.6.15)
|
129
131
|
|
130
132
|
PLATFORMS
|
131
133
|
arm64-darwin-22
|
data/lib/quant/asset.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "asset_class"
|
4
|
-
|
5
3
|
module Quant
|
6
4
|
# A {Quant::Asset} is a representation of a financial instrument such as a stock, option, future, or currency.
|
7
5
|
# It is used to represent the instrument that is being traded, analyzed, or managed.
|
@@ -17,40 +17,9 @@ module Quant
|
|
17
17
|
class DominantCyclesSource
|
18
18
|
def initialize(indicator_source:)
|
19
19
|
@indicator_source = indicator_source
|
20
|
+
indicator_source.define_indicator_accessors(indicator_source: self)
|
20
21
|
end
|
21
22
|
|
22
|
-
# Auto-Correlation Reversals is a method of computing the dominant cycle
|
23
|
-
# by correlating the data stream with itself delayed by a lag.
|
24
|
-
def acr; indicator(Indicators::DominantCycles::Acr) end
|
25
|
-
|
26
|
-
# The band-pass dominant cycle passes signals within a certain frequency
|
27
|
-
# range, and attenuates signals outside that range.
|
28
|
-
# The trend component of the signal is removed, leaving only the cyclical
|
29
|
-
# component. Then we count number of iterations between zero crossings
|
30
|
-
# and this is the `period` of the dominant cycle.
|
31
|
-
def band_pass; indicator(Indicators::DominantCycles::BandPass) end
|
32
|
-
|
33
|
-
# The Dual Differentiator algorithm computes the phase angle from the
|
34
|
-
# analytic signal as the arctangent of the ratio of the imaginary
|
35
|
-
# component to the real component. Further, the angular frequency
|
36
|
-
# is defined as the rate change of phase. We can use these facts to
|
37
|
-
# derive the cycle period.
|
38
|
-
def differential; indicator(Indicators::DominantCycles::Differential) end
|
39
|
-
|
40
|
-
# Static, arbitrarily set period.
|
41
|
-
def half_period; indicator(Indicators::DominantCycles::HalfPeriod) end
|
42
|
-
|
43
|
-
# Homodyne means the signal is multiplied by itself. More precisely,
|
44
|
-
# we want to multiply the signal of the current bar with the complex
|
45
|
-
# value of the signal one bar ago
|
46
|
-
def homodyne; indicator(Indicators::DominantCycles::Homodyne) end
|
47
|
-
|
48
|
-
# The phase accumulation method of computing the dominant cycle measures
|
49
|
-
# the phase at each sample by taking the arctangent of the ratio of the
|
50
|
-
# quadrature component to the in-phase component. The phase is then
|
51
|
-
# accumulated and the period is derived from the phase.
|
52
|
-
def phase_accumulator; indicator(Indicators::DominantCycles::PhaseAccumulator) end
|
53
|
-
|
54
23
|
private
|
55
24
|
|
56
25
|
def indicator(indicator_class)
|
data/lib/quant/experimental.rb
CHANGED
data/lib/quant/indicators/adx.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "indicator_point"
|
4
|
-
require_relative "indicator"
|
5
|
-
require_relative "atr"
|
6
|
-
|
7
3
|
module Quant
|
8
|
-
|
4
|
+
module Indicators
|
9
5
|
class AdxPoint < IndicatorPoint
|
10
6
|
attribute :dmu, default: 0.0
|
11
7
|
attribute :dmd, default: 0.0
|
@@ -25,12 +21,9 @@ module Quant
|
|
25
21
|
end
|
26
22
|
|
27
23
|
class Adx < Indicator
|
24
|
+
register name: :adx
|
28
25
|
depends_on Indicators::Atr
|
29
26
|
|
30
|
-
def alpha
|
31
|
-
bars_to_alpha(dc_period)
|
32
|
-
end
|
33
|
-
|
34
27
|
def scale
|
35
28
|
1.0
|
36
29
|
end
|
@@ -75,7 +68,7 @@ module Quant
|
|
75
68
|
p0.di_ema = three_pole_super_smooth(:di, period:, previous: :di_ema).clamp(-10.0, 10.0)
|
76
69
|
|
77
70
|
p0.value = p0.di_ema
|
78
|
-
p0.inst_stoch = stochastic
|
71
|
+
p0.inst_stoch = stochastic(:di, period:)
|
79
72
|
p0.stoch = three_pole_super_smooth :inst_stoch, period:, previous: :stoch
|
80
73
|
end
|
81
74
|
end
|
data/lib/quant/indicators/atr.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "indicator_point"
|
4
|
-
require_relative "indicator"
|
5
|
-
|
6
3
|
module Quant
|
7
|
-
|
4
|
+
module Indicators
|
8
5
|
class AtrPoint < IndicatorPoint
|
9
6
|
attribute :tr, default: 0.0
|
10
7
|
attribute :period, default: :min_period
|
@@ -28,6 +25,8 @@ module Quant
|
|
28
25
|
end
|
29
26
|
|
30
27
|
class Atr < Indicator
|
28
|
+
register name: :atr
|
29
|
+
|
31
30
|
attr_reader :points
|
32
31
|
|
33
32
|
def period
|
data/lib/quant/indicators/cci.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Quant
|
4
|
-
|
4
|
+
module Indicators
|
5
5
|
class CciPoint < IndicatorPoint
|
6
6
|
attribute :hp, default: 0.0
|
7
7
|
attribute :real, default: 0.0
|
@@ -18,6 +18,8 @@ module Quant
|
|
18
18
|
#
|
19
19
|
# SOURCE: https://www.mesasoftware.com/papers/CORRELATION%20AS%20A%20CYCLE%20INDICATOR.pdf
|
20
20
|
class Cci < Indicator
|
21
|
+
register name: :cci
|
22
|
+
|
21
23
|
def max_period
|
22
24
|
[min_period, dc_period].max
|
23
25
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Quant
|
4
|
-
|
4
|
+
module Indicators
|
5
5
|
# The decycler oscillator can be useful for determining the transition be- tween uptrends and downtrends by the crossing of the zero
|
6
6
|
# line. Alternatively, the changes of slope of the decycler oscillator are easier to identify than the changes in slope of the
|
7
7
|
# original decycler. Optimum cutoff periods can easily be found by experimentation.
|
@@ -24,6 +24,8 @@ module Quant
|
|
24
24
|
end
|
25
25
|
|
26
26
|
class Decycler < Indicator
|
27
|
+
register name: :decycler
|
28
|
+
|
27
29
|
def max_period
|
28
30
|
dc_period
|
29
31
|
end
|
@@ -1,12 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../indicator_point"
|
4
|
-
require_relative "dominant_cycle"
|
5
|
-
|
6
3
|
module Quant
|
7
|
-
|
8
|
-
|
9
|
-
class AcrPoint <
|
4
|
+
module Indicators
|
5
|
+
module DominantCycles
|
6
|
+
class AcrPoint < Quant::Indicators::IndicatorPoint
|
10
7
|
attribute :hp, default: 0.0
|
11
8
|
attribute :filter, default: 0.0
|
12
9
|
attribute :interim_period, default: 0.0
|
@@ -31,6 +28,8 @@ module Quant
|
|
31
28
|
# The cyclic information is extracted using a discrete Fourier transform
|
32
29
|
# (DFT) of the autocorrelation results.
|
33
30
|
class Acr < DominantCycle
|
31
|
+
register name: :acr
|
32
|
+
|
34
33
|
BANDWIDTH_DEGREES = 370
|
35
34
|
BANDWIDTH_RADIANS = BANDWIDTH_DEGREES * Math::PI / 180.0
|
36
35
|
|
@@ -1,10 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "dominant_cycle"
|
4
|
-
|
5
3
|
module Quant
|
6
|
-
|
7
|
-
|
4
|
+
module Indicators
|
5
|
+
module DominantCycles
|
8
6
|
class BandPassPoint < Quant::Indicators::IndicatorPoint
|
9
7
|
attribute :hp, default: 0.0
|
10
8
|
attribute :bp, default: 0.0
|
@@ -22,6 +20,8 @@ module Quant
|
|
22
20
|
# component. Then we count number of iterations between zero crossings
|
23
21
|
# and this is the `period` of the dominant cycle.
|
24
22
|
class BandPass < DominantCycle
|
23
|
+
register name: :band_pass
|
24
|
+
|
25
25
|
def bandwidth
|
26
26
|
0.75
|
27
27
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Quant
|
4
|
-
|
5
|
-
|
4
|
+
module Indicators
|
5
|
+
module DominantCycles
|
6
6
|
# The Dual Differentiator algorithm computes the phase angle from the
|
7
7
|
# analytic signal as the arctangent of the ratio of the imaginary
|
8
8
|
# component to the real component. Further, the angular frequency
|
9
9
|
# is defined as the rate change of phase. We can use these facts to
|
10
10
|
# derive the cycle period.
|
11
11
|
class Differential < DominantCycle
|
12
|
+
register name: :differential
|
13
|
+
|
12
14
|
def compute_period
|
13
15
|
p0.ddd = (p0.q2 * (p0.i2 - p1.i2)) - (p0.i2 * (p0.q2 - p1.q2))
|
14
16
|
p0.inst_period = p0.ddd > 0.01 ? 6.2832 * (p0.i2**2 + p0.q2**2) / p0.ddd : 0.0
|
@@ -1,9 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../indicator"
|
4
|
-
|
5
3
|
module Quant
|
6
|
-
|
4
|
+
module Indicators
|
7
5
|
# Dominant Cycles measure the primary cycle within a given range. By default, the library
|
8
6
|
# is wired to look for cycles between 10 and 48 bars. These values can be adjusted by setting
|
9
7
|
# the `min_period` and `max_period` configuration values in {Quant::Config}.
|
@@ -18,7 +16,7 @@ module Quant
|
|
18
16
|
# The purpose of these indicators is to compute the dominant cycle and underpin the various
|
19
17
|
# indicators that would otherwise be setting an arbitrary lookback period. This makes the
|
20
18
|
# indicators adaptive and auto-tuning to the market dynamics. Or so the theory goes!
|
21
|
-
|
19
|
+
module DominantCycles
|
22
20
|
class DominantCyclePoint < Quant::Indicators::IndicatorPoint
|
23
21
|
attribute :smooth, default: 0.0
|
24
22
|
attribute :detrend, default: 0.0
|
@@ -1,10 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "dominant_cycle"
|
4
|
-
|
5
3
|
module Quant
|
6
|
-
|
7
|
-
|
4
|
+
module Indicators
|
5
|
+
module DominantCycles
|
8
6
|
# This dominant cycle indicator is based on the half period
|
9
7
|
# that is the midpoint of the `min_period` and `max_period`
|
10
8
|
# configured in the `Quant.config.indicators` object.
|
@@ -14,6 +12,8 @@ module Quant
|
|
14
12
|
end
|
15
13
|
|
16
14
|
class HalfPeriod < DominantCycle
|
15
|
+
register name: :half_period
|
16
|
+
|
17
17
|
def compute
|
18
18
|
# No-Op
|
19
19
|
end
|
@@ -1,15 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../indicator_point"
|
4
|
-
require_relative "dominant_cycle"
|
5
|
-
|
6
3
|
module Quant
|
7
|
-
|
8
|
-
|
4
|
+
module Indicators
|
5
|
+
module DominantCycles
|
9
6
|
# Homodyne means the signal is multiplied by itself. More precisely,
|
10
7
|
# we want to multiply the signal of the current bar with the complex
|
11
8
|
# value of the signal one bar ago
|
12
9
|
class Homodyne < DominantCycle
|
10
|
+
register name: :homodyne
|
11
|
+
|
13
12
|
def compute_period
|
14
13
|
p0.re = (p0.i2 * p1.i2) + (p0.q2 * p1.q2)
|
15
14
|
p0.im = (p0.i2 * p1.q2) - (p0.q2 * p1.i2)
|
@@ -1,10 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "dominant_cycle"
|
4
|
-
|
5
3
|
module Quant
|
6
|
-
|
7
|
-
|
4
|
+
module Indicators
|
5
|
+
module DominantCycles
|
8
6
|
# The phase accumulation method of computing the dominant cycle is perhaps
|
9
7
|
# the easiest to comprehend. In this technique, we measure the phase
|
10
8
|
# at each sample by taking the arctangent of the ratio of the quadrature
|
@@ -26,6 +24,8 @@ module Quant
|
|
26
24
|
# Therefore, shorter cycle periods necessarily have a higher output
|
27
25
|
# signal-to-noise ratio.
|
28
26
|
class PhaseAccumulator < DominantCycle
|
27
|
+
register name: :phase_accumulator
|
28
|
+
|
29
29
|
def compute_period
|
30
30
|
p0.i1 = 0.15 * p0.i1 + 0.85 * p1.i1
|
31
31
|
p0.q1 = 0.15 * p0.q1 + 0.85 * p1.q1
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Quant
|
2
|
+
module Indicators
|
3
|
+
class EmaPoint < IndicatorPoint
|
4
|
+
attribute :ss_dc_period, default: :input
|
5
|
+
attribute :ss_half_dc_period, default: :input
|
6
|
+
attribute :ss_micro_period, default: :input
|
7
|
+
attribute :ss_min_period, default: :input
|
8
|
+
attribute :ss_half_period, default: :input
|
9
|
+
attribute :ss_max_period, default: :input
|
10
|
+
|
11
|
+
attribute :ema_dc_period, default: :input
|
12
|
+
attribute :ema_half_dc_period, default: :input
|
13
|
+
attribute :ema_micro_period, default: :input
|
14
|
+
attribute :ema_min_period, default: :input
|
15
|
+
attribute :ema_half_period, default: :input
|
16
|
+
attribute :ema_max_period, default: :input
|
17
|
+
|
18
|
+
attribute :osc_dc_period, default: 0.0
|
19
|
+
attribute :osc_half_dc_period, default: 0.0
|
20
|
+
attribute :osc_micro_period, default: 0.0
|
21
|
+
attribute :osc_min_period, default: 0.0
|
22
|
+
attribute :osc_half_period, default: 0.0
|
23
|
+
attribute :osc_max_period, default: 0.0
|
24
|
+
end
|
25
|
+
|
26
|
+
class Ema < Indicator
|
27
|
+
register name: :ema
|
28
|
+
|
29
|
+
def half_dc_period
|
30
|
+
dc_period / 2
|
31
|
+
end
|
32
|
+
|
33
|
+
def compute_super_smoothers
|
34
|
+
p0.ss_dc_period = super_smoother :input, previous: :ss_dc_period, period: dc_period
|
35
|
+
p0.ss_half_dc_period = super_smoother :input, previous: :ss_half_dc_period, period: half_dc_period
|
36
|
+
p0.ss_micro_period = super_smoother :input, previous: :ss_micro_period, period: micro_period
|
37
|
+
p0.ss_min_period = super_smoother :input, previous: :ss_min_period, period: min_period
|
38
|
+
p0.ss_half_period = super_smoother :input, previous: :ss_half_period, period: half_period
|
39
|
+
p0.ss_max_period = super_smoother :input, previous: :ss_max_period, period: max_period
|
40
|
+
end
|
41
|
+
|
42
|
+
def compute_emas
|
43
|
+
p0.ema_dc_period = ema :input, previous: :ema_dc_period, period: dc_period
|
44
|
+
p0.ema_half_dc_period = ema :input, previous: :ema_half_dc_period, period: half_dc_period
|
45
|
+
p0.ema_micro_period = ema :input, previous: :ema_micro_period, period: micro_period
|
46
|
+
p0.ema_min_period = ema :input, previous: :ema_min_period, period: min_period
|
47
|
+
p0.ema_half_period = ema :input, previous: :ema_half_period, period: half_period
|
48
|
+
p0.ema_max_period = ema :input, previous: :ema_max_period, period: max_period
|
49
|
+
end
|
50
|
+
|
51
|
+
def compute_oscillators
|
52
|
+
p0.osc_dc_period = p0.ss_dc_period - p0.ema_dc_period
|
53
|
+
p0.osc_half_dc_period = p0.ss_half_dc_period - p0.ema_half_dc_period
|
54
|
+
p0.osc_micro_period = p0.ss_micro_period - p0.ema_micro_period
|
55
|
+
p0.osc_min_period = p0.ss_min_period - p0.ema_min_period
|
56
|
+
p0.osc_half_period = p0.ss_half_period - p0.ema_half_period
|
57
|
+
p0.osc_max_period = p0.ss_max_period - p0.ema_max_period
|
58
|
+
end
|
59
|
+
|
60
|
+
def compute
|
61
|
+
compute_super_smoothers
|
62
|
+
compute_emas
|
63
|
+
compute_oscillators
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Quant
|
4
|
-
|
4
|
+
module Indicators
|
5
5
|
class FramaPoint < IndicatorPoint
|
6
6
|
attribute :frama, default: :input
|
7
7
|
attribute :dimension, default: 0.0
|
@@ -15,6 +15,7 @@ module Quant
|
|
15
15
|
#
|
16
16
|
# SOURCE: http://www.mesasoftware.com/papers/FRAMA.pdf
|
17
17
|
class Frama < Indicator
|
18
|
+
register name: :frama
|
18
19
|
using Quant
|
19
20
|
|
20
21
|
# The max_period is divided into two smaller, equal periods, so must be even
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Quant
|
4
|
-
|
4
|
+
module Indicators
|
5
5
|
# The {Quant::Indicators::Indicator} class is the abstract ancestor for all Indicators.
|
6
6
|
#
|
7
7
|
class Indicator
|
@@ -15,6 +15,10 @@ module Quant
|
|
15
15
|
include Mixins::FisherTransform
|
16
16
|
# include Mixins::Direction
|
17
17
|
|
18
|
+
def self.register(name:)
|
19
|
+
Quant::IndicatorsSource.register(name:, indicator_class: self)
|
20
|
+
end
|
21
|
+
|
18
22
|
# Provides a registry of dependent indicators for each indicator class.
|
19
23
|
# NOTE: Internal use only.
|
20
24
|
def self.dependent_indicator_classes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Quant
|
4
|
-
|
4
|
+
module Indicators
|
5
5
|
class MamaPoint < IndicatorPoint
|
6
6
|
attribute :smooth, default: 0.0
|
7
7
|
attribute :detrend, default: 0.0
|
@@ -46,6 +46,8 @@ module Quant
|
|
46
46
|
# dominant cycle indicator other than the homodyne for the rest
|
47
47
|
# of your indicators.
|
48
48
|
class Mama < Indicator
|
49
|
+
register name: :mama
|
50
|
+
|
49
51
|
# constrain between 6 and 50 bars
|
50
52
|
def constrain_period_bars
|
51
53
|
p0.period = p0.period.clamp(min_period, max_period)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Quant
|
4
|
-
|
4
|
+
module Indicators
|
5
5
|
# The MESA inidicator
|
6
6
|
class MesaPoint < IndicatorPoint
|
7
7
|
attribute :mama, default: :input
|
@@ -33,12 +33,11 @@ module Quant
|
|
33
33
|
# indicators for the dominant cycle, then this version is useful
|
34
34
|
# as it avoids extra computational steps.
|
35
35
|
class Mesa < Indicator
|
36
|
-
|
37
|
-
|
38
|
-
end
|
36
|
+
register name: :mesa
|
37
|
+
depends_on DominantCycles::Homodyne
|
39
38
|
|
40
39
|
def fast_limit
|
41
|
-
@fast_limit ||= bars_to_alpha(
|
40
|
+
@fast_limit ||= bars_to_alpha(micro_period)
|
42
41
|
end
|
43
42
|
|
44
43
|
def slow_limit
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Quant
|
4
|
-
|
4
|
+
module Indicators
|
5
5
|
# A simple point used primarily to test the indicator system in unit tests.
|
6
6
|
# It has a simple computation that just sets the pong value to the input value
|
7
7
|
# and increments the compute_count by 1 each time compute is called.
|
@@ -13,6 +13,8 @@ module Quant
|
|
13
13
|
|
14
14
|
# A simple idicator used primarily to test the indicator system
|
15
15
|
class Ping < Indicator
|
16
|
+
register name: :ping
|
17
|
+
|
16
18
|
def compute
|
17
19
|
p0.pong = input
|
18
20
|
p0.compute_count += 1
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Quant
|
4
|
-
|
5
|
-
|
4
|
+
module Indicators
|
5
|
+
module Pivots
|
6
6
|
# Camarilla pivot point calculations are rather straightforward. We need to
|
7
7
|
# input the previous day’s open, high, low and close. The formulas for each
|
8
8
|
# resistance and support level are:
|
@@ -27,9 +27,7 @@ module Quant
|
|
27
27
|
# S5 = S4 – 1.168 * (S3 – S4)
|
28
28
|
# S6 = Close – (R6 – Close)
|
29
29
|
class Camarilla < Pivot
|
30
|
-
|
31
|
-
1.1
|
32
|
-
end
|
30
|
+
register name: :camarilla
|
33
31
|
|
34
32
|
def compute_midpoint
|
35
33
|
p0.midpoint = t0.close_price
|
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Quant
|
4
|
-
|
5
|
-
|
4
|
+
module Indicators
|
5
|
+
module Pivots
|
6
6
|
class Classic < Pivot
|
7
|
+
register name: :classic
|
8
|
+
|
7
9
|
def compute_midpoint
|
8
10
|
p0.midpoint = super_smoother :input, previous: :midpoint, period: averaging_period
|
9
11
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Quant
|
4
|
-
|
5
|
-
|
4
|
+
module Indicators
|
5
|
+
module Pivots
|
6
6
|
# The value of X in the formula below depends on where the Close of the market is.
|
7
7
|
# If Close = Open then X = (H + L + (C * 2))
|
8
8
|
|
@@ -14,6 +14,8 @@ module Quant
|
|
14
14
|
# PP = X / 4 (this is not an official DeMark number but merely a reference point based on the calculation of X)
|
15
15
|
# S1 = X / 2 - H
|
16
16
|
class Demark < Pivot
|
17
|
+
register name: :demark
|
18
|
+
|
17
19
|
def averaging_period
|
18
20
|
min_period / 2
|
19
21
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module Quant
|
2
|
-
|
3
|
-
|
2
|
+
module Indicators
|
3
|
+
module Pivots
|
4
4
|
class Guppy < Pivot
|
5
|
+
register name: :guppy
|
6
|
+
|
5
7
|
def guppy_ema(period, band)
|
6
8
|
return p0.input unless p1[band]
|
7
9
|
|
@@ -15,7 +17,7 @@ module Quant
|
|
15
17
|
|
16
18
|
# The short-term MAs are typically set at 3, 5, 8, 10, 12, and 15 periods. The
|
17
19
|
# longer-term MAs are typically set at 30, 35, 40, 45, 50, and 60.
|
18
|
-
def
|
20
|
+
def compute_bands
|
19
21
|
p0[1] = guppy_ema(5, 1)
|
20
22
|
p0[2] = guppy_ema(8, 2)
|
21
23
|
p0[3] = guppy_ema(10, 3)
|