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.
- Michael J Bommarito II's blog
- Add new comment
- 1197 reads
Recent comments
6 days 7 hours ago
1 week 6 days ago
1 week 6 days ago
10 weeks 3 days ago
15 weeks 6 hours ago
15 weeks 1 day ago
17 weeks 4 days ago
17 weeks 5 days ago
18 weeks 3 days ago
19 weeks 6 days ago