Giter Club home page Giter Club logo

talib-ruby's Introduction

talib-ruby

Ruby Wrapper for ta-lib

This project has been started by Timur Adigamov on Rubyforge,
but since it didn’t build on my machine and wasn’t complete i modified it slightly, et voila.

Important note for commit id 11277315208a8bfcfd2a3211e10b5732d6705fc7 and gem version 1.0.6

From now on all returned lists from talib_ruby now correspond to what ta-lib returns, i.e. there will be no longer leading nil values in any outXYZ lists.
The nil values will now be trailing nil values if your inserted outXYZ lists are too large (let’s say you always insert out arrays with the same length as the inXYZ lists).
Therefore the returned value outBegIdx is no more relevant for the outXYZ lists, since the first calculated value can be found right at index 0 in the outXYZ lists.
All calculated values are still the same, it’s only a shifting issue which has been corrected now.
Thanks go to Masayuki Yamamoto who showed me this.

Install and build instructions

Install ta-lib:

Install ta-lib from MacPorts:

sudo port install ta-lib

Or install ta-lib from Homebrew:

sudo brew install ta-lib

If you want to compile ta-lib from the sources (ta-lib.org) you have to use the following statements (thanks to rmldj):

./configure LDFLAGS="-lm"
make
sudo make install

Install the ruby wrapper talib_ruby:

sudo env ARCHFLAGS="-arch PLATFORM" gem install talib_ruby -- --with-talib-include=ABSOLUTE_PATH_TO_TALIB_HEADERS  --with-talib-lib=ABSOLUTE_PATH_TO_TALIB_LIBS
  • PLATFORM = [i386 | x86_64 | …]
  • ABSOLUTE_PATH_TO_TALIB_HEADERS = The path to the ta-lib header files
    • e.g. for Port: /opt/local/var/macports/software/ta-lib/0.4.0_0/opt/local/include
    • e.g. for Homebrew: /usr/local/Cellar/ta-lib/0.4.0/include
  • ABSOLUTE_PATH_TO_TALIB_LIBS = The path to the ta-lib lib files
    • e.g. fo Port: /opt/local/var/macports/software/ta-lib/0.4.0_0/opt/local/lib
    • e.g. fo Homebrew: /usr/local/Cellar/ta-lib/0.4.0/lib

Now ta-lib can be used by using require ‘talib_ruby’
Needs at least Mac OSX 10.5. Has not been tested on Windows, but works there too what i’ve heard.
Tested with Ruby 1.8.7, 1.9.3 and 2.0.0.

Example

Calculation of Moving Average (MA):

require 'rubygems'
require 'talib_ruby'

# init input data
a = Array.new
10.times { |i| a.push i.to_f }

10.times do |k|
    b = Array.new(10)
    l = TaLib::Function.new("MA")
    # setup input parameter
    l.in_real(0,a)
    # setup optional parameter
    l.opt_int(0,k+2)
    # setup output parameter
    l.out_real(0,b)
    lookback = l.lookback
    l.call(0,9)
    p "k=#{k+2}"
    p b
end

Useful links

Donate

If you think this library is useful i would be grateful for a donation.

License

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright © 2013 by Valentin Treu, released under the MIT license.

talib-ruby's People

Contributors

escudero avatar marcocarvalho avatar mlamby avatar ricpruss avatar rivella50 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

talib-ruby's Issues

It isn't possible to use OBV indicator

Running the following example code:

close = [26.0, 54.0, 8.0, 77.0, 61.0, 39.0, 44.0, 91.0, 98.0, 17.0]
volume = [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0]

func = TaLib::Function.new("OBV")
len = close.length
func.in_real(0, close)
#func.in_real(1, volume)
func.in_volume(0,volume)

out_real = Array.new(len)
@func.out_real(0, out_real)
@func.call(0, len - 1)

I get either:

undefined method `in_volume' for #<TaLib::Function:0x007ff19bbd5440 @name="OBV", @result=[]>

if I use func.in_volume or

RuntimeError: unsuccess return code TA_SetInputParamRealPtr
    from (irb):151:in `in_real'
    from (irb):151
    from /Users/vertis/.rbenv/versions/2.1.6/bin/irb:11:in `<main>'

if I try to use in_real(1,...)

Looking at the talib code seems to suggest there should be an in_volume (unless I'm misunderstanding something)

unsuccess return code TA_SetInputParamPricePtr (RuntimeError)

Hello

I use ta-indicator & talib since 2 months on 2 servers.
Today, ruby refuse to exec command like .indicator(:WclPrice)

/home/user/.rvm/gems/ruby-2.0.0-p247/gems/ta-indicator-0.1.1/lib/indicator/auto_gen/wcl_price.rb:34:in in_price': unsuccess return code TA_SetInputParamPricePtr (RuntimeError) from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/ta-indicator-0.1.1/lib/indicator/auto_gen/wcl_price.rb:34:inrun'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/ta-indicator-0.1.1/lib/indicator/mixin.rb:7:in `indicator'

This in both servers, without any update or anything.... it worked until now, and suddenly does not work from anywhere.

Hope here is the right place to report that problem.
Regards and keep on the good work

undefined symbol: TA_GetFuncHandle

I've installed ta-lib on Ubuntu 12.10 via source code, then talib_ruby, it seems ok.

  • Ruby v1.9.3p392
  • Gem v1.8.25
  • GCC v4.7.2
$ env ARCHFLAGS="-arch i386" gem install talib_ruby -- --with-talib-include=/usr/local/ta-lib/include/ta-lib --with-talib-lib=/usr/local/ta-lib/lib
Building native extensions.  This could take a while...
Successfully installed talib_ruby-1.0.4
1 gem installed

but got an error when run the example. I've no idea what to do next.

$ ruby example/ma.rb
ruby: symbol lookup error: /.../gems/talib_ruby-1.0.4/lib/talib.so: undefined symbol: TA_GetFuncHandle

Issue installing on Debian

I'm hoping you can offer some insight as to what might be going on here (see output below). My guess is that the issue is with the line, "talib.c:2:25: error: ta_abstract.h: No such file or directory". I've installed ta-lib-dev, which I thought would take care of these dependencies, but perhaps not. Thoughts?

sudo gem install talib_ruby
Building native extensions. This could take a while...
ERROR: Error installing talib_ruby:

ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb checking for TA_Initialize() in -lta_lib... no
creating Makefile

make
gcc -I. -I. -I/usr/lib/ruby/1.8/i486-linux -I. -D_FILE_OFFSET_BITS=64 -fPIC -fno-strict-aliasing -g -g -O2 -fPIC -c talib.c
talib.c:2:25: error: ta_abstract.h: No such file or directory
talib.c:30: error: expected specifier-qualifier-list before ‘TA_ParamHolder’
talib.c:37: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘’ token
talib.c: In function ‘ta_func_param_info’:
talib.c:57: error: ‘TA_RetCode’ undeclared (first use in this function)
talib.c:57: error: (Each undeclared identifier is reported only once
talib.c:57: error: for each function it appears in.)
talib.c:57: error: expected ‘;’ before ‘ret_code’
talib.c:58: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘’ token
talib.c:58: error: ‘handle’ undeclared (first use in this function)
talib.c:60: error: ‘ret_code’ undeclared (first use in this function)
talib.c:61: error: ‘TA_SUCCESS’ undeclared (first use in this function)
talib.c:67: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘’ token
talib.c:67: error: ‘param_info’ undeclared (first use in this function)
talib.c:77: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘’ token
talib.c:89: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘’ token
talib.c: In function ‘init_tables’:
talib.c:118: error: ‘TA_RetCode’ undeclared (first use in this function)
talib.c:118: error: expected ‘;’ before ‘ret_code’
talib.c:120: error: ‘TA_StringTable’ undeclared (first use in this function)
talib.c:120: error: ‘group_table’ undeclared (first use in this function)
talib.c:123: error: ‘ret_code’ undeclared (first use in this function)
talib.c:124: error: ‘TA_SUCCESS’ undeclared (first use in this function)
talib.c:127: error: ‘function_table’ undeclared (first use in this function)
talib.c: In function ‘ta_func_free’:
talib.c:160: error: ‘ParamHolder’ has no member named ‘in’
talib.c:160: error: ‘ParamHolder’ has no member named ‘in’
talib.c:161: error: ‘ParamHolder’ has no member named ‘out’
talib.c:161: error: ‘ParamHolder’ has no member named ‘out’
talib.c:162: error: ‘ParamHolder’ has no member named ‘p’
talib.c: In function ‘ta_func_initialize’:
talib.c:184: error: ‘TA_RetCode’ undeclared (first use in this function)
talib.c:184: error: expected ‘;’ before ‘ret_code’
talib.c:185: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘’ token
talib.c:185: error: ‘handle’ undeclared (first use in this function)
talib.c:186: error: ‘TA_ParamHolder’ undeclared (first use in this function)
talib.c:186: error: ‘ta_param_holder’ undeclared (first use in this function)
talib.c:191: error: ‘ret_code’ undeclared (first use in this function)
talib.c:192: error: ‘TA_SUCCESS’ undeclared (first use in this function)
talib.c:197: error: ‘ParamHolder’ has no member named ‘p’
talib.c: In function ‘ta_func_get_input_count’:
talib.c:210: error: invalid type argument of ‘->’ (have ‘int’)
talib.c: In function ‘ta_func_get_option_input_count’:
talib.c:218: error: invalid type argument of ‘->’ (have ‘int’)
talib.c: In function ‘ta_func_get_output_count’:
talib.c:226: error: invalid type argument of ‘->’ (have ‘int’)
talib.c: In function ‘ta_func_setup_in_integer’:
talib.c:283: error: ‘TA_RetCode’ undeclared (first use in this function)
talib.c:283: error: expected ‘;’ before ‘ret_code’
talib.c:287: error: ‘ret_code’ undeclared (first use in this function)
talib.c:287: error: ‘ParamHolder’ has no member named ‘p’
talib.c:288: error: ‘TA_SUCCESS’ undeclared (first use in this function)
talib.c: In function ‘ta_func_setup_in_real’:
talib.c:299: error: ‘TA_RetCode’ undeclared (first use in this function)
talib.c:299: error: expected ‘;’ before ‘ret_code’
talib.c:303: error: ‘ParamHolder’ has no member named ‘in’
talib.c:305: error: ‘ret_code’ undeclared (first use in this function)
talib.c:305: error: ‘ParamHolder’ has no member named ‘p’
talib.c:306: error: ‘TA_SUCCESS’ undeclared (first use in this function)
talib.c: In function ‘ta_func_setup_in_price’:
talib.c:312: error: ‘TA_RetCode’ undeclared (first use in this function)
talib.c:312: error: expected ‘;’ before ‘ret_code’
talib.c:315: error: ‘ParamHolder’ has no member named ‘in’
talib.c:316: error: ‘ret_code’ undeclared (first use in this function)
talib.c:316: error: ‘ParamHolder’ has no member named ‘p’
talib.c:317: error: ‘TA_SUCCESS’ undeclared (first use in this function)
talib.c: In function ‘ta_func_setup_opt_in_integer’:
talib.c:328: error: ‘TA_RetCode’ undeclared (first use in this function)
talib.c:328: error: expected ‘;’ before ‘ret_code’
talib.c:331: error: ‘ret_code’ undeclared (first use in this function)
talib.c:331: error: ‘ParamHolder’ has no member named ‘p’
talib.c:332: error: ‘TA_SUCCESS’ undeclared (first use in this function)
talib.c: In function ‘ta_func_setup_opt_in_real’:
talib.c:343: error: ‘TA_RetCode’ undeclared (first use in this function)
talib.c:343: error: expected ‘;’ before ‘ret_code’
talib.c:347: error: ‘ret_code’ undeclared (first use in this function)
talib.c:347: error: ‘ParamHolder’ has no member named ‘p’
talib.c:348: error: ‘TA_SUCCESS’ undeclared (first use in this function)
talib.c: In function ‘ta_func_setup_out_real’:
talib.c:359: error: ‘TA_RetCode’ undeclared (first use in this function)
talib.c:359: error: expected ‘;’ before ‘ret_code’
talib.c:367: error: ‘ParamHolder’ has no member named ‘out’
talib.c:370: error: ‘ret_code’ undeclared (first use in this function)
talib.c:370: error: ‘ParamHolder’ has no member named ‘p’
talib.c:371: error: ‘TA_SUCCESS’ undeclared (first use in this function)
talib.c: In function ‘ta_func_setup_out_integer’:
talib.c:377: error: ‘TA_RetCode’ undeclared (first use in this function)
talib.c:377: error: expected ‘;’ before ‘ret_code’
talib.c:385: error: ‘ParamHolder’ has no member named ‘out’
talib.c:388: error: ‘ret_code’ undeclared (first use in this function)
talib.c:388: error: ‘ParamHolder’ has no member named ‘p’
talib.c:389: error: ‘TA_SUCCESS’ undeclared (first use in this function)
talib.c: In function ‘ta_func_call’:
talib.c:400: error: ‘TA_RetCode’ undeclared (first use in this function)
talib.c:400: error: expected ‘;’ before ‘ret_code’
talib.c:402: error: ‘TA_Integer’ undeclared (first use in this function)
talib.c:402: error: expected ‘;’ before ‘out_start’
talib.c:407: error: ‘ret_code’ undeclared (first use in this function)
talib.c:407: error: ‘ParamHolder’ has no member named ‘p’
talib.c:407: error: ‘out_start’ undeclared (first use in this function)
talib.c:407: error: ‘out_num’ undeclared (first use in this function)
talib.c:408: error: ‘TA_SUCCESS’ undeclared (first use in this function)
talib.c:417: error: ‘ParamHolder’ has no member named ‘out’
talib.c: In function ‘ta_func_lookback’:
talib.c:426: error: ‘TA_RetCode’ undeclared (first use in this function)
talib.c:426: error: expected ‘;’ before ‘ret_code’
talib.c:428: error: ‘TA_Integer’ undeclared (first use in this function)
talib.c:428: error: expected ‘;’ before ‘out_lookback’
talib.c:431: error: ‘ret_code’ undeclared (first use in this function)
talib.c:431: error: ‘ParamHolder’ has no member named ‘p’
talib.c:431: error: ‘out_lookback’ undeclared (first use in this function)
talib.c:432: error: ‘TA_SUCCESS’ undeclared (first use in this function)
talib.c: In function ‘Init_talib’:
talib.c:446: error: ‘TA_Input_Price’ undeclared (first use in this function)
talib.c:447: error: ‘TA_Input_Real’ undeclared (first use in this function)
talib.c:448: error: ‘TA_Input_Integer’ undeclared (first use in this function)
talib.c:449: error: ‘TA_IN_PRICE_OPEN’ undeclared (first use in this function)
talib.c:450: error: ‘TA_IN_PRICE_HIGH’ undeclared (first use in this function)
talib.c:451: error: ‘TA_IN_PRICE_LOW’ undeclared (first use in this function)
talib.c:452: error: ‘TA_IN_PRICE_CLOSE’ undeclared (first use in this function)
talib.c:453: error: ‘TA_IN_PRICE_VOLUME’ undeclared (first use in this function)
talib.c:454: error: ‘TA_IN_PRICE_OPENINTEREST’ undeclared (first use in this function)
talib.c:455: error: ‘TA_IN_PRICE_TIMESTAMP’ undeclared (first use in this function)
talib.c:456: error: ‘TA_OptInput_RealRange’ undeclared (first use in this function)
talib.c:457: error: ‘TA_OptInput_RealList’ undeclared (first use in this function)
talib.c:458: error: ‘TA_OptInput_IntegerRange’ undeclared (first use in this function)
talib.c:459: error: ‘TA_OptInput_IntegerList’ undeclared (first use in this function)
talib.c:460: error: ‘TA_OPTIN_IS_PERCENT’ undeclared (first use in this function)
talib.c:461: error: ‘TA_OPTIN_IS_DEGREE’ undeclared (first use in this function)
talib.c:462: error: ‘TA_OPTIN_IS_CURRENCY’ undeclared (first use in this function)
talib.c:463: error: ‘TA_OPTIN_ADVANCED’ undeclared (first use in this function)
talib.c:464: error: ‘TA_Output_Real’ undeclared (first use in this function)
talib.c:465: error: ‘TA_Output_Integer’ undeclared (first use in this function)
talib.c:466: error: ‘TA_OUT_LINE’ undeclared (first use in this function)
talib.c:467: error: ‘TA_OUT_DOT_LINE’ undeclared (first use in this function)
talib.c:468: error: ‘TA_OUT_DASH_LINE’ undeclared (first use in this function)
talib.c:469: error: ‘TA_OUT_DOT’ undeclared (first use in this function)
talib.c:470: error: ‘TA_OUT_HISTO’ undeclared (first use in this function)
talib.c:471: error: ‘TA_OUT_PATTERN_BOOL’ undeclared (first use in this function)
talib.c:472: error: ‘TA_OUT_PATTERN_BULL_BEAR’ undeclared (first use in this function)
talib.c:473: error: ‘TA_OUT_PATTERN_STRENGTH’ undeclared (first use in this function)
talib.c:474: error: ‘TA_OUT_POSITIVE’ undeclared (first use in this function)
talib.c:475: error: ‘TA_OUT_NEGATIVE’ undeclared (first use in this function)
talib.c:476: error: ‘TA_OUT_ZERO’ undeclared (first use in this function)
talib.c:477: error: ‘TA_OUT_UPPER_LIMIT’ undeclared (first use in this function)
talib.c:478: error: ‘TA_OUT_LOWER_LIMIT’ undeclared (first use in this function)
talib.c:479: error: ‘TA_MAType_SMA’ undeclared (first use in this function)
talib.c:480: error: ‘TA_MAType_EMA’ undeclared (first use in this function)
talib.c:481: error: ‘TA_MAType_WMA’ undeclared (first use in this function)
talib.c:482: error: ‘TA_MAType_DEMA’ undeclared (first use in this function)
talib.c:483: error: ‘TA_MAType_TEMA’ undeclared (first use in this function)
talib.c:484: error: ‘TA_MAType_TRIMA’ undeclared (first use in this function)
talib.c:485: error: ‘TA_MAType_KAMA’ undeclared (first use in this function)
talib.c:486: error: ‘TA_MAType_MAMA’ undeclared (first use in this function)
talib.c:487: error: ‘TA_MAType_T3’ undeclared (first use in this function)
make: *** [talib.o] Error 1

Gem files will remain installed in /var/lib/gems/1.8/gems/talib_ruby-1.0.3 for inspection.
Results logged to /var/lib/gems/1.8/gems/talib_ruby-1.0.3/ext/talib/gem_make.out

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.