performant maximum drawdown calculation

Hi everyone,just a quick question about performant maximum drawdown calculation.pnl:num cut 10f+((pnum:10000)*num:5*252)?20.0value "\t mdds:{(x)} last maxs first flip 1_{p:(x[1],enlist y);(maxp-count[p]#enlist y;p)} scan enlist[(0;())], flip pnl"On my machine it takes about 204 secs to calculate the maximumdrawdown for 10000 paths. Each path has 1260 points.Is it possible to speed up the calculation?Regards,Kim

\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

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

Am 21.03.2012 21:38, schrieb JK:

\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

On Monday, March 19, 2012 6:19:40 AM UTC-7, kuentang wrote:

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


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-kdbplus@googlegroups.com.
To unsubscribe from this group, send email to personal-kdbplus+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/personal-kdbplus?hl=en.