Archive for the 'kdb+' Category
April 2nd, 2018 by admin
qStudio 1.45 Released, we have:
- Bugfix: Ctrl+F Search in source fixed. (Thanks Alex)
- Added Step-Plot Chart display option
- Added Stacked Bar Chart display option
- Added Dot graph render display option (Inspired by Noormo)
- Bugfix: Hidden folders/files regex now works again in file tree and command bar. Target and hidden folders are ignored by default.
- Bugfix: Mac was displaying startup error with java 9
Download
Some example charts:
April 2nd, 2018 by admin
Our standard time-series graph interpolates between points. When the data you are displaying is price points, it’s not really valid to always interpolate. If the price was 0.40 at 2pm then 0.46 at 3pm, that does not mean it could be interpreted as 0.43 at 2.30pm. Amazingly till now, sqlDashboards had no sensible way to show taht data. Now we do:

For comparison here is the same data as a time-series graph:

The step-plot is usable for time-series and numerical XY data series. The format is detailed on the usual chart format pages.
April 2nd, 2018 by admin
qStudio has added support for stacked bar charts:

The chart format for this is: The first string columns are used as category labels. Whatever numeric columns appear next are a separate series in the chart. Each row in the data becomes one stacked bar. The table for the data shown above for example is:
dt |
LSE |
BTS |
NAS |
ASE |
NYQ |
SES |
TSE |
HKG |
2018-03-30 |
1047 |
2120 |
592 |
25 |
3660 |
303 |
225 |
383 |
2018-03-29 |
1148 |
2118 |
528 |
10 |
3656 |
541 |
215 |
303 |
2018-03-28 |
1201 |
2085 |
555 |
17 |
3644 |
302 |
290 |
339 |
2018-03-27 |
1206 |
2182 |
535 |
21 |
3604 |
235 |
299 |
319 |
2018-03-26 |
1239 |
2041 |
515 |
16 |
3549 |
251 |
234 |
363 |
2018-03-25 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
2018-03-24 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
2018-03-23 |
1379 |
2115 |
595 |
29 |
3430 |
138 |
251 |
348 |
2018-03-22 |
1431 |
2179 |
517 |
25 |
3399 |
531 |
222 |
320 |
2018-03-21 |
1530 |
2032 |
558 |
29 |
3282 |
438 |
296 |
359 |
2018-03-20 |
1531 |
2134 |
520 |
23 |
3256 |
515 |
265 |
322 |
You may need to “kdb pivot” your original data to get it in the correct shape.
April 1st, 2018 by Ryan Hamilton
“The Financial Information eXchange (FIX) protocol is an electronic communications protocol initiated in 1992 for international real-time exchange of information related to the securities transactions and markets.”. You can see an example of a FIX message being parsed here.
What we care about is that an order goes through a lifecycle. From newly created to filled or removed. Anything that involves state-transitions or a lifecycle can be visualized as a graph. A graph depicts transitions from one state to another. Often SQL tables record every transition of that state. This can then be summarised into a count of the last state, giving something like the following:
From |
To |
label |
cnt |
PendingCancel |
Calculated |
Rejected |
50 |
PendingReplace |
Calculated |
Rejected |
10 |
PendingReplace |
Calculated |
Replaced |
40 |
Calculated |
PendingReplace |
PendingReplace |
50 |
Calculated |
Filled |
Trade |
9400 |
Calculated |
Calculated |
Trade |
5239 |
PendingCancel |
Removed |
Cancelled |
150 |
Calculated |
PendingCancel |
PendingCancel |
200 |
New |
Calculated |
Calculated |
9660 |
New |
Removed |
Rejected |
140 |
Created |
Removed |
Rejected |
300 |
Created |
New |
New |
9800 |
qStudio now automatically converts this result table to DOT format and if you have graphviz“>graphviz installed and on the PATH, will generate the following:

Note I did tweak the table a little to add styling like so:
update style:(`Filled`Removed!("color=green";"color=red")) To,label:(label,'" ",/:cnt) from currentFixStatus
The format is detailed again in our qStudio Chart Data Format page.
This is another even simpler example:

January 13th, 2018 by Ryan Hamilton
Notable events this year or possibly the previous year due to incoherent memory issues:
- KX went open on APIs – Improved and open sourced python, R, java and kafka interfaces.
- Java Driver – Got some new serialization functionality
- PyQ – KX acquired the rights
- The fusion/interface/machine-learning team at kdb promise to keep bringing improvements
- KX went to the cloud – There is now a cloud offering of kdb that is dynamically costed based on usage. It’s for existing customers only so far. Beta is available for personal use but kx may terminate access at any time. You can’t run it on third party “clouds”, no AWS I guess.and costs $0.10 per core <=4 cores, $0.05 per core >4 cores.
- Other users outside finance start to use kdb – It’s great to see and this probably flows from First Derivatives (FD) having purchased KX. However a number of them seem like proof of concepts pushed by FD to demonstrate it can be used. Hopefully in 2018 we will see more independently operating users.
- European Space Agency (ESA) – Al Worden an actual astronaut came to the London meetup with some great stories.
- Partnerships with redbull racing and marketing companies demonstrate possible growth opportunities
- Technical:
- Debugger with Stack Trace – You can now change the number of threads after startup
- uj/ij changes – A change in the behaviour of ij/lj joins means we now have ljf/ujf functions to provide historical equivalents. This is an old change but worth mentioning here as more people are only now upgrading from kdb 2.x
- Analyst – a jupyter notebook / tableau for kdb – KX launched an “analyst” product “a complete real time data transformation, exploration and discovery workflow. Using an intuitive point and click interface, the typical analyst can import, transform, filter, and visualize massive datasets without programming”
December 21st, 2017 by Ryan Hamilton
A quick post to highlight something a lot of people are bumping into with upgrades. The joins in 3.x for uj/ij and lj all changed how they treat nulls from the keyed table. In particular nulls now by default overwrite existing values. In the past nulls from the joining table did not overwrite and left the original value in the column. See the difference in the 3/three row shown below:
q)t:([] a:1 2 3; b:`one`two`three; c:1.0 2.0 3.0)
q)u:([a:2 3 4] b:`j``l; c:100 200 300.0)
q)t
a b c
---------
1 one 1
2 two 2
3 three 3
q)u
a| b c
-| -----
2| j 100
3| 200
4| l 300
q)t lj u / v3.x The null from u overwrites previous value in column b
a b c
---------
1 one 1
2 j 100
3 200
q)t ljf u / v2.0 or ljf - The original 3 value not overwritten by null
a b c
-----------
1 one 1
2 j 100
3 three 200
Other than the int/long indexing change this is one of the biggest breaking changes in migrating kdb 2.x to 3.x.
You may also enjoy our full kdb joins article.
April 13th, 2017 by Ryan Hamilton
qStudio 1.43 Released. This:
- Adds stack traces to kdb 3.5+
- Fixes the mac bug where the filename wasn’t shown when trying to save a file.
- Fixes a number of multi-threading UI problems
Download it now.
April 13th, 2017 by Ryan Hamilton
kdb+ 3.5 had a significant number of changes:
- Debugger – At long last we can finally get stack traces when errors occur.
- Concurrent Memory Allocator – Supposedly better performance when returning large results from peach
- Port Reuse – Allow multiple processes to listen on same port. Assuming Linux Support
- Improved Performance – of Sorting and Searching
- Additional ujf function – Similar to uj from v2.x fills from left hand side
kdb Debugger
The feature that most interests us right now is the Debugging functionality. If you are not familiar with how basic errors, exceptions and stack movement is handled in kdb see our first article on kdb debugging here. In this short post we will only look at the new stack trace functionality.
Now when you run a function that causes an error at the terminal you will get the stack trace. Here’s a simple example where the function f fails:
Whatever depth the error occurs at we get the full depth stack trace, showing every function that was called to get there using .Q.bt[]:

The good news is that this same functionality is availabe in qStudio 1.43. Give it a try: qStudio.
Note: the ability to show stack traces relies on qStudio wrapping every query you send to the server with its own code to perform some analysis and return those values. By default wrapping is on as seen in preferences. If you are accessing a kdb server ran by someone else you may have to turn wrapping off as that server may limit which queries are allowed. Unfortunately stack tracing those queries won’t be easily possible.
That’s just the basics, there are other new exposed functions and variables, such as .Q.trp – for trapping calls and accessing traces that we are going to look at in more detail in future.
February 27th, 2017 by Ryan Hamilton
qUnit has added a new HTML report to allow visually easily seeing the difference between expected kdb results and actual results. To generate a report you could call:
.qunit.generateReport[.qunit.runTests[]; `:html/qunit.html]

It’s also added a
.qunit.assertKnown[actualResult; expectedFilename; msg]
call to allow comparing an actual results to a file on disk. While allow easy updating of that file and avoiding naming collisions.
February 7th, 2017 by admin
This post is a walkthrough of my implementation in Q of the RosettaCode task ‘Death Star’.
The code is organized as general-purpose bitmap generator which can be used in other projects, and a client specific to the task of deathstar-drawing. The interface is a function which passes a map of pixel position to pixel value. The map can be a mapping function, or alternatively a 2D array of pixel values. The bitmap generator raster-scans the image, getting pixel values from either a mapping function or a mapped array.
genheader follows directly from the referenced BMP Wikipedia article.
genbitmap and genrow perform a raster scan of the image to be constructed. genbitmap steps along the vertical axis, calling genrow, which steps along the pixels of the current line, in turn calling fcn, the pixel-mapping function passed in by the client.
A sample client is included in comments, the simplest possible demonstration of shape and color (a circular mask selecting between two fill colors):
Conveniently, functions and arrays can be equivalently accessed in Q.
Here is an array-passing client which replicates the first example in the Wikipedia article on BMP format.
Element ordering can be confusing at first glance: Byte order for RGB pixels is B,G,R. Also, rows are indexed from bottom to top, and since bitmaps are in row-major order, the first and second array indices designated x and y correspond to the y and x image axes respectively.

After centering the image fcn applies several masks:
is calculates the orientation of a point on a sphere, and then a pixel value for that point, using the dot product of l, the light source direction, and s, the surface orientation. A correction of (1+value)/2 is applied, to achieve the ‘soft’ appearance of a space object in a movie. Alternatively we might have suppressed negative illumination values, to get the high-contrast appearance of an actual space object.
We might want to generate images of the death star at different rotations, however due to some simplifying assumptions we can’t rotate the weapon face to the side without glitching. We calculate z1 and z2 to select between the forward surface of the death star and the rearward surface of the weapon face. We should also calculate z3, the forward surface of the weapon face sphere, and z4, the rearward surface of the death star:
z3:170+z[x2;y;r];
z4:-z1;
Then the masks can be modified so that when z3 > z1 > z4 > z2, an additional bit of background is visible through the carved-out chunk of the deathstar.
TODO: discuss limitations of mask-and-fill; alternative approaches; display-list; …
TODO: discuss animation; …
TODO: discuss three-component architecture: orchestrator, world, bitmap generator
TODO: … conclusions