Monday, May 28. 2012
I've just wrote a wrapper extension to the TA-Lib - the technical analysis library. It includes over 150 market analysis indicators and some of vector math functions. The ext is primarily intended to help finance software developers to analyse market data with PHP. Nevertheless I think it wouldn't help to forecast the recently blowed Facebooks IPO
If you've already worked with TA-Lib Java or .NET implementations, you'll be probably fine with the trader extension as well. A slight difference here is that the routine signatures has been simplified to fit more typical PHP users needs. A short example would be where TA-Lib signature has
TA_RetCode TA_AD( int startIdx, int endIdx, const double inHigh, const double inLow, const double inClose, const double inVolume, int *outBegIdx, int *outNBElement, double outReal );
a PHPs one has
array trader_ad(array high, array low, array close, array volume)
Using a typical data source in PHP like a DB offers a possibility to get and process data in chunks. Given you had a DB table with the columns high, low, close and volume the select operation could be indexed by columns so completely prepared data can be delivered for the above trader_ad() function.
$dbh = new PDO('mysql:dbname=testdb;host=127.0.0.1'); $sql = 'SELECT `high`, `low`, `close`, `volume` FROM `stock` LIMIT 1000'; $sth = $dbh->prepare($sql); $sth->execute(); $data = $sth->fetchAll(PDO::FETCH_ASSOC); $ad = trader_ad($data['high'], $data['low'], $data['close'], $data['volume']);
The SQL facility to limit the amount of data makes also some args in the original signatures obsolete (I'm talking about the end and start index, etc.). Instead PHP will always start processing by zero and end with the smallest element count of the passed arrays. You should just precisely select the necessary segment of data.
Apart from the stock routines there are also some math vector routines which could be useful in your daily work. For instance trader_add() will do vector addition of two one dimensional arrays, trader_acos() will calculate anti-cousine for each element in a one dimensional array, etc.
The ext is marked alpha for now despite TA-Lib is very stable. So just get it from PECL, use it, report bugs, suggest improvements and it'll find it's way to stable
More information about the TA-Lib, technical analysis and financial indexes can be drawn under
Display comments as (Linear | Threaded)
I am soooo excited about this.
I am having a little trouble compiling it on my system. I sent you an email but I just found this as well. Thank you for making this!
You can see my problem at:
it's most likely a paths issue. If you consider the following line
/bin/sh /private/tmp/pear/temp/pear-build-rootpwFTIe/trader-0.2.1/libtool --mode=compile cc -I. -I/private/tmp/pear/temp/trader -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-rootpwFTIe/trader-0.2.1/include -I/private/tmp/pear/temp/pear-build-rootpwFTIe/trader-0.2.1/main -I/private/tmp/pear/temp/trader -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/private/tmp/pear/temp/trader/ta-lib/include -I/private/tmp/pear/temp/trader/ta-lib/src/ta_common -I/private/tmp/pear/temp/trader/functions -DHAVE_CONFIG_H -g -O2 -c /private/tmp/pear/temp/trader/ta-lib/src/ta_common/ta_global.c -o ta-lib/src/ta_common/ta_global.lou
everywhere is an absolute path and at the end is a relative one. Looks like it tries to compile under two different paths. I have unfortunately no mac mashines to test it. Will try to get some, but that could take some time.
You could unpack the tarball and play with config.m4 - that's where it should be fixed
Could you please try the latest config.m4 from trunk http://svn.php.net/viewvc/pecl/trader/trunk/config.m4?revision=326807&view=markup ?
I had a quick question about returned data.
I fed the trader_ema with 86 entries and a period of 20, Do you know why it would only return 48 entries?
I've fixed this in trunk. It was a trivial bug in my implementation. Could you please try it?
Thank you!!! Thank you especially for getting to this so quickly! I am in the middle of heavy development and I am using these functions a lot!
Do you know if there are more functions that TA-lib offers that have not been implemented yet?
Such as Negative Volume Index? I believe that they are part of the ta-lib, but I am not sure.
If there are more in the ta-lib, do you know when or if you are going to implement them?
I would love to help in any way I can, but my knowledge is limited when it comes to programming in C.
all the TA-Lib functions should be implemented now. You can browse here http://www.ta-lib.org/function.html for the list, but also under http://lxr.php.net/xref/PECL/trader/ta-lib/src/ta_func/ where all the currently implemented functions are listed. I might be missing something of course, but actually shouldn't
You're helping already very much just using the trader ext and giving the feedback which helps to fix bugs. If you had mood, you could also write tests and help to make the php docs more reasonable.
Conserning the new implementations - as the ext is based on the TA-Lib, the additions should be implemented in it first, go back to the TA-Lib community. This were a meaningful way to add more indexes to the PHP ext then. Unfortunately I've not that much time to extend TA-Lib at the moment, but when it becomes a new release, of course I'll take it over into the trader ext.
Do all of the functions have the ability to pass a moving average type or only a select few? Are the parameters you have specified in the docs with each function the only parameters available for that function?
For example: The Relative Strength Index function (trader_rsi) is sometimes calculated with an exponential moving average instead of Wilder's accumulative moving average. I would like to be able to pass in an moving average type just like I can with trader_ma.
Also, do you know what integers correspond with which MA type?
I tried to ask in the ta-lib forum but I did not get a response.
TA-Lib forum seems to be dead, recently i've tried to register there but my request still wasn't approved. Will try on sourceforge next time )
A quick grep gave me the list of the functions supporting MA
I'm not sure, but trader_stochrsi is the one you might be looking for.
And yes, each function in the trader ext implements all the available args it ta-lib. Except - as I've wrote in this article, array index args are not present in php signatures. All the effective args should be there.
For types the TRADER_MA_TYPE_* constants are usable. Just look here http://de.php.net/manual/en/trader.constants.php . That's what i've also meant on improving the documentation
Great to know, thank you again.
Those constants will be extremely useful.
Hi, I am having trouble installing this. The PHP Trader PECL seems to be broken, using PHP5.3.
sudo pecl install trader-beta
/tmp/pear/temp/trader/trader.c:1225:2: error: 'PHP_FE_END' undeclared here (not
in a function)
make: *** [trader.lo] Error 1
It's the same issue that's been reported here:
Any help would be really appreciated as I'm stuck. Thanks!
Having problems on my Raspberry Pi (ARMv6) with PHP5.4.4 + PEAR 1.9.4 and trader0.3.0 during the ./configure phase:
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... configure: error: in `/home/gene/setups/trader-0.3.0':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
can it compile other extensions? Looks more like it fails to determine the platform or like that. I've no raspberry pi unfortunately. Are there some comparable emulators yet?