Calculating the Kappa Function: Matlab MEX Code

    Last week, I'd provided a Matlab function to calculate the Kappa, Omega, and Sortino ratios in one line.  There are, however, a number of memory and performance constraints with this function, and thus I have written a Matlab MEX C function to calculate Kappa.

    As an example, the following is a comparison of the speed of calculating the Omega ratio (minus one) at return threshold 0 for 16 assets over 1 million historical log-returns.  The first is the method mentioned in Matlab's documentation, the second is the function I'd given last week, and the third is the new Matlab MEX function.  These times are calculated on a dual Xeon 3.4GHz with 4GB RAM with Matlab R2007a, multithreading enabled. 

    You can download the Kappa MEX function's source here.  To compile it, type 'mex -O kappaC.c' from the Matlab console.  Your mileage may vary, but

>> ts = normrnd(0.0001, 0.01,10^6,16);
>> r = 0;
>> n = 1;
>> tic; lpm(-ts, -r, n) ./ lpm(ts, r, n); toc;
Elapsed time is 24.898883 seconds.

>> tic; kappa(ts,r,n); toc;
Elapsed time is 1.999696 seconds.

>> tic; kappaC(ts,r,n); toc;
Elapsed time is 0.884618 seconds.