class Object
Public Class Methods
self.hints provides the information about TA-Lib function. The information of them are extracted from talib library itself.
ATTENTION¶ ↑
library (talib_ruby) must support TaLib::Function
.{groups,functions}.
Args¶ ↑
- verbose:
-
parameter name only when false, or entire structs when true.
- group:
-
group name of functions.
- function:
-
name of function.
Description¶ ↑
-
one of group or function should be specified.
-
these args can be String,
Array
of String, or “all”
*
Return¶ ↑
# File lib/tafunc.rb, line 685 def self.hints( verbose: false, group: "all", function: "all" ) group_list = nil case when group == "all" group_list = self.groups when group.class == String group_list = [group] when group.class == Array group_list = group else raise "Type error #{group.class} for group!"+ " Please specify group in String or Array of String." end func_list = nil tmp = self.functions case when function == "all" func_list = tmp.values.flatten when function.class == Array func_list = function group_list = [] func_list.each{|f| group_list.push( tmp.keys.map{|e| (tmp[e].grep(f).size>0)? e : nil }.compact ) } group_list.flatten! when function.class == String func_list = [function] group_list = tmp.keys.map{|e| (tmp[e].grep(function).size>0)? e : nil }.compact else end # group_list = group_list.sort.uniq func_list = func_list.sort.uniq #pp group_list #pp func_list # group_list.each{|grp| puts "==== #{grp} ====" self.functions[grp].each{|func| #puts func if func_list.grep(func).size > 0 tmp = self.new(func) puts "<#{func}>" puts "inputs:" if verbose then pp tmp.ifs_ins else tmp.ifs_ins.each{|e| puts PPREFIX+e.param_name.underscore } end puts "" puts "options:" if verbose then pp tmp.ifs_opts else tmp.ifs_opts.each{|e| puts PPREFIX+e.param_name.underscore } end puts "" puts "outputs:" if verbose then pp tmp.ifs_outs else tmp.ifs_outs.each{|e| puts PPREFIX+e.param_name.underscore } end puts "" puts "" end } } end
Public Instance Methods
wrap Function#call to accept various kinds of args.
Args¶ ↑
- *r
-
range of input array in several ways: no args: from pram_in_* m, n: direct indexes m..n: range object array: array
Return¶ ↑
due to the function.
# File lib/tafunc.rb, line 573 def call( *r ) m, n = nil, nil # specifies m and n, simulation range in input data. case when r.size == 0 # no args. raise "No setting of param_in_* for #{name}!" if @param_in[0].nil? m, n = 0, @param_in[0][:val].size-1 when r.first.class == Range # Range is given. m, n = r.first.first, r.first.last when r.size == 2 # 2 indexes are given. #puts "couple of index." m, n = r.first, r.last when r.first.class == Array # Array is given. #puts "array." self.param_in_real = r.first if @param_in[0].nil? m, n = 0, r.first.size-1 else raise "Strange args: #{r}! Should be in one of Nothing,"+ " two indexes, Array or Range." end #puts "idx: #{m}, #{n}" param_size = case @param_in[0][:type] when :TA_Input_Price [ @param_in[0][:val][:open], @param_in[0][:val][:high], @param_in[0][:val][:low], @param_in[0][:val][:close], ].map{|e| (e.nil?)? 0 : e.size }.max when :TA_Input_Real self.param_in_real.size when :TA_Input_Integer raise "Not yet implemented." else raise "Strange type for input parameter:"+ " #{@param_in[0][:type]}." end case when m > n raise "calculation range(#{m},#{n}) is currently not supported!" when n >= param_size raise "#{n} is too big!"+ " less than or equal to #{self.param_in_real.size-1}" end # ret = param_out_setting tmp = super( m, n ) ret.merge!( { :start_idx => tmp[0], :num_elements => tmp[1], } ) # return ret end
auto prepare output arrays.
Requirements¶ ↑
all in-parameters have already been set.
Args¶ ↑
- h
-
output hash to be set.
- force_mode:
-
force to create new array for output (default: false)
Return¶ ↑
- h
-
{ :output_parameter1 => [ nil, nil, … ],
:output_parameter2 => [ nil, nil, ... ], }
TODO¶ ↑
-
currently tested only MA, MACDEXT.
# File lib/tafunc.rb, line 642 def param_out_setting( h = {}, force_mode: false ) # get output attributes (arrays to prepare). # ex. param_out_macd, param_out_macd_signal, param_out_macd_hist # tmp = self.param_attr( :out ) # prepare arrays and set them. tmp.each{|a| # if force_mode or self.send( a ).nil? then h[a] = Array.new( self.param_in_real.size ) self.send( (a.to_s+'=').to_sym, h[a] ) else h[a] = self.send( a ) # call getter. end } return h end