performant maximum drawdown calculation

312 views
Skip to first unread message

kuentang

unread,
Mar 19, 2012, 9:19:40 AM3/19/12
to Kdb+ Personal Developers

Hi everyone,

just a quick question about performant maximum drawdown calculation.

pnl:num cut 10f+((pnum:10000)*num:5*252)?20.0
value "\\t mdds:{([]x)} last maxs first flip 1_{p:(x[1],enlist y);(max
p-count[p]#enlist y;p)} scan enlist[(0;())], flip pnl"

On my machine it takes about 204 secs to calculate the maximum
drawdown for 10000 paths. Each path has 1260 points.

Is it possible to speed up the calculation?

Regards,
Kim

JK

unread,
Mar 21, 2012, 4:38:32 PM3/21/12
to personal...@googlegroups.com
\t mdds:{([]x)} last maxs first flip 1_{p:(x[1],enlist y);(max p-count[p]#enlist y;p)} scan enlist[(0;())], flip pnl
/takes about 145000ms

\t foo: {max neg x-maxs x} each pnl
/takes about 145ms

foo~mdds`x
/1b

John

Kim Kuen Tang

unread,
Mar 22, 2012, 2:18:51 AM3/22/12
to personal...@googlegroups.com


Cool,
it is really that fast.

In my implementation i try to avoid each since most of the time this is the bottleneck. But in this case it is not.

I also compare these two calculations:

value "\\t r1 : {max neg x-maxs x} each pnl"
value "\\t r2 : {max neg x-maxs x} pnl"

Again the first one is faster.

Is there a reason?

Kim
--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/personal-kdbplus/-/-DMYow7ogUYJ.
To post to this group, send email to personal...@googlegroups.com.
To unsubscribe from this group, send email to personal-kdbpl...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/personal-kdbplus?hl=en.

Reply all
Reply to author
Forward
0 new messages