Category Archives: KDB

N Queens : all possible solutions in q/kdb+

I have written the code to generate all possible solutions for the N Queens problem. I have used backtracking approach, which allows me to generate all the solutions. Whenever, a solution is found I print it and then backtrack to … Continue reading

Posted in KDB, Q | Tagged , | Leave a comment

Regular Expressions in q/KDB+

The verb like is used for matching regular expressions in q/KDB+. Usage : X like Y. Reserved characters for pattern matching in q : a) “?” matches a character b) “*” matches a sequence of characters c) “[]” is used … Continue reading

Posted in KDB, Regular Expressions | Tagged | Leave a comment

Shorter Code to Generate all Permutations of a string in q/KDB+

My new Solution : perm:{[s] $[(count s)=1;s;raze {(first x),/:perm 1_x}each (rotate[1]\)s]} My old Solution : perm:{[s] $[(count s)=1;s;[p:(rotate[1]\)s;raze((string first each p),/:’perm each 1_/:p)]]} Variant of my old Solution : perm:{[s] $[(count s)=1;s;[p:(rotate[1]\)s;raze((string first each p),/:’.z.s each 1_/:p)]]} The .z.s function … Continue reading

Posted in KDB, Q | Tagged | Leave a comment

Publication on KDB

Its a lazy sunday morning and the first time I felt that high temperatures are coming back to the city. Winter is over. Perfect time, not to go out of home, cozily sit in your room and do some random … Continue reading

Posted in KDB, Q | Tagged | Leave a comment

Bond Vauation – Present Value Approach in Q/KDB+

Let, c denote the cash flow, t denote the time frame, d denote the discount rate, pv denote the present value of the cash flows, M the face value then PV = (c/d + c/d^2 + … + c/d^n) + … Continue reading

Posted in KDB, Pricing, Q | Tagged | Leave a comment

Matrix operations in Q/KDB+

1) Find the maximum element of each column in matrix m. max m 2) Find the minimum element of each row of a matrix m. min each x. 3) Test for symetric matrix m~flip m 4) Test for anti-symetric matrix … Continue reading

Posted in KDB, Q | Leave a comment