Class: Alphavantage::Indicator
- Inherits:
-
Object
- Object
- Alphavantage::Indicator
- Includes:
- Validations
- Defined in:
- lib/alphavantage/indicator.rb
Constant Summary collapse
- MOVING_AVERAGE_TYPES =
{ sma: 0, ema: 1, wma: 2, dema: 3, tema: 4, trima: 5, t3: 6, kama: 7, mama: 8 }
Constants included from Validations
Validations::VALID_DATATYPES, Validations::VALID_INDICATOR_INTERVALS, Validations::VALID_INTERVALS, Validations::VALID_OUTPUTSIZES, Validations::VALID_SERIES_TYPES, Validations::VALID_SLICES
Instance Method Summary collapse
- #adosc(fastperiod: 3, slowperiod: 10) ⇒ Object
- #apo(series_type:, fastperiod: 12, slowperiod: 26, matype: 'sma') ⇒ Object (also: #ppo)
- #bbands(time_period:, series_type:, nbdevup: 2, nbdevdn: 2, matype: 'sma') ⇒ Object
- #ht_trendline(series_type:) ⇒ Object (also: #ht_sine, #ht_trendmode, #ht_dcperiod, #ht_dcphase, #ht_phasor)
-
#initialize(symbol:, interval:) ⇒ Indicator
constructor
A new instance of Indicator.
- #macd(series_type:, fastperiod: 12, slowperiod: 26, signalperiod: 9) ⇒ Object
- #macdext(series_type:, fastperiod: 12, slowperiod: 26, signalperiod: 9, fastmatype: 'sma', slowmatype: 'sma', signalmatype: 'sma') ⇒ Object
- #sar(acceleration: 0.01, maximum: 0.20) ⇒ Object
- #sma(time_period:, series_type:) ⇒ Object (also: #ema, #wma, #dema, #tema, #trima, #kama, #mama, #t3, #rsi, #mom, #cmo, #roc, #rocr, #trix, #midpoint)
- #stoch(fastkperiod: 5, slowkperiod: 3, slowdperiod: 3, slowkmatype: 'sma', slowdmatype: 'sma') ⇒ Object
- #stochf(fastkperiod: 5, fastdperiod: 3, fastdmatype: 'sma') ⇒ Object
- #stochrsi(time_period:, series_type:, fastkperiod: 5, fastdperiod: 3, fastdmatype: 'sma') ⇒ Object
- #ultosc(timeperiod1: 7, timeperiod2: 14, timeperiod3: 28) ⇒ Object
- #vwap ⇒ Object (also: #bop, #trange, #ad, #obv)
- #willr(time_period:) ⇒ Object (also: #adx, #adxr, #aroon, #aroonosc, #mfi, #dx, #minus_di, #plus_di, #minus_dm, #plus_dm, #midprice, #atr, #natr)
Constructor Details
#initialize(symbol:, interval:) ⇒ Indicator
Returns a new instance of Indicator.
5 6 7 8 |
# File 'lib/alphavantage/indicator.rb', line 5 def initialize(symbol:,interval:) @symbol = symbol @interval = interval end |
Instance Method Details
#adosc(fastperiod: 3, slowperiod: 10) ⇒ Object
169 170 171 172 173 174 175 176 177 |
# File 'lib/alphavantage/indicator.rb', line 169 def adosc(fastperiod: 3, slowperiod: 10) Client.get(params: { function: __callee__.upcase, symbol: @symbol, interval: validate_indicator_interval(@interval), fastperiod: validate_integer(label: 'fastperiod', value: fastperiod), slowperiod: validate_integer(label: 'slowperiod', value: slowperiod) }) end |
#apo(series_type:, fastperiod: 12, slowperiod: 26, matype: 'sma') ⇒ Object Also known as: ppo
193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/alphavantage/indicator.rb', line 193 def apo(series_type:, fastperiod: 12, slowperiod: 26, matype: 'sma') Client.get(params: { function: __callee__.upcase, symbol: @symbol, interval: validate_indicator_interval(@interval), series_type: validate_series_type(series_type), fastperiod: validate_integer(label: 'fastperiod', value: fastperiod), slowperiod: validate_integer(label: 'slowperiod', value: slowperiod), matype: validate_mat(MOVING_AVERAGE_TYPES[matype.to_sym]) }) end |
#bbands(time_period:, series_type:, nbdevup: 2, nbdevdn: 2, matype: 'sma') ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/alphavantage/indicator.rb', line 206 def bbands(time_period:, series_type:, nbdevup: 2, nbdevdn: 2, matype: 'sma') Client.get(params: { function: __callee__.upcase, symbol: @symbol, interval: validate_indicator_interval(@interval), time_period: validate_integer(label: 'time period', value: time_period), series_type: validate_series_type(series_type), nbdevup: validate_integer(label: 'nbdevup', value: nbdevup), nbdevdn: validate_integer(label: 'nbdevdn', value: nbdevdn), matype: validate_mat(MOVING_AVERAGE_TYPES[matype.to_sym]) }) end |
#ht_trendline(series_type:) ⇒ Object Also known as: ht_sine, ht_trendmode, ht_dcperiod, ht_dcphase, ht_phasor
179 180 181 182 183 184 185 186 |
# File 'lib/alphavantage/indicator.rb', line 179 def ht_trendline(series_type:) Client.get(params: { function: __callee__.upcase, symbol: @symbol, interval: validate_indicator_interval(@interval), series_type: validate_series_type(series_type) }) end |
#macd(series_type:, fastperiod: 12, slowperiod: 26, signalperiod: 9) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/alphavantage/indicator.rb', line 35 def macd(series_type:, fastperiod: 12, slowperiod: 26, signalperiod: 9) Client.get(params: { function: __callee__.upcase, symbol: @symbol, interval: validate_indicator_interval(@interval), series_type: validate_series_type(series_type), fastperiod: validate_integer(label: 'fastperiod', value: fastperiod), slowperiod: validate_integer(label: 'slowperiod', value: slowperiod), signalperiod: validate_integer(label: 'signalperiod', value: signalperiod) }) end |
#macdext(series_type:, fastperiod: 12, slowperiod: 26, signalperiod: 9, fastmatype: 'sma', slowmatype: 'sma', signalmatype: 'sma') ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/alphavantage/indicator.rb', line 59 def macdext( series_type:, fastperiod: 12, slowperiod: 26, signalperiod: 9, fastmatype: 'sma', slowmatype: 'sma', signalmatype: 'sma' ) Client.get(params: { function: __callee__.upcase, symbol: @symbol, interval: validate_indicator_interval(@interval), series_type: validate_series_type(series_type), fastperiod: validate_integer(label: 'fastperiod', value: fastperiod), slowperiod: validate_integer(label: 'slowperiod', value: slowperiod), signalperiod: validate_integer(label: 'signalperiod', value: signalperiod), fastmatype: validate_mat(MOVING_AVERAGE_TYPES[fastmatype.to_sym]), slowmatype: validate_mat(MOVING_AVERAGE_TYPES[slowmatype.to_sym]), signalmatype: validate_mat(MOVING_AVERAGE_TYPES[signalmatype.to_sym]) }) end |
#sar(acceleration: 0.01, maximum: 0.20) ⇒ Object
219 220 221 222 223 224 225 226 227 |
# File 'lib/alphavantage/indicator.rb', line 219 def sar(acceleration: 0.01, maximum: 0.20) Client.get(params: { function: __callee__.upcase, symbol: @symbol, interval: validate_indicator_interval(@interval), acceleration: validate_integer(label: 'acceleration', value: acceleration), maximum: validate_integer(label: 'maximum', value: maximum) }) end |
#sma(time_period:, series_type:) ⇒ Object Also known as: ema, wma, dema, tema, trima, kama, mama, t3, rsi, mom, cmo, roc, rocr, trix, midpoint
10 11 12 13 14 15 16 17 18 |
# File 'lib/alphavantage/indicator.rb', line 10 def sma(time_period:,series_type:) Client.get(params: { function: __callee__.upcase, symbol: @symbol, interval: validate_indicator_interval(@interval), time_period: validate_integer(label: 'time period', value: time_period), series_type: validate_series_type(series_type) }) end |
#stoch(fastkperiod: 5, slowkperiod: 3, slowdperiod: 3, slowkmatype: 'sma', slowdmatype: 'sma') ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/alphavantage/indicator.rb', line 82 def stoch( fastkperiod: 5, slowkperiod: 3, slowdperiod: 3, slowkmatype: 'sma', slowdmatype: 'sma' ) Client.get(params: { function: __callee__.upcase, symbol: @symbol, interval: validate_indicator_interval(@interval), fastkperiod: validate_integer(label: 'fastkperiod', value: fastkperiod), slowkperiod: validate_integer(label: 'slowkperiod', value: slowkperiod), slowdperiod: validate_integer(label: 'slowdperiod', value: slowdperiod), slowkmatype: validate_mat(MOVING_AVERAGE_TYPES[slowkmatype.to_sym]), slowdmatype: validate_mat(MOVING_AVERAGE_TYPES[slowdmatype.to_sym]) }) end |
#stochf(fastkperiod: 5, fastdperiod: 3, fastdmatype: 'sma') ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/alphavantage/indicator.rb', line 101 def stochf( fastkperiod: 5, fastdperiod: 3, fastdmatype: 'sma' ) Client.get(params: { function: __callee__.upcase, symbol: @symbol, interval: validate_indicator_interval(@interval), fastkperiod: validate_integer(label: 'fastkperiod', value: fastkperiod), fastdperiod: validate_integer(label: 'fastdperiod', value: fastdperiod), fastdmatype: validate_mat(MOVING_AVERAGE_TYPES[fastdmatype.to_sym]) }) end |
#stochrsi(time_period:, series_type:, fastkperiod: 5, fastdperiod: 3, fastdmatype: 'sma') ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/alphavantage/indicator.rb', line 116 def stochrsi( time_period:, series_type:, fastkperiod: 5, fastdperiod: 3, fastdmatype: 'sma' ) Client.get(params: { function: __callee__.upcase, symbol: @symbol, interval: validate_indicator_interval(@interval), time_period: validate_integer(label: 'time period', value: time_period), series_type: validate_series_type(series_type), fastkperiod: validate_integer(label: 'fastkperiod', value: fastkperiod), fastdperiod: validate_integer(label: 'fastdperiod', value: fastdperiod), fastdmatype: validate_mat(MOVING_AVERAGE_TYPES[fastdmatype.to_sym]) }) end |
#ultosc(timeperiod1: 7, timeperiod2: 14, timeperiod3: 28) ⇒ Object
229 230 231 232 233 234 235 236 237 238 |
# File 'lib/alphavantage/indicator.rb', line 229 def ultosc(timeperiod1: 7, timeperiod2: 14, timeperiod3: 28) Client.get(params: { function: __callee__.upcase, symbol: @symbol, interval: validate_indicator_interval(@interval), timeperiod1: validate_integer(label: 'timeperiod1', value: timeperiod1), timeperiod2: validate_integer(label: 'timeperiod2', value: timeperiod2), timeperiod3: validate_integer(label: 'timeperiod3', value: timeperiod3) }) end |
#vwap ⇒ Object Also known as: bop, trange, ad, obv
157 158 159 160 161 162 163 |
# File 'lib/alphavantage/indicator.rb', line 157 def vwap Client.get(params: { function: __callee__.upcase, symbol: @symbol, interval: [:bop,:trange,:ad,:obv].include?(__callee__) ? validate_indicator_interval(@interval) : validate_interval(@interval) }) end |
#willr(time_period:) ⇒ Object Also known as: adx, adxr, aroon, aroonosc, mfi, dx, minus_di, plus_di, minus_dm, plus_dm, midprice, atr, natr
135 136 137 138 139 140 141 142 |
# File 'lib/alphavantage/indicator.rb', line 135 def willr(time_period:) Client.get(params: { function: __callee__.upcase, symbol: @symbol, interval: validate_indicator_interval(@interval), time_period: validate_integer(label: 'time period', value: time_period) }) end |