Top Posts
Categories
- KDB (6)
- Pricing (4)
- Q (17)
- Q Idioms (3)
- Regression (3)
- Regular Expressions (3)
- Time Series (1)
-
Join 18 other subscribers
Archives
Tag Cloud
Blog Stats
- 73,304 hits
Category Archives: Q
msum using sliding window in kdb+
I implemented the msum verb in kdb+ using the sliding window code. First step is to find the sliding window function in q using scan operator : q)sw:{{1 _ x, y}\[x#0;y]} q)y 1 6 21 56 The first argument of … Continue reading
Generate all subsets of a string in q/KDB+
Input : “abc” Here, the elements “a”,”b”,”c” represent the elements of the set. Output : “abc”, “ab”,”ca”,”bc”,”a”,”b”,”c”,””. The output represents all subsets of the set containing the elements “abc”. Q Code : subsets:{[s1;s2] $[(count s2)=0;show s1;[.z.s[string `$s1,(first s2);1_s2];.z.s[s1;1_s2]]]} Run it … Continue reading
Posted in Q
Leave a comment
Cumulative Normal Distribution in Q/KDB+
I have implemented the numerical approximation for the normal cumulative distribution function(cdf) here. Normal cdf is very important in financial mathematics because of its applications, one of them being in Black Scholes pricing. Mathematically, can be expressed as : Q … Continue reading
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
Equality of Strings in q/KDB+
I came across an error and in the process of solving it discovered more about regular expressions in q. I will list the problem first. I created a fictitious table named t for the same. q)t sym price volume ——————— … Continue reading
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
Generate all permutations in q/KDB+
My solution : perm:{[s] $[(count s)=1;s;[p:(rotate[1]\)s;raze((string first each p),/:’perm each 1_/:p)]]} Results : perm “a” “a” perm “ab” “ab” “ba” perm “abc” “abc” “acb” “bca” “bac” “cab” “cba” The kdb+ personal developers blog contains a thread on generating all the … Continue reading
Exponential Smoothing in q/KDB+
The formula for exponential smoothing is : S(1) = Y(0) S(t) = Alpha * Y(t) + (1-Alpha) S(t-1) 1) The corresponding solution in Q is : es:{{(x*z)+(1-x)*y}[x]\[y]} where, x is the smoothing factor(Alpha) and y is the list containing the … Continue reading
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
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