{idx:where d=max d:x-y;(y[idx],x[idx])}[|\[last a;reverse a];a]
6.02 8
This assumes we have all the data a-priori and can run the time series backwards. You will need a different solution for a streaming dataset.
Mark Lefevre
--
You received this message because you are subscribed to the Google Groups "AquaQ TorQ" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kdbtorq+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/kdbtorq/9837ad81-a4f6-4b21-baa9-95c517b93b38%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
q) maxspread:{$[((x@1)-x@2)<(y@1)-y@2;y;x]}
q) findmax:{?[x>y;x;y]}
q) findmin:{?[x<y;x;y]}
q) reverse 1_maxspread/[3#0;{{{(z;min x; max y)}[findmax\[a@x;reverse a];findmin\[a@y-x+1;a];x]}[x;count a]}each til floor 0.5*count a]
6.09 7.97
Simon Tsang | Programmer Anaylst Advisory | Application Development – Fixed Income
Scotiabank |
Global Wholesale and Wealth Technology
320 Bay St, 13th floor, Toronto, Ontario, Canada M5H 4A6
T 1.416.860-1764
Scotiabank is a business name used by The Bank of Nova Scotia
--
You received this message because you are subscribed to the Google Groups "AquaQ TorQ" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kdbtorq+u...@googlegroups.com.
To view this discussion on the web, visit
https://groups.google.com/d/msgid/kdbtorq/9837ad81-a4f6-4b21-baa9-95c517b93b38%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Sorry, forgot the handle the case so that we are not buying in the future.
Here’s the query:
q) maxspread:{$[(0f<y@1) and (0f<y@2) and ((x@1)-x@2)>(y@1)-y@2;y;x]}
q) findmax:{?[x>y;x;y]}
q) findmin:{?[x<y;x;y]}
q) 1_maxspread/[3#0;{{{buy:min x; sell:max y where y>buy;(z;buy;sell)}[findmax\[a@x;reverse a];findmin\[a@y-x+1;a];x]}[x;count a]}each til floor 0.5*count a]
6.43 7.62
Regards,
Simon Tsang | Programmer Anaylst Advisory | Application Development – Fixed Income
Scotiabank |
Global Wholesale and Wealth Technology
320 Bay St, 13th floor, Toronto, Ontario, Canada M5H 4A6
T 1.416.860-1764
Scotiabank is a business name used by The Bank of Nova Scotia
To view this discussion on the web, visit https://groups.google.com/d/msgid/kdbtorq/A3A26B73B6B60C44B8CFF2B710E8986F37E3AB2B%40SCTORMAIL204.scglobal.ad.scotiacapital.com.
Hi all,
I should also consider the case by finding the best buy from the sell, and the best sell from the buy:
q) maxspread:{$[(0f<y@1) and (0f<y@2) and ((x@1)-x@2)>(y@1)-y@2;y;x]}
q) findmax:{?[x>y;x;y]}
q) findmin:{?[x<y;x;y]}
q) 1_maxspread/[3#0;raze{{{buy:min x where x<last y;sell:max y where y>first x;((z;buy;first y);(z;first x;sell))}[findmin\[a@x;a];findmax\[a@y-x+1;a];x]}[x;count a]}each til floor 0.5*count a]
q) 6.02 7.92
To view this discussion on the web, visit https://groups.google.com/d/msgid/kdbtorq/A3A26B73B6B60C44B8CFF2B710E8986F37E3AB7D%40SCTORMAIL204.scglobal.ad.scotiacapital.com.
Still haven’t seen a right answer.
Anyway, here’s another shot:
q) 1_{$[((-). 1_x)>(-). 1_y;y;x]}/[3#0;{{{(z;x;max y where y>x)}[a@x;|\[a@y-x+1;a];x]}[x;count a]}each til floor 0.5*count a]
6.13 8
Regards,
Simon Tsang | Programmer Anaylst Advisory | Application Development – Fixed Income
Scotiabank |
Global Wholesale and Wealth Technology
320 Bay St, 13th floor, Toronto, Ontario, Canada M5H 4A6
T 1.416.860-1764
Scotiabank is a business name used by The Bank of Nova Scotia
--
You received this message because you are subscribed to the Google Groups "AquaQ TorQ" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
kdbtorq+u...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/kdbtorq/953cf097-802b-4ac9-b2bf-3bb11d9743c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "AquaQ TorQ" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kdbtorq+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/kdbtorq/9837ad81-a4f6-4b21-baa9-95c517b93b38%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "AquaQ TorQ" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kdbtorq+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/kdbtorq/60b4972a-0c07-4acc-9b81-204221f55c83%40googlegroups.com.
l:7.67 6.74 6.72 7.27 7.09 6.95 6.39 7.34 6.9 7.4 6.47 6.78 6.91 7.95 6.72 7.85 6.62 6.21 7.68 7.41 6.19 6.23 6.15 7.97 6.5 7.97 6.13 7.88 7.31 6.92 6.76 6.14 7.09 7.59 6.37 6.63 6.24 6.66 6.43 7.64 6.15 7.64 7.32 7.92 7.16 7.41 6.77 6.93 6.57 8 6.52 7.52 6.26 6.55 6.13 7.53 6.24 7.01 6.06 6.52 6.28 7.62 7.65 6.92 7.01 7.06 7.83 6.5 6.04 6.74 7.8 7.4 6.93 6.87 6.35 6.22 6.09 6.59 6.29 7.25 6.49 7.77 7.21 7.63 6.23 7.63 6.6 6.14 6.18 7.2 7.92 7.76 7.24 7.37 6.46 6.09 6.62 7.63 6.92 6.02;d:()!();
{ls:l[til x];rs:l[x+til neg[x]+count l];d[max[rs]-min[ls]]:(max[rs];min[ls])} each til count l;
d max key d;
--
You received this message because you are subscribed to the Google Groups "AquaQ TorQ" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kdbtorq+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/kdbtorq/9837ad81-a4f6-4b21-baa9-95c517b93b38%40googlegroups.com.