Forum Replies Created

Page 8 of 8
  • davidcrossey

    Member
    November 29, 2021 at 12:00 am in reply to: .Q.hdpf throws ` type Error.

    I’m not certain, but using a simple example, column order in .d file doesn’t appear to impact the operation of .Q.dpft (which is called by .Q.hdpf):

    q)get hsym `$"./2021.11.25/t/.d" 
    `sym`qty`price 
    
    q)get hsym `$"./2021.11.26/t/.d" 
    `sym`price`qty 
    q)\l . 
    q)t 
    date       sym  price   qty 
    ---------------------------- 
    2021.11.25 akjl 90.30751 2 
    2021.11.25 amge 91.49882 33 
    2021.11.26 jobl 64.2737  39 
    2021.11.26 lfjp 38.69818 48

    One can check through the definition of .Q.hdpf to see what it’s doing; granted it’s implemented in k), however you can see some clear parts:

    q).Q.hdpf 
    k){[h;d;p;f](@[`.;;0#]dpft[d;p;f]@)'t@>(#.:)'t:.q.tables`.;if[h:@[hopen;h;0];h"\l .";>h]}

    which as per link in my initial response aligns to this statement of 3 parts:

    “Saves all tables by calling .Q.dpft, clears tables, and sends reload message to HDB.”

    The question to ask yourself is where is it failing?

    If the data is being saved to your HDB then it’s getting past the .Q.dpft call. The type error could be coming from the reload, where you RDB is trying to reload the HDB via handle ‘h’. Are you passing an HDB handle to your process as the first parameter, is that handle valid etc

  • davidcrossey

    Member
    November 23, 2021 at 12:00 am in reply to: .Q.hdpf throws ` type Error.

    Hi k-mambo,

    A type error is a very general error, meaning it could be any number of issues.

    The best place to start would be to confirm what arguments you are passing to .Q.hdpf and that each of the parameters are of the correct type as per .Q.hdpf

     

    .Q.hdpf[historicalport;directory;partition;`p#field]

     

    Additional resources:

    Thanks for sharing your question on the KX Community!

    Hope this helps,

    David

  • davidcrossey

    Member
    November 22, 2021 at 12:00 am in reply to: kdb equivalent of pandas groupby

    Hi powerpeanuts,

    I would keep it simple as you have it, and change select to update in your example as follows:

    q)update change:0^price-prev[price] by sym from trade 
    time       sym price size change 
    ----------------------------------- 
    09:30:00.000 a 10.75  100 0 
    09:31:00.000 a 11.75  100 1 
    09:32:00.000 a 13.2   100 1.45 
    09:30:00.000 b 100.75 100 0 
    09:31:00.000 b 106.95 100 6.2 
    09:32:00.000 b 123.95 100 17

    Note, I’ve also used fill (^) here to set the first change value for each sym as 0; this is optional and you can leave it as null if you prefer.

    Hope this helps and answers your question.

    Kind regards,

    David

  • davidcrossey

    Member
    November 21, 2021 at 12:00 am in reply to: How to print a newline character

    Hi mamsds,

    Have a look at this thread: Show or 0N! – KX Community 

    Hope this helps,

    David

  • davidcrossey

    Member
    November 16, 2021 at 12:00 am in reply to: Referencing new column

    Hi powerpeanuts,

    You would need to add your new column first, before trying to use it in the where clause. For example:

    q)t:([] name:`Dent`Beeblebrox`Prefect; iq:98 42 126) 
    q)select name, iq2 from (update iq2:iq%100 from t) where iq2>1 
    name    iq2 
    ------------ 
    Prefect 1.26

    Thanks for posting your question on the KX Community. Great username too!

    Kind regards,

    David

  • davidcrossey

    Member
    November 9, 2021 at 12:00 am in reply to: Use .Q functions or not

    Hi codh,

    Thanks for your query on the KX Community!

    @kjame is spot on here .Q namespace tool usage is encouraged as it provides a lot of useful functionality. Users should only use the publicly documented API as per The .Q namespace.

    Undocumented functions are subject to change without warning or notice as per the disclaimer in .q.k – usage is at the user’s own risk.

    We can look into documenting changes to the publicly documented API as these occur.

    Kind regards,

    David

     

  • davidcrossey

    Member
    November 5, 2021 at 12:00 am in reply to: Partitioning Tables Intraday by Custom Fields?

    Hi Leah,

    A kdb logfile typically has the form of (func;tabName;tabData), which can be as simple as f:{upsert[x;y]}. There isn’t anything special in terms of replaying the data into the kdb process, but more so to do with saving down the data.

    Assuming you mean to save to another date, you could simply pull out a date from the data (after replay) and use it as a parameter for your save down logic.

    If you mean at a higher level on partitioning the data differently across the entire database, data can be partitioned by any column of types date, month, year and int (1, 2), so depending on the requirements you could map values to a specific int based partition schema (3).

    Hope this helps!

    Kind regards,

    David

    References:

    1. 14. Introduction to Kdb+ – Q for Mortals (kx.com)
    2. Partitioned tables | Knowledge Base | kdb+ and q documentation – Kdb+ and q documentation (kx.com)
    3. Multi-partitioned kdb+ databases: an equity options case study | White Papers | kdb+ and q documentation – Kdb+ and q documentation (kx.com)
  • davidcrossey

    Member
    October 19, 2021 at 12:00 am in reply to: KDB Geom/Trig

    Hi planefan,

    Radians tend to be the more natural unit when working with angles than degrees, and you’ll find they are typically the default unit in most languages.

    KDB doesn’t have built in support for degrees, however you can work in degrees by converting to radians and rounding your results.

    For example:

     

    q)deg:0,0+12#30 
    q)deg 
    0 30 60 90 120 150 180 210 240 270 300 330 360 
    q)pi:3.141592653589793 
    q)round:{(10 xexp neg x)*`long$y*10 xexp x}[3;] /3 dp; change as necessary 
    q)deg!round sin deg*pi%180 
    0  | 0 
    30 | 0.5 
    60 | 0.866 
    90 | 1 
    120| 0.866 
    150| 0.5 
    180| 0 
    210| -0.5 
    240| -0.866 
    270| -1 
    300| -0.866 
    330| -0.5 
    360| 0

     

    You can set the above as a function for easier re-use; and also swap sin, for cos or tan, although be careful with tan(90) and tan(270) which should be be set to null / undefined.

    Kind regards,

    David

  • davidcrossey

    Member
    October 18, 2021 at 12:00 am in reply to: KDB Geom/Trig

    Hi planefan,

    Thanks for posting your query on KX Community!

    For the angles you are trying to solve, are you working in degrees or radians?

    KDB assumes a radian input, see here using sin as an example. You can see how to convert between degrees and radians on Geometry and trigonometry

    Kind regards,

    David

  • davidcrossey

    Member
    October 13, 2021 at 12:00 am in reply to: retrieving values

    Hi MEdan,

    It depends if your variable is a dictionary or a table as this flips the indexes:

    • dictionary = d[key;index]
    • table = t[index;key]

    For example:

     

    q)d:`name`iq!(`Dent`Beeblebrox`Prefect;98 42 126) 
    q)d 
    name| Dent Beeblebrox Prefect 
    iq  | 98 42 126 
    q)t:flip d 
    q)t 
    name       iq 
    -------------- 
    Dent       98 
    Beeblebrox 42 
    Prefect    126
    
    q)d[;2] 
    name| `Prefect 
    iq  | 126 
    
    q)d[`name;] 
    `Dent`Beeblebrox`Prefect 
    q)d[`name;2] 
    `Prefect 
    q)t[2;] 
    name| `Prefect 
    iq  | 126 
    
    q)t[;`name] 
    `Dent`Beeblebrox`Prefect 
    q)t[2;`name] 
    `Prefect

     

    Passing only the symbol to either dictionary or table will return the associated values key/column:

     

    q)d `iq 
    98 42 126 
    q)t `iq 
    98 42 126

     

    Further reading:

    Thanks for posting your query on the portal!

    Kind regards,

    David

  • davidcrossey

    Member
    October 10, 2021 at 12:00 am in reply to: embedPy: q list imported as numpy array

    Hi Simon,

    Please find some insight from our team as follows;

    embedpy defaults to numpy arrays because that makes a lot more sense for the typical usage pattern.

    numpy arrays behave enough like lists that this is usually not a problem.

    In a rare case that it is, it’s reasonable to do explicit conversion by calling list(). it’s exposed to q as .p.list, so e.g. to pass a float vector to print() as a python list instead of a numpy array,

     

    q).p.print .p.list 1 2 3f 
    [1.0, 2.0, 3.0]

     

    That’s exactly the same as doing that in python, but saves defining a function

     

    q).p.eval["lambda x:print(list(x))";1 2 3f] 
    [1.0, 2.0, 3.0]

     

    Thanks for adding your question on the portal!

    Kind regards,

    David

  • davidcrossey

    Member
    October 9, 2021 at 12:00 am in reply to: Largest float value KDB can handle

    Hi ekallivrousis,

    The largest decimal value would be the float type as per Data types

    q)(2 xexp 1023)*1+1-2 xexp -52 
    1.7976931348623157e+308

    See here for more Double-precision floating-point format

    Also note that the q console can only display float values to 17 significant figures, e.g.

    q)P 
    7i 
    q)1.123456789 
    1.123457 
    q)P 0 /this is eqiuvalent to P 
    17 
    q)P 
    0i 
    q)0.11111111111111112 
    0.11111111111111112 
    q)1.11111111111111112 
    1.1111111111111112

    Further reading here:

    Hope this helps, and thanks for sharing your query on the Community portal!

    Kind regards,

    David

  • davidcrossey

    Member
    October 5, 2021 at 12:00 am in reply to: C++ convert large decimal to KDB

    Hi @ekallivrousis,

    You could use the Double / Float type as per the C API Reference

    Thanks for posting your query on the forums!

    Kind regards,

    David

  • davidcrossey

    Member
    September 2, 2021 at 12:00 am in reply to: Kx Platform AMD?

    Hi Simon,

    Thanks for raising this query on the Community portal, and apologies in the delayed response.

    Regarding the KX Platform installer, ARM 64-bit isn’t defined as it’s not a supported architecture at this time.

    We do have a ARM 64-bit version of kdb for Linux and macOS for v4.1t that can be downloaded from downloads.kx.com  – note this is a test version and is not intended, nor supported for production usage.

    Hope this helps.

    Kind regards,

    David

Page 8 of 8