Class: Indicator::AutoGen::Macd

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

Overview

Ta-Lib function mapping class Function: ‘MACD’ Description: ‘Moving Average Convergence/Divergence’ 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) ⇒ Macd

Returns a new instance of Macd.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/indicator/auto_gen/macd.rb', line 13

def initialize(*args)
  if args.first.is_a? Hash
    h = args.first
    @fast_period = h[:fast_period] || 12
    @slow_period = h[:slow_period] || 26
    @signal_period = h[:signal_period] || 9
  else
    @fast_period = args[0] || 12 
    @slow_period = args[1] || 26 
    @signal_period = args[2] || 9 
  end
  
  @func = TaLib::Function.new("MACD")
end

Instance Attribute Details

#fast_periodObject

Fast Period <Integer>



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

def fast_period
  @fast_period
end

#signal_periodObject

Signal Period <Integer>



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

def signal_period
  @signal_period
end

#slow_periodObject

Slow Period <Integer>



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

def slow_period
  @slow_period
end

Class Method Details

.argumentsObject

The list of arguments



34
35
36
# File 'lib/indicator/auto_gen/macd.rb', line 34

def self.arguments
  [ :fast_period, :slow_period, :signal_period ]
end

.inputsObject

The minimum set of inputs required



39
40
41
# File 'lib/indicator/auto_gen/macd.rb', line 39

def self.inputs
  [ :in_real ]
end

.outputsObject

The outputs generated by this function



44
45
46
# File 'lib/indicator/auto_gen/macd.rb', line 44

def self.outputs
  [ :out_macd, :out_macd_signal, :out_macd_hist ]
end

.price_input?Boolean

Is price data required as an input

Returns:

  • (Boolean)


29
30
31
# File 'lib/indicator/auto_gen/macd.rb', line 29

def self.price_input?
  false
end

Instance Method Details

#run(in_real) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/indicator/auto_gen/macd.rb', line 48

def run(in_real)
  len = in_real.length
  @func.in_real(0, map(in_real))

  @func.opt_int(0, @fast_period)
  @func.opt_int(1, @slow_period)
  @func.opt_int(2, @signal_period)

  out_macd = Array.new(len)
  @func.out_real(0, out_macd)
  out_macd_signal = Array.new(len)
  @func.out_real(1, out_macd_signal)
  out_macd_hist = Array.new(len)
  @func.out_real(2, out_macd_hist)

  @func.call(0, len - 1)

{:out_macd => out_macd,
  :out_macd_signal => out_macd_signal,
  :out_macd_hist => out_macd_hist}
end