Class: Quant::Indicators::Indicator
Constant Summary
Mixins::UniversalFilters::K
Instance Attribute Summary collapse
Instance Method Summary
collapse
#fisher_transform, #inverse_fisher_transform, #relative_fisher_transform
#stochastic
#three_pole_super_smooth, #two_pole_super_smooth
#hilbert_transform
#exponential_moving_average
#simple_moving_average
#extended_weighted_moving_average, #weighted_moving_average
#universal_band_pass, #universal_ema, #universal_filter, #universal_one_pole_high_pass, #universal_one_pole_low_pass, #universal_two_pole_high_pass, #universal_two_pole_low_pass
#three_pole_butterworth, #two_pole_butterworth
#high_pass_filter, #hpf2, #two_pole_high_pass_filter
#angle, #bars_to_alpha, #deg2rad, #period_to_alpha, #rad2deg
Constructor Details
#initialize(series:, source:) ⇒ Indicator
Returns a new instance of Indicator.
18
19
20
21
22
23
24
|
# File 'lib/quant/indicators/indicator.rb', line 18
def initialize(series:, source:)
@series = series
@source = source
@points = {}
series.new_indicator(self)
series.each { |tick| self << tick }
end
|
Instance Attribute Details
#p0 ⇒ Object
Returns the value of attribute p0.
74
75
76
|
# File 'lib/quant/indicators/indicator.rb', line 74
def p0
@p0
end
|
#p1 ⇒ Object
Returns the value of attribute p1.
74
75
76
|
# File 'lib/quant/indicators/indicator.rb', line 74
def p1
@p1
end
|
#p2 ⇒ Object
Returns the value of attribute p2.
74
75
76
|
# File 'lib/quant/indicators/indicator.rb', line 74
def p2
@p2
end
|
#p3 ⇒ Object
Returns the value of attribute p3.
74
75
76
|
# File 'lib/quant/indicators/indicator.rb', line 74
def p3
@p3
end
|
#series ⇒ Object
include Mixins::Direction
16
17
18
|
# File 'lib/quant/indicators/indicator.rb', line 16
def series
@series
end
|
#source ⇒ Object
include Mixins::Direction
16
17
18
|
# File 'lib/quant/indicators/indicator.rb', line 16
def source
@source
end
|
#t0 ⇒ Object
Returns the value of attribute t0.
75
76
77
|
# File 'lib/quant/indicators/indicator.rb', line 75
def t0
@t0
end
|
#t1 ⇒ Object
Returns the value of attribute t1.
75
76
77
|
# File 'lib/quant/indicators/indicator.rb', line 75
def t1
@t1
end
|
#t2 ⇒ Object
Returns the value of attribute t2.
75
76
77
|
# File 'lib/quant/indicators/indicator.rb', line 75
def t2
@t2
end
|
#t3 ⇒ Object
Returns the value of attribute t3.
75
76
77
|
# File 'lib/quant/indicators/indicator.rb', line 75
def t3
@t3
end
|
Instance Method Details
#<<(tick) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/quant/indicators/indicator.rb', line 77
def <<(tick)
@t0 = tick
@p0 = points_class.new(indicator: self, tick:, source:)
@points[tick] = @p0
@p1 = values[-2] || @p0
@p2 = values[-3] || @p1
@p3 = values[-4] || @p2
@t1 = ticks[-2] || @t0
@t2 = ticks[-3] || @t1
@t3 = ticks[-4] || @t2
compute
end
|
#[](index) ⇒ Object
62
63
64
|
# File 'lib/quant/indicators/indicator.rb', line 62
def [](index)
values[index]
end
|
#compute ⇒ Object
101
102
103
|
# File 'lib/quant/indicators/indicator.rb', line 101
def compute
raise NotImplementedError
end
|
#dc_period ⇒ Object
54
55
56
|
# File 'lib/quant/indicators/indicator.rb', line 54
def dc_period
dominant_cycle.points[t0].period
end
|
#dominant_cycle ⇒ Object
50
51
52
|
# File 'lib/quant/indicators/indicator.rb', line 50
def dominant_cycle
series.indicators[source].dominant_cycle
end
|
#dominant_cycle_kind ⇒ Object
42
43
44
|
# File 'lib/quant/indicators/indicator.rb', line 42
def dominant_cycle_kind
Quant.config.indicators.dominant_cycle_kind
end
|
#each(&block) ⇒ Object
93
94
95
|
# File 'lib/quant/indicators/indicator.rb', line 93
def each(&block)
@points.each_value(&block)
end
|
#half_period ⇒ Object
34
35
36
|
# File 'lib/quant/indicators/indicator.rb', line 34
def half_period
Quant.config.indicators.half_period
end
|
#indicator_name ⇒ Object
105
106
107
|
# File 'lib/quant/indicators/indicator.rb', line 105
def indicator_name
self.class.name.split("::").last
end
|
The input is the value derived from the source for the indicator for the current tick. For example, if the source is :oc2, then the input is the value of the current tick’s (open + close) / 2
140
141
142
|
# File 'lib/quant/indicators/indicator.rb', line 140
def input
t0.send(source)
end
|
#inspect ⇒ Object
97
98
99
|
# File 'lib/quant/indicators/indicator.rb', line 97
def inspect
"#<#{self.class.name} symbol=#{series.symbol} source=#{source} ticks=#{ticks.size}>"
end
|
#max_period ⇒ Object
30
31
32
|
# File 'lib/quant/indicators/indicator.rb', line 30
def max_period
Quant.config.indicators.max_period
end
|
#micro_period ⇒ Object
38
39
40
|
# File 'lib/quant/indicators/indicator.rb', line 38
def micro_period
Quant.config.indicators.micro_period
end
|
#min_period ⇒ Object
26
27
28
|
# File 'lib/quant/indicators/indicator.rb', line 26
def min_period
Quant.config.indicators.min_period
end
|
#p(offset) ⇒ Object
117
118
119
120
121
122
|
# File 'lib/quant/indicators/indicator.rb', line 117
def p(offset)
raise ArgumentError, "offset must be a positive value" if offset < 0
index = offset + 1
values[[-index, -size].max]
end
|
#pivot_kind ⇒ Object
46
47
48
|
# File 'lib/quant/indicators/indicator.rb', line 46
def pivot_kind
Quant.config.indicators.pivot_kind
end
|
#points_class ⇒ Object
109
110
111
|
# File 'lib/quant/indicators/indicator.rb', line 109
def points_class
Object.const_get "Quant::Indicators::#{indicator_name}Point"
end
|
#size ⇒ Object
70
71
72
|
# File 'lib/quant/indicators/indicator.rb', line 70
def size
@points.size
end
|
#t(offset) ⇒ Object
128
129
130
131
132
133
|
# File 'lib/quant/indicators/indicator.rb', line 128
def t(offset)
raise ArgumentError, "offset must be a positive value" if offset < 0
index = offset + 1
ticks[[-index, -size].max]
end
|
#ticks ⇒ Object
58
59
60
|
# File 'lib/quant/indicators/indicator.rb', line 58
def ticks
@points.keys
end
|
#values ⇒ Object
66
67
68
|
# File 'lib/quant/indicators/indicator.rb', line 66
def values
@points.values
end
|