# Ta-lib port using SWIG

**URL:** <https://www.ruby-forum.com/t/ta-lib-port-using-swig/88654>\
**Category:** Ruby\
**Created:** [March 13, 2007, 11:20am UTC](https://www.ruby-forum.com/t/ta-lib-port-using-swig/88654 "2007-03-13T11:20:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BENI](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BENI](https://www.ruby-forum.com/u/BENI)\
**Post date:** [March 13, 2007, 11:20am UTC](https://www.ruby-forum.com/t/ta-lib-port-using-swig/88654/1 "2007-03-13T11:20:43Z")

</div>

ta-lib is a collection of math/statistical functions for estimating  
price variablity of stock prices.

There is no port that exists for ruby.

Since I needed one so thought of building.

I followed the pick axe book.

Finally as there are about 120 functions to port so thuoght of using  
SWIG.

I have gone through SWIG doc anf series of mails in comp.lang.ruby  
but still some how I am unable to get the ball rooling.

I am particularly struck whether i would need to write some extra  
typemap in swig given my C header of one of the function

# ================== TA\_RetCode TA\_MA( int startIdx, int endIdx, const double inReal[], int optInTimePeriod, int optInMAType, int \*outBegIdx, int \*outNbElement, double outReal[], )

# In C

Lets say you wish to calculate a 30 day moving average using closing  
prices. The function call could look as follow:

TA\_Real closePrice[400];  
TA\_Real out[400];  
TA\_Integer outBeg;  
TA\_Integer outNbElement;

/\* … initialize your closing price here… \*/

retCode = TA\_MA( 0, 399,  
&closePrice[0],  
30,TA\_MAType\_SMA,  
&outBeg, &outNbElement, &out[0] );

# /\* The output is displayed here \*/ for( i=0; i \< outNbElement; i++ ) printf( “Day %d = %f\n”, outBeg+i, out[i] );

Given this API do I need to write special typemap for arguments  
like…const double inReal[],int \*outBegIdx,int  
\*outNbElement,double outReal[]

Can anyone give me a lead???
