Class: Indicator::AutoGen::Stoch

Inherits:
Base
  • Object
show all
Defined in:
lib/indicator/auto_gen/stoch.rb

Overview

Ta-Lib function mapping class Function: ‘STOCH’ Description: ‘Stochastic’ This file has been autogenerated - Do Not Edit.

Instance Attribute Summary collapse

Attributes inherited from Base

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inherited, #map_ohlcv

Methods included from DataMapper

#default_getter, #default_getter=, #map

Constructor Details

#initialize(*args) ⇒ Stoch

Returns a new instance of Stoch.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/indicator/auto_gen/stoch.rb', line 17

def initialize(*args)
  if args.first.is_a? Hash
    h = args.first
    @fast_k_period = h[:fast_k_period] || 5
    @slow_k_period = h[:slow_k_period] || 3
    @slow_k_ma = h[:slow_k_ma] || 0
    @slow_d_period = h[:slow_d_period] || 3
    @slow_d_ma = h[:slow_d_ma] || 0
  else
    @fast_k_period = args[0] || 5 
    @slow_k_period = args[1] || 3 
    @slow_k_ma = args[2] || 0 
    @slow_d_period = args[3] || 3 
    @slow_d_ma = args[4] || 0 
  end
  
  @func = TaLib::Function.new("STOCH")
end

Instance Attribute Details

#fast_k_periodObject

Fast-K Period <Integer>



7
8
9
# File 'lib/indicator/auto_gen/stoch.rb', line 7

def fast_k_period
  @fast_k_period
end

#slow_d_maObject

Slow-D MA <MA Type>



15
16
17
# File 'lib/indicator/auto_gen/stoch.rb', line 15

def slow_d_ma
  @slow_d_ma
end

#slow_d_periodObject

Slow-D Period <Integer>



13
14
15
# File 'lib/indicator/auto_gen/stoch.rb', line 13

def slow_d_period
  @slow_d_period
end

#slow_k_maObject

Slow-K MA <MA Type>



11
12
13
# File 'lib/indicator/auto_gen/stoch.rb', line 11

def slow_k_ma
  @slow_k_ma
end

#slow_k_periodObject

Slow-K Period <Integer>



9
10
11
# File 'lib/indicator/auto_gen/stoch.rb', line 9

def slow_k_period
  @slow_k_period
end

Class Method Details

.argumentsObject

The list of arguments



42
43
44
# File 'lib/indicator/auto_gen/stoch.rb', line 42

def self.arguments
  [ :fast_k_period, :slow_k_period, :slow_k_ma, :slow_d_period, :slow_d_ma ]
end

.inputsObject

The minimum set of inputs required



47
48
49
# File 'lib/indicator/auto_gen/stoch.rb', line 47

def self.inputs
  [ :high, :low, :close ]
end

.outputsObject

The outputs generated by this function



52
53
54
# File 'lib/indicator/auto_gen/stoch.rb', line 52

def self.outputs
  [ :out_slow_k, :out_slow_d ]
end

.price_input?Boolean

Is price data required as an input

Returns:

  • (Boolean)


37
38
39
# File 'lib/indicator/auto_gen/stoch.rb', line 37

def self.price_input?
  true
end

Instance Method Details

#run(*args) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/indicator/auto_gen/stoch.rb', line 56

def run(*args)
  o, h, l, c, v, len = map_ohlcv(self.class.inputs, *args)
  @func.in_price(0, o, h, l, c, v, nil)

  @func.opt_int(0, @fast_k_period)
  @func.opt_int(1, @slow_k_period)
  @func.opt_int(2, @slow_k_ma)
  @func.opt_int(3, @slow_d_period)
  @func.opt_int(4, @slow_d_ma)

  out_slow_k = Array.new(len)
  @func.out_real(0, out_slow_k)
  out_slow_d = Array.new(len)
  @func.out_real(1, out_slow_d)

  @func.call(0, len - 1)

{:out_slow_k => out_slow_k,
  :out_slow_d => out_slow_d}
end