Technical Analysis in Finance using PDL - An Introduction.

In early 2013 I came across PDL and was surprised at its quality and applicability to large data sets which exist in the finance/trading world if you consider intra-day data which is stored tick by tick. You can easily run into 100,000 or more ticks in a few hours and tools like R and Excel become really slow for performing complex analysis and researching models.
Inevitably, all work was then done in C/C++ to leverage performance.

I finally found time to learn PDL and to learn to use it to perform Technical Analysis on data such as stock quotes. My aim is to learn how to use PDL efficiently and write a technical analysis library that mirrors what may already be available for C/C++ using say TA-Lib and other custom libraries that may be written in-house.

With this in mind I started writing PDL::Finance::TA which I shall expand as time progresses to contain all possible technical analysis functions and more. Hopefully, this project will enable me to learn PDL, and provide other Perl users tools to quickly use PDL to perform financial modelling and maybe make some money.

As of today, 4th January 2014, PDL::Finance::TA has only one function movavg which is the moving average over a single dimension of data. In other words, it is a simple smoothing filter. Simple Moving Averages are a very common technical analysis tool that are used in conjunction with other tools which I will get to in the future write-ups.

Here is a quick way to use the movavg function:

use PDL;

use PDL::Finance::TA 'movavg';

my $p = sequence(50);

my $ma13 = $p->movavg(13);

Another example is provided in which downloads end-of-day quotes from Yahoo! Finance and plots the 5, 13 and 21 day moving averages on the close prices for 1 year. Below is a screenshot of what that looks like using PDL::Finance::TA and PDL::Graphics::PGPLOT.

Screen Shot 2014-01-04 at 12.50.19 AM.png

As time progresses, more functions and examples shall be added demonstrating the use of PDL in performing financial research.

1 Comment

Hi Vikas,
how to use "PDL::Finance::TA and PDL::Graphics::PGPLOT" to get picture like above and more others...?
"As of today, 4th January 2014, PDL::Finance::TA has only one function movavg..."
What about today, one year after...?

Leave a comment

About Vikas Kumar

user-pic I use Perl.