sqa-tai 0.1.0 → 0.1.2

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.
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SQA
4
+ module TAI
5
+ # Overlap Studies (Moving Averages, Bands)
6
+ module OverlapStudies
7
+ # Moving Average - Generic
8
+ # @param prices [Array<Float>] Array of prices
9
+ # @param period [Integer] Time period (default: 30)
10
+ # @param ma_type [Integer] MA type: 0=SMA, 1=EMA, 2=WMA, 3=DEMA, 4=TEMA, 5=TRIMA, 6=KAMA, 7=MAMA, 8=T3 (default: 0)
11
+ # @return [Array<Float>] MA values
12
+ def ma(prices, period: 30, ma_type: 0)
13
+ check_available!
14
+ validate_prices!(prices)
15
+ validate_period!(period, prices.size)
16
+
17
+ TALibFFI.ma(prices, time_period: period, ma_type: ma_type)
18
+ end
19
+
20
+ # Simple Moving Average
21
+ # @param prices [Array<Float>] Array of prices
22
+ # @param period [Integer] Time period (default: 30)
23
+ # @return [Array<Float>] SMA values
24
+ def sma(prices, period: 30)
25
+ check_available!
26
+ validate_prices!(prices)
27
+ validate_period!(period, prices.size)
28
+
29
+ TALibFFI.sma(prices, time_period: period)
30
+ end
31
+
32
+ # Exponential Moving Average
33
+ # @param prices [Array<Float>] Array of prices
34
+ # @param period [Integer] Time period (default: 30)
35
+ # @return [Array<Float>] EMA values
36
+ def ema(prices, period: 30)
37
+ check_available!
38
+ validate_prices!(prices)
39
+ validate_period!(period, prices.size)
40
+
41
+ TALibFFI.ema(prices, time_period: period)
42
+ end
43
+
44
+ # Weighted Moving Average
45
+ # @param prices [Array<Float>] Array of prices
46
+ # @param period [Integer] Time period (default: 30)
47
+ # @return [Array<Float>] WMA values
48
+ def wma(prices, period: 30)
49
+ check_available!
50
+ validate_prices!(prices)
51
+ validate_period!(period, prices.size)
52
+
53
+ TALibFFI.wma(prices, time_period: period)
54
+ end
55
+
56
+ # Double Exponential Moving Average
57
+ # @param prices [Array<Float>] Array of prices
58
+ # @param period [Integer] Time period (default: 30)
59
+ # @return [Array<Float>] DEMA values
60
+ def dema(prices, period: 30)
61
+ check_available!
62
+ validate_prices!(prices)
63
+ validate_period!(period, prices.size)
64
+
65
+ TALibFFI.dema(prices, time_period: period)
66
+ end
67
+
68
+ # Triple Exponential Moving Average
69
+ # @param prices [Array<Float>] Array of prices
70
+ # @param period [Integer] Time period (default: 30)
71
+ # @return [Array<Float>] TEMA values
72
+ def tema(prices, period: 30)
73
+ check_available!
74
+ validate_prices!(prices)
75
+ validate_period!(period, prices.size)
76
+
77
+ TALibFFI.tema(prices, time_period: period)
78
+ end
79
+
80
+ # Triangular Moving Average
81
+ # @param prices [Array<Float>] Array of prices
82
+ # @param period [Integer] Time period (default: 30)
83
+ # @return [Array<Float>] TRIMA values
84
+ def trima(prices, period: 30)
85
+ check_available!
86
+ validate_prices!(prices)
87
+ validate_period!(period, prices.size)
88
+
89
+ TALibFFI.trima(prices, time_period: period)
90
+ end
91
+
92
+ # Kaufman Adaptive Moving Average
93
+ # @param prices [Array<Float>] Array of prices
94
+ # @param period [Integer] Time period (default: 30)
95
+ # @return [Array<Float>] KAMA values
96
+ def kama(prices, period: 30)
97
+ check_available!
98
+ validate_prices!(prices)
99
+ validate_period!(period, prices.size)
100
+
101
+ TALibFFI.kama(prices, time_period: period)
102
+ end
103
+
104
+ # Triple Exponential Moving Average (T3)
105
+ # @param prices [Array<Float>] Array of prices
106
+ # @param period [Integer] Time period (default: 5)
107
+ # @param vfactor [Float] Volume factor (default: 0.7)
108
+ # @return [Array<Float>] T3 values
109
+ def t3(prices, period: 5, vfactor: 0.7)
110
+ check_available!
111
+ validate_prices!(prices)
112
+ validate_period!(period, prices.size)
113
+
114
+ TALibFFI.t3(prices, time_period: period, vfactor: vfactor)
115
+ end
116
+
117
+ # Bollinger Bands
118
+ # @param prices [Array<Float>] Array of prices
119
+ # @param period [Integer] Time period (default: 5)
120
+ # @param nbdev_up [Float] Upper deviation (default: 2.0)
121
+ # @param nbdev_down [Float] Lower deviation (default: 2.0)
122
+ # @return [Array<Array<Float>>] [upper_band, middle_band, lower_band]
123
+ def bbands(prices, period: 5, nbdev_up: 2.0, nbdev_down: 2.0)
124
+ check_available!
125
+ validate_prices!(prices)
126
+ validate_period!(period, prices.size)
127
+
128
+ result = TALibFFI.bbands(
129
+ prices,
130
+ time_period: period,
131
+ nbdev_up: nbdev_up,
132
+ nbdev_dn: nbdev_down
133
+ )
134
+
135
+ # Handle hash return format from newer ta_lib_ffi versions
136
+ if result.is_a?(Hash)
137
+ [result[:upper_band], result[:middle_band], result[:lower_band]]
138
+ else
139
+ result
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end