sqa-tai 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/sqa/tai/cycle_indicators.rb +72 -0
- data/lib/sqa/tai/momentum_indicators.rb +517 -0
- data/lib/sqa/tai/overlap_studies.rb +144 -0
- data/lib/sqa/tai/pattern_recognition.rb +684 -0
- data/lib/sqa/tai/price_transform.rb +64 -0
- data/lib/sqa/tai/statistical_functions.rb +122 -0
- data/lib/sqa/tai/version.rb +1 -1
- data/lib/sqa/tai/volatility_indicators.rb +179 -0
- data/lib/sqa/tai/volume_indicators.rb +54 -0
- data/lib/sqa/tai.rb +20 -1804
- data/mkdocs.yml +7 -10
- metadata +9 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SQA
|
|
4
|
+
module TAI
|
|
5
|
+
# Price Transform
|
|
6
|
+
module PriceTransform
|
|
7
|
+
# Average Price
|
|
8
|
+
# @param open [Array<Float>] Open prices
|
|
9
|
+
# @param high [Array<Float>] High prices
|
|
10
|
+
# @param low [Array<Float>] Low prices
|
|
11
|
+
# @param close [Array<Float>] Close prices
|
|
12
|
+
# @return [Array<Float>] Average price values
|
|
13
|
+
def avgprice(open, high, low, close)
|
|
14
|
+
check_available!
|
|
15
|
+
validate_prices!(open)
|
|
16
|
+
validate_prices!(high)
|
|
17
|
+
validate_prices!(low)
|
|
18
|
+
validate_prices!(close)
|
|
19
|
+
|
|
20
|
+
TALibFFI.avgprice(open, high, low, close)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Median Price
|
|
24
|
+
# @param high [Array<Float>] High prices
|
|
25
|
+
# @param low [Array<Float>] Low prices
|
|
26
|
+
# @return [Array<Float>] Median price values
|
|
27
|
+
def medprice(high, low)
|
|
28
|
+
check_available!
|
|
29
|
+
validate_prices!(high)
|
|
30
|
+
validate_prices!(low)
|
|
31
|
+
|
|
32
|
+
TALibFFI.medprice(high, low)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Typical Price
|
|
36
|
+
# @param high [Array<Float>] High prices
|
|
37
|
+
# @param low [Array<Float>] Low prices
|
|
38
|
+
# @param close [Array<Float>] Close prices
|
|
39
|
+
# @return [Array<Float>] Typical price values
|
|
40
|
+
def typprice(high, low, close)
|
|
41
|
+
check_available!
|
|
42
|
+
validate_prices!(high)
|
|
43
|
+
validate_prices!(low)
|
|
44
|
+
validate_prices!(close)
|
|
45
|
+
|
|
46
|
+
TALibFFI.typprice(high, low, close)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Weighted Close Price
|
|
50
|
+
# @param high [Array<Float>] High prices
|
|
51
|
+
# @param low [Array<Float>] Low prices
|
|
52
|
+
# @param close [Array<Float>] Close prices
|
|
53
|
+
# @return [Array<Float>] Weighted close price values
|
|
54
|
+
def wclprice(high, low, close)
|
|
55
|
+
check_available!
|
|
56
|
+
validate_prices!(high)
|
|
57
|
+
validate_prices!(low)
|
|
58
|
+
validate_prices!(close)
|
|
59
|
+
|
|
60
|
+
TALibFFI.wclprice(high, low, close)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SQA
|
|
4
|
+
module TAI
|
|
5
|
+
# Statistical Functions
|
|
6
|
+
module StatisticalFunctions
|
|
7
|
+
# Pearson's Correlation Coefficient
|
|
8
|
+
# @param prices1 [Array<Float>] First array of prices
|
|
9
|
+
# @param prices2 [Array<Float>] Second array of prices
|
|
10
|
+
# @param period [Integer] Time period (default: 30)
|
|
11
|
+
# @return [Array<Float>] Correlation values
|
|
12
|
+
def correl(prices1, prices2, period: 30)
|
|
13
|
+
check_available!
|
|
14
|
+
validate_prices!(prices1)
|
|
15
|
+
validate_prices!(prices2)
|
|
16
|
+
validate_period!(period, [prices1.size, prices2.size].min)
|
|
17
|
+
|
|
18
|
+
TALibFFI.correl(prices1, prices2, time_period: period)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Beta
|
|
22
|
+
# @param prices1 [Array<Float>] First array of prices
|
|
23
|
+
# @param prices2 [Array<Float>] Second array of prices
|
|
24
|
+
# @param period [Integer] Time period (default: 5)
|
|
25
|
+
# @return [Array<Float>] Beta values
|
|
26
|
+
def beta(prices1, prices2, period: 5)
|
|
27
|
+
check_available!
|
|
28
|
+
validate_prices!(prices1)
|
|
29
|
+
validate_prices!(prices2)
|
|
30
|
+
validate_period!(period, [prices1.size, prices2.size].min)
|
|
31
|
+
|
|
32
|
+
TALibFFI.beta(prices1, prices2, time_period: period)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Variance
|
|
36
|
+
# @param prices [Array<Float>] Array of prices
|
|
37
|
+
# @param period [Integer] Time period (default: 5)
|
|
38
|
+
# @param nbdev [Float] Number of deviations (default: 1.0)
|
|
39
|
+
# @return [Array<Float>] Variance values
|
|
40
|
+
def var(prices, period: 5, nbdev: 1.0)
|
|
41
|
+
check_available!
|
|
42
|
+
validate_prices!(prices)
|
|
43
|
+
validate_period!(period, prices.size)
|
|
44
|
+
|
|
45
|
+
TALibFFI.var(prices, time_period: period, nbdev: nbdev)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Standard Deviation
|
|
49
|
+
# @param prices [Array<Float>] Array of prices
|
|
50
|
+
# @param period [Integer] Time period (default: 5)
|
|
51
|
+
# @param nbdev [Float] Number of deviations (default: 1.0)
|
|
52
|
+
# @return [Array<Float>] Standard deviation values
|
|
53
|
+
def stddev(prices, period: 5, nbdev: 1.0)
|
|
54
|
+
check_available!
|
|
55
|
+
validate_prices!(prices)
|
|
56
|
+
validate_period!(period, prices.size)
|
|
57
|
+
|
|
58
|
+
TALibFFI.stddev(prices, time_period: period, nbdev: nbdev)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Linear Regression
|
|
62
|
+
# @param prices [Array<Float>] Array of prices
|
|
63
|
+
# @param period [Integer] Time period (default: 14)
|
|
64
|
+
# @return [Array<Float>] Linear regression values
|
|
65
|
+
def linearreg(prices, period: 14)
|
|
66
|
+
check_available!
|
|
67
|
+
validate_prices!(prices)
|
|
68
|
+
validate_period!(period, prices.size)
|
|
69
|
+
|
|
70
|
+
TALibFFI.linearreg(prices, time_period: period)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Linear Regression Angle
|
|
74
|
+
# @param prices [Array<Float>] Array of prices
|
|
75
|
+
# @param period [Integer] Time period (default: 14)
|
|
76
|
+
# @return [Array<Float>] Linear regression angle values
|
|
77
|
+
def linearreg_angle(prices, period: 14)
|
|
78
|
+
check_available!
|
|
79
|
+
validate_prices!(prices)
|
|
80
|
+
validate_period!(period, prices.size)
|
|
81
|
+
|
|
82
|
+
TALibFFI.linearreg_angle(prices, time_period: period)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Linear Regression Intercept
|
|
86
|
+
# @param prices [Array<Float>] Array of prices
|
|
87
|
+
# @param period [Integer] Time period (default: 14)
|
|
88
|
+
# @return [Array<Float>] Linear regression intercept values
|
|
89
|
+
def linearreg_intercept(prices, period: 14)
|
|
90
|
+
check_available!
|
|
91
|
+
validate_prices!(prices)
|
|
92
|
+
validate_period!(period, prices.size)
|
|
93
|
+
|
|
94
|
+
TALibFFI.linearreg_intercept(prices, time_period: period)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Linear Regression Slope
|
|
98
|
+
# @param prices [Array<Float>] Array of prices
|
|
99
|
+
# @param period [Integer] Time period (default: 14)
|
|
100
|
+
# @return [Array<Float>] Linear regression slope values
|
|
101
|
+
def linearreg_slope(prices, period: 14)
|
|
102
|
+
check_available!
|
|
103
|
+
validate_prices!(prices)
|
|
104
|
+
validate_period!(period, prices.size)
|
|
105
|
+
|
|
106
|
+
TALibFFI.linearreg_slope(prices, time_period: period)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Time Series Forecast
|
|
110
|
+
# @param prices [Array<Float>] Array of prices
|
|
111
|
+
# @param period [Integer] Time period (default: 14)
|
|
112
|
+
# @return [Array<Float>] Time series forecast values
|
|
113
|
+
def tsf(prices, period: 14)
|
|
114
|
+
check_available!
|
|
115
|
+
validate_prices!(prices)
|
|
116
|
+
validate_period!(period, prices.size)
|
|
117
|
+
|
|
118
|
+
TALibFFI.tsf(prices, time_period: period)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
data/lib/sqa/tai/version.rb
CHANGED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SQA
|
|
4
|
+
module TAI
|
|
5
|
+
# Volatility Indicators
|
|
6
|
+
module VolatilityIndicators
|
|
7
|
+
# Average True Range
|
|
8
|
+
# @param high [Array<Float>] High prices
|
|
9
|
+
# @param low [Array<Float>] Low prices
|
|
10
|
+
# @param close [Array<Float>] Close prices
|
|
11
|
+
# @param period [Integer] Time period (default: 14)
|
|
12
|
+
# @return [Array<Float>] ATR values
|
|
13
|
+
def atr(high, low, close, period: 14)
|
|
14
|
+
check_available!
|
|
15
|
+
validate_prices!(high)
|
|
16
|
+
validate_prices!(low)
|
|
17
|
+
validate_prices!(close)
|
|
18
|
+
|
|
19
|
+
TALibFFI.atr(high, low, close, time_period: period)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# True Range
|
|
23
|
+
# @param high [Array<Float>] High prices
|
|
24
|
+
# @param low [Array<Float>] Low prices
|
|
25
|
+
# @param close [Array<Float>] Close prices
|
|
26
|
+
# @return [Array<Float>] True Range values
|
|
27
|
+
def trange(high, low, close)
|
|
28
|
+
check_available!
|
|
29
|
+
validate_prices!(high)
|
|
30
|
+
validate_prices!(low)
|
|
31
|
+
validate_prices!(close)
|
|
32
|
+
|
|
33
|
+
TALibFFI.trange(high, low, close)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Normalized Average True Range
|
|
37
|
+
# @param high [Array<Float>] High prices
|
|
38
|
+
# @param low [Array<Float>] Low prices
|
|
39
|
+
# @param close [Array<Float>] Close prices
|
|
40
|
+
# @param period [Integer] Time period (default: 14)
|
|
41
|
+
# @return [Array<Float>] NATR values
|
|
42
|
+
def natr(high, low, close, period: 14)
|
|
43
|
+
check_available!
|
|
44
|
+
validate_prices!(high)
|
|
45
|
+
validate_prices!(low)
|
|
46
|
+
validate_prices!(close)
|
|
47
|
+
|
|
48
|
+
TALibFFI.natr(high, low, close, time_period: period)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Parabolic SAR
|
|
52
|
+
# @param high [Array<Float>] High prices
|
|
53
|
+
# @param low [Array<Float>] Low prices
|
|
54
|
+
# @param acceleration [Float] Acceleration factor (default: 0.02)
|
|
55
|
+
# @param maximum [Float] Maximum acceleration (default: 0.20)
|
|
56
|
+
# @return [Array<Float>] SAR values
|
|
57
|
+
def sar(high, low, acceleration: 0.02, maximum: 0.20)
|
|
58
|
+
check_available!
|
|
59
|
+
validate_prices!(high)
|
|
60
|
+
validate_prices!(low)
|
|
61
|
+
|
|
62
|
+
TALibFFI.sar(high, low, acceleration: acceleration, maximum: maximum)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Parabolic SAR - Extended
|
|
66
|
+
# @param high [Array<Float>] High prices
|
|
67
|
+
# @param low [Array<Float>] Low prices
|
|
68
|
+
# @param start_value [Float] Start value (default: 0.0)
|
|
69
|
+
# @param offset_on_reverse [Float] Offset on reverse (default: 0.0)
|
|
70
|
+
# @param acceleration_init [Float] Acceleration init (default: 0.02)
|
|
71
|
+
# @param acceleration_step [Float] Acceleration step (default: 0.02)
|
|
72
|
+
# @param acceleration_max [Float] Acceleration max (default: 0.20)
|
|
73
|
+
# @return [Array<Float>] SAREXT values
|
|
74
|
+
def sarext(high, low, start_value: 0.0, offset_on_reverse: 0.0, acceleration_init: 0.02, acceleration_step: 0.02, acceleration_max: 0.20)
|
|
75
|
+
check_available!
|
|
76
|
+
validate_prices!(high)
|
|
77
|
+
validate_prices!(low)
|
|
78
|
+
|
|
79
|
+
TALibFFI.sarext(high, low,
|
|
80
|
+
start_value: start_value,
|
|
81
|
+
offset_on_reverse: offset_on_reverse,
|
|
82
|
+
af_init: acceleration_init,
|
|
83
|
+
af_increment: acceleration_step,
|
|
84
|
+
af_max: acceleration_max)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Acceleration Bands
|
|
88
|
+
# @param high [Array<Float>] High prices
|
|
89
|
+
# @param low [Array<Float>] Low prices
|
|
90
|
+
# @param close [Array<Float>] Close prices
|
|
91
|
+
# @param period [Integer] Time period (default: 20)
|
|
92
|
+
# @return [Array<Array<Float>>] [upper_band, middle_band, lower_band]
|
|
93
|
+
def accbands(high, low, close, period: 20)
|
|
94
|
+
check_available!
|
|
95
|
+
validate_prices!(high)
|
|
96
|
+
validate_prices!(low)
|
|
97
|
+
validate_prices!(close)
|
|
98
|
+
validate_period!(period, [high.size, low.size, close.size].min)
|
|
99
|
+
|
|
100
|
+
result = TALibFFI.accbands(high, low, close, time_period: period)
|
|
101
|
+
|
|
102
|
+
# Handle hash return format from newer ta_lib_ffi versions
|
|
103
|
+
if result.is_a?(Hash)
|
|
104
|
+
[result[:upper_band], result[:middle_band], result[:lower_band]]
|
|
105
|
+
else
|
|
106
|
+
result
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Hilbert Transform - Instantaneous Trendline
|
|
111
|
+
# @param prices [Array<Float>] Array of prices
|
|
112
|
+
# @return [Array<Float>] Trendline values
|
|
113
|
+
def ht_trendline(prices)
|
|
114
|
+
check_available!
|
|
115
|
+
validate_prices!(prices)
|
|
116
|
+
|
|
117
|
+
TALibFFI.ht_trendline(prices)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# MESA Adaptive Moving Average
|
|
121
|
+
# @param prices [Array<Float>] Array of prices
|
|
122
|
+
# @param fast_limit [Float] Fast limit (default: 0.5)
|
|
123
|
+
# @param slow_limit [Float] Slow limit (default: 0.05)
|
|
124
|
+
# @return [Array<Array<Float>>] [mama, fama]
|
|
125
|
+
def mama(prices, fast_limit: 0.5, slow_limit: 0.05)
|
|
126
|
+
check_available!
|
|
127
|
+
validate_prices!(prices)
|
|
128
|
+
|
|
129
|
+
result = TALibFFI.mama(prices, fastlimit: fast_limit, slowlimit: slow_limit)
|
|
130
|
+
|
|
131
|
+
# Handle hash return format from newer ta_lib_ffi versions
|
|
132
|
+
if result.is_a?(Hash)
|
|
133
|
+
[result[:mama], result[:fama]]
|
|
134
|
+
else
|
|
135
|
+
result
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# Moving Average with Variable Period
|
|
140
|
+
# @param prices [Array<Float>] Array of prices
|
|
141
|
+
# @param periods [Array<Integer>] Array of periods for each data point
|
|
142
|
+
# @param ma_type [Integer] Moving average type (default: 0)
|
|
143
|
+
# @return [Array<Float>] MAVP values
|
|
144
|
+
def mavp(prices, periods, ma_type: 0)
|
|
145
|
+
check_available!
|
|
146
|
+
validate_prices!(prices)
|
|
147
|
+
validate_prices!(periods)
|
|
148
|
+
|
|
149
|
+
TALibFFI.mavp(prices, periods, ma_type: ma_type)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Midpoint over period
|
|
153
|
+
# @param prices [Array<Float>] Array of prices
|
|
154
|
+
# @param period [Integer] Time period (default: 14)
|
|
155
|
+
# @return [Array<Float>] Midpoint values
|
|
156
|
+
def midpoint(prices, period: 14)
|
|
157
|
+
check_available!
|
|
158
|
+
validate_prices!(prices)
|
|
159
|
+
validate_period!(period, prices.size)
|
|
160
|
+
|
|
161
|
+
TALibFFI.midpoint(prices, time_period: period)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# Midpoint Price over period
|
|
165
|
+
# @param high [Array<Float>] High prices
|
|
166
|
+
# @param low [Array<Float>] Low prices
|
|
167
|
+
# @param period [Integer] Time period (default: 14)
|
|
168
|
+
# @return [Array<Float>] Midpoint price values
|
|
169
|
+
def midprice(high, low, period: 14)
|
|
170
|
+
check_available!
|
|
171
|
+
validate_prices!(high)
|
|
172
|
+
validate_prices!(low)
|
|
173
|
+
validate_period!(period, [high.size, low.size].min)
|
|
174
|
+
|
|
175
|
+
TALibFFI.midprice(high, low, time_period: period)
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SQA
|
|
4
|
+
module TAI
|
|
5
|
+
# Volume Indicators
|
|
6
|
+
module VolumeIndicators
|
|
7
|
+
# On Balance Volume
|
|
8
|
+
# @param close [Array<Float>] Close prices
|
|
9
|
+
# @param volume [Array<Float>] Volume values
|
|
10
|
+
# @return [Array<Float>] OBV values
|
|
11
|
+
def obv(close, volume)
|
|
12
|
+
check_available!
|
|
13
|
+
validate_prices!(close)
|
|
14
|
+
validate_prices!(volume)
|
|
15
|
+
|
|
16
|
+
TALibFFI.obv(close, volume)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Chaikin A/D Line
|
|
20
|
+
# @param high [Array<Float>] High prices
|
|
21
|
+
# @param low [Array<Float>] Low prices
|
|
22
|
+
# @param close [Array<Float>] Close prices
|
|
23
|
+
# @param volume [Array<Float>] Volume values
|
|
24
|
+
# @return [Array<Float>] AD values
|
|
25
|
+
def ad(high, low, close, volume)
|
|
26
|
+
check_available!
|
|
27
|
+
validate_prices!(high)
|
|
28
|
+
validate_prices!(low)
|
|
29
|
+
validate_prices!(close)
|
|
30
|
+
validate_prices!(volume)
|
|
31
|
+
|
|
32
|
+
TALibFFI.ad(high, low, close, volume)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Chaikin A/D Oscillator
|
|
36
|
+
# @param high [Array<Float>] High prices
|
|
37
|
+
# @param low [Array<Float>] Low prices
|
|
38
|
+
# @param close [Array<Float>] Close prices
|
|
39
|
+
# @param volume [Array<Float>] Volume values
|
|
40
|
+
# @param fast_period [Integer] Fast period (default: 3)
|
|
41
|
+
# @param slow_period [Integer] Slow period (default: 10)
|
|
42
|
+
# @return [Array<Float>] ADOSC values
|
|
43
|
+
def adosc(high, low, close, volume, fast_period: 3, slow_period: 10)
|
|
44
|
+
check_available!
|
|
45
|
+
validate_prices!(high)
|
|
46
|
+
validate_prices!(low)
|
|
47
|
+
validate_prices!(close)
|
|
48
|
+
validate_prices!(volume)
|
|
49
|
+
|
|
50
|
+
TALibFFI.adosc(high, low, close, volume, fast_period: fast_period, slow_period: slow_period)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|