talib_ruby 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +12 -4
- data/example/ma.rb +2 -3
- data/ext/talib/talib.c +48 -24
- metadata +4 -10
data/README.textile
CHANGED
@@ -11,16 +11,24 @@ Install ta-lib from "MacPorts":http://www.macports.org/ports.php?by=name&substr=
|
|
11
11
|
|
12
12
|
bc. sudo port install ta-lib
|
13
13
|
|
14
|
+
Or install ta-lib from "Homebrew":https://github.com/mxcl/homebrew/blob/master/Library/Formula/ta-lib.rb:
|
15
|
+
|
16
|
+
bc. sudo brew install ta-lib
|
17
|
+
|
14
18
|
Install the ruby wrapper talib_ruby:
|
15
19
|
|
16
20
|
bc. 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
|
17
21
|
|
18
22
|
* PLATFORM = [i386 | x86_64 | ...]
|
19
|
-
* ABSOLUTE_PATH_TO_TALIB_HEADERS = The path to the ta-lib header files
|
20
|
-
|
23
|
+
* ABSOLUTE_PATH_TO_TALIB_HEADERS = The path to the ta-lib header files
|
24
|
+
** e.g. for Port: /opt/local/var/macports/software/ta-lib/0.4.0_0/opt/local/include/ta-lib
|
25
|
+
** e.g. for Homebrew: /usr/local/Cellar/ta-lib/0.4.0/include/ta-lib
|
26
|
+
* ABSOLUTE_PATH_TO_TALIB_LIBS = The path to the ta-lib lib files
|
27
|
+
** e.g. fo Port: /opt/local/var/macports/software/ta-lib/0.4.0_0/opt/local/lib)
|
28
|
+
** e.g. fo Homebrew: /usr/local/Cellar/ta-lib/0.4.0/lib
|
21
29
|
|
22
30
|
Now ta-lib can be used by using _require 'talib_ruby'_
|
23
|
-
|
31
|
+
Needs at least Mac OSX 10.5. Has not been tested on Windows, but works there too what i've heard.
|
24
32
|
|
25
33
|
h3. Example
|
26
34
|
|
@@ -52,4 +60,4 @@ h3. Useful links
|
|
52
60
|
|
53
61
|
* "TA-Lib Forum":http://www.tadoc.org/forum/index.php?board=9.0
|
54
62
|
* "XML explanation":http://ta-lib.svn.sourceforge.net/viewvc/ta-lib/trunk/ta-lib/ta_func_api.xml?view=markup of all supported Functions
|
55
|
-
* "C/C++ API Documentation":http://ta-lib.org/d_api/d_api.html
|
63
|
+
* "C/C++ API Documentation":http://ta-lib.org/d_api/d_api.html
|
data/example/ma.rb
CHANGED
@@ -11,10 +11,9 @@ a = Array.new
|
|
11
11
|
# setup input parameter
|
12
12
|
l.in_real(0,a);
|
13
13
|
# setup optional parameter
|
14
|
-
l.opt_int(0,k+2)
|
14
|
+
l.opt_int(0,k+2);
|
15
15
|
# setup output parameter
|
16
|
-
l.out_real(0,b)
|
17
|
-
lb = l.lookback
|
16
|
+
l.out_real(0,b);
|
18
17
|
l.call(0,9)
|
19
18
|
p "k=#{k+2}"
|
20
19
|
p b
|
data/ext/talib/talib.c
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#include "ruby.h"
|
2
|
-
#include
|
2
|
+
#include <ta-lib/ta_abstract.h>
|
3
3
|
|
4
4
|
static VALUE rb_mTaLib;
|
5
5
|
static VALUE rb_cTAFunction;
|
@@ -28,8 +28,8 @@ static VALUE rb_sOutParamInfo;
|
|
28
28
|
// combine all heap storage to this struct and free only this on ta_free
|
29
29
|
typedef struct _ph {
|
30
30
|
TA_ParamHolder *p;
|
31
|
-
|
32
|
-
|
31
|
+
double* in[IN_CNT]; // johnribera@Hotmail: the usual case (double)
|
32
|
+
double* out[OUT_CNT];
|
33
33
|
} ParamHolder;
|
34
34
|
|
35
35
|
/* :nodoc: */
|
@@ -104,7 +104,7 @@ static double* FLT2DBL(double **dest, VALUE in_array)
|
|
104
104
|
VALUE *inp;
|
105
105
|
int i;
|
106
106
|
|
107
|
-
if
|
107
|
+
if(NIL_P(in_array)) return 0;
|
108
108
|
|
109
109
|
inp = RARRAY_PTR(in_array);
|
110
110
|
if (*dest) free(*dest); // only on 1st use do we skip this step
|
@@ -289,6 +289,8 @@ static VALUE ta_func_setup_in_integer(VALUE self, VALUE param_index, VALUE in_ar
|
|
289
289
|
ret_code = TA_SetInputParamIntegerPtr( param_holder->p, FIX2INT(param_index), (int*)(RARRAY_PTR(in_array)));
|
290
290
|
if ( ret_code != TA_SUCCESS )
|
291
291
|
rb_raise(rb_eRuntimeError, "unsuccess return code TA_SetInputParamIntegerPtr");
|
292
|
+
|
293
|
+
return T_TRUE;
|
292
294
|
}
|
293
295
|
|
294
296
|
/*
|
@@ -298,35 +300,41 @@ static VALUE ta_func_setup_in_integer(VALUE self, VALUE param_index, VALUE in_ar
|
|
298
300
|
*/
|
299
301
|
static VALUE ta_func_setup_in_real(VALUE self, VALUE param_index, VALUE in_array)
|
300
302
|
{
|
303
|
+
double** dp;
|
301
304
|
TA_RetCode ret_code;
|
302
305
|
ParamHolder *param_holder;
|
303
306
|
|
304
307
|
Data_Get_Struct(self, ParamHolder, param_holder);
|
305
|
-
|
308
|
+
dp = param_holder->in;
|
306
309
|
//FIXME: memory leak fixed: johnribera@hotmail.com (see: FL2DBL())
|
307
310
|
ret_code = TA_SetInputParamRealPtr( param_holder->p, FIX2INT(param_index), FLT2DBL(&dp[FIX2INT(param_index)], in_array));
|
308
311
|
if ( ret_code != TA_SUCCESS )
|
309
312
|
rb_raise(rb_eRuntimeError, "unsuccess return code TA_SetInputParamRealPtr");
|
313
|
+
return T_TRUE;
|
310
314
|
}
|
311
315
|
|
312
316
|
static VALUE ta_func_setup_in_price(VALUE self, VALUE param_index, VALUE in_open, VALUE in_high, VALUE in_low, VALUE in_close, VALUE in_volume, VALUE in_oi)
|
313
317
|
{
|
318
|
+
double **dp;
|
314
319
|
TA_RetCode ret_code;
|
315
320
|
ParamHolder *param_holder;
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
321
|
+
Data_Get_Struct(self, ParamHolder, param_holder);
|
322
|
+
dp = param_holder->in;
|
323
|
+
|
324
|
+
ret_code = TA_SetInputParamPricePtr(
|
325
|
+
param_holder->p,
|
326
|
+
FIX2INT(param_index),
|
327
|
+
FLT2DBL(&dp[0], in_open),
|
328
|
+
FLT2DBL(&dp[1], in_high),
|
329
|
+
FLT2DBL(&dp[2], in_low),
|
330
|
+
FLT2DBL(&dp[3], in_close),
|
331
|
+
FLT2DBL(&dp[4], in_volume),
|
332
|
+
FLT2DBL(&dp[5], in_oi)
|
333
|
+
);
|
328
334
|
if ( ret_code != TA_SUCCESS )
|
329
335
|
rb_raise(rb_eRuntimeError, "unsuccess return code TA_SetInputParamPricePtr");
|
336
|
+
|
337
|
+
return T_TRUE;
|
330
338
|
}
|
331
339
|
|
332
340
|
/*
|
@@ -342,6 +350,8 @@ static VALUE ta_func_setup_opt_in_integer(VALUE self, VALUE param_index, VALUE v
|
|
342
350
|
ret_code = TA_SetOptInputParamInteger( param_holder->p, FIX2INT(param_index), FIX2INT(val));
|
343
351
|
if ( ret_code != TA_SUCCESS )
|
344
352
|
rb_raise(rb_eRuntimeError, "unsuccess return code TA_SetOptInputParamIntegerPtr");
|
353
|
+
|
354
|
+
return val;
|
345
355
|
}
|
346
356
|
|
347
357
|
/*
|
@@ -358,6 +368,8 @@ static VALUE ta_func_setup_opt_in_real(VALUE self, VALUE param_index, VALUE val)
|
|
358
368
|
ret_code = TA_SetOptInputParamReal( param_holder->p, FIX2INT(param_index), NUM2DBL(val));
|
359
369
|
if ( ret_code != TA_SUCCESS )
|
360
370
|
rb_raise(rb_eRuntimeError, "unsuccess return code TA_SetOptInputParamRealPtr");
|
371
|
+
|
372
|
+
return val;
|
361
373
|
}
|
362
374
|
|
363
375
|
/*
|
@@ -370,35 +382,47 @@ static VALUE ta_func_setup_out_real(VALUE self, VALUE param_index, VALUE out_arr
|
|
370
382
|
TA_RetCode ret_code;
|
371
383
|
ParamHolder *param_holder;
|
372
384
|
long idx = FIX2INT(param_index);
|
385
|
+
double **dp;
|
373
386
|
if (idx > 2)
|
374
387
|
rb_raise(rb_eRuntimeError, "param_index must be 0..2");
|
388
|
+
|
375
389
|
Data_Get_Struct(self, ParamHolder, param_holder);
|
376
390
|
rb_ary_store(rb_iv_get(self, "@result"), idx, out_array);
|
377
391
|
// FIXME: malloc w/o free: johnribera@hotmail.com fixed
|
378
|
-
|
379
|
-
|
392
|
+
dp = &(param_holder->out[idx]);
|
393
|
+
if (*dp) free(*dp); // not true only 1st time called (reusing same ptrs)
|
394
|
+
|
380
395
|
*dp = (double*)malloc(RARRAY_LEN(out_array) * sizeof(double));
|
381
396
|
ret_code = TA_SetOutputParamRealPtr(param_holder->p, idx, *dp);
|
397
|
+
|
382
398
|
if ( ret_code != TA_SUCCESS )
|
383
399
|
rb_raise(rb_eRuntimeError, "unsuccess return code TA_SetOutputParamRealPtr");
|
400
|
+
|
401
|
+
return out_array;
|
384
402
|
}
|
385
403
|
|
386
404
|
static VALUE ta_func_setup_out_integer(VALUE self, VALUE param_index, VALUE out_array)
|
387
405
|
{
|
388
406
|
TA_RetCode ret_code;
|
389
407
|
ParamHolder *param_holder;
|
390
|
-
|
408
|
+
long idx = FIX2INT(param_index);
|
409
|
+
int **ip;
|
391
410
|
if (idx > 2)
|
392
411
|
rb_raise(rb_eRuntimeError, "param_index must be 0..2");
|
412
|
+
|
393
413
|
Data_Get_Struct(self, ParamHolder, param_holder);
|
394
414
|
rb_ary_store(rb_iv_get(self, "@result"), idx, out_array);
|
415
|
+
|
395
416
|
// FIXME: malloc w/o free FIXED: johnribera@Hotmail.com
|
396
|
-
|
397
|
-
|
417
|
+
ip = (int**)&(param_holder->out[idx]);
|
418
|
+
if (*ip) free(*ip); // not true only very 1st time in
|
398
419
|
*ip = (int*)malloc(RARRAY_LEN(out_array) * sizeof(int));
|
399
|
-
|
420
|
+
|
421
|
+
ret_code = TA_SetOutputParamIntegerPtr( param_holder->p, idx, *ip);
|
400
422
|
if ( ret_code != TA_SUCCESS )
|
401
423
|
rb_raise(rb_eRuntimeError, "unsuccess return code TA_SetOutputParamIntegerPtr");
|
424
|
+
|
425
|
+
return out_array;
|
402
426
|
}
|
403
427
|
|
404
428
|
/*
|
@@ -443,7 +467,7 @@ static VALUE ta_func_lookback(VALUE self)
|
|
443
467
|
if ( ret_code != TA_SUCCESS )
|
444
468
|
rb_raise(rb_eRuntimeError, "unsuccess return code TA_GetLookback");
|
445
469
|
|
446
|
-
|
470
|
+
return INT2FIX(out_lookback);
|
447
471
|
}
|
448
472
|
|
449
473
|
void Init_talib()
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: talib_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 31
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 1
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
8
|
+
- 5
|
9
|
+
version: 1.0.5
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Valentin Treu
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date:
|
17
|
+
date: 2013-04-07 00:00:00 +02:00
|
19
18
|
default_executable:
|
20
19
|
dependencies: []
|
21
20
|
|
@@ -33,7 +32,6 @@ files:
|
|
33
32
|
- ext/talib/talib.c
|
34
33
|
- lib/talib_ruby.rb
|
35
34
|
- README.textile
|
36
|
-
- ext/talib/extconf.rb
|
37
35
|
has_rdoc: true
|
38
36
|
homepage: http://github.com/rivella50/talib-ruby
|
39
37
|
licenses: []
|
@@ -44,27 +42,23 @@ rdoc_options: []
|
|
44
42
|
require_paths:
|
45
43
|
- lib
|
46
44
|
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
-
none: false
|
48
45
|
requirements:
|
49
46
|
- - ">="
|
50
47
|
- !ruby/object:Gem::Version
|
51
|
-
hash: 3
|
52
48
|
segments:
|
53
49
|
- 0
|
54
50
|
version: "0"
|
55
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
52
|
requirements:
|
58
53
|
- - ">="
|
59
54
|
- !ruby/object:Gem::Version
|
60
|
-
hash: 3
|
61
55
|
segments:
|
62
56
|
- 0
|
63
57
|
version: "0"
|
64
58
|
requirements: []
|
65
59
|
|
66
60
|
rubyforge_project:
|
67
|
-
rubygems_version: 1.3.
|
61
|
+
rubygems_version: 1.3.6
|
68
62
|
signing_key:
|
69
63
|
specification_version: 3
|
70
64
|
summary: Ruby Wrapper for ta-lib
|