Forum Replies Created

Page 1 of 2
  • unterrainer_ale

    Member
    December 18, 2024 at 11:47 am in reply to: How to insert a boolean list into a table

    Hi Jonathan, great, glad it worked. Just remember, you can send queries via parse trees like

    handle(function;argument1;...;argumentN)

    q)h(insert;`emulation;(1b;1b;1b))

    ,1

    q)h "emulation"

    a b c

    -----

    1 1 1

    1 1 1

  • unterrainer_ale

    Member
    December 16, 2024 at 9:59 pm in reply to: How to insert a boolean list into a table

    This is because the standard definition of .z.pg (the handle for synchronous messages) is value. value evaluates a string using variables that are defined locally. Because the values you use in the string query aren’t defined on the process you send the query to, you’re getting an error. You can send your query as a parse tree and it will use the local definition of the variables (from the client side) 

    // server 
    q)emulation:([] a:`boolean$(); b:`boolean$(); c:`boolean$())<br>q)a:1b;b:1b;c:1b;<br>q)a<br>1b<br>q)b<br>1b<br>q)c<br>1b<br>// client<br>q)value "2+2"<br>4<br>// You get the same error if you try to use value with variables that are not defined<br>q)value "g+h"<br>'g<br> [1] g+h<br> ^<br>q)h "`emulation insert (1b;1b;1b)"
    ,0
    q)h "emulation"
    a b c
    -----
    1 1 1
    q)h(insert;`emulation;(1b;1b;1b))<br>,1<br>q)h "emulation"<br>a b c<br>-----<br>1 1 1<br>1 1 1<br>// Note a,b,c is defined on the server<br>q)h"`emulation insert (a;b;c)"
    ,2
    q)h"emulation"
    a b c
    -----
    1 1 1
    1 1 1
    1 1 1
    q)a:4
    q)b:5
    // a and b defined in local process (no boolean) 
    q)value "a+b"
    9
    // defining variables locally that can be send via a parse tree
    q)x:1b;y:1b;z:1b
    q)h(insert;`emulation;(x;y;z))
    ,3
    q)h"emulation"
    a b c
    -----
    1 1 1
    1 1 1
    1 1 1
    1 1 1

    You can read more about IPC here https://code.kx.com/q/basics/ipc/#send-messages

  • unterrainer_ale

    Member
    December 6, 2024 at 4:45 pm in reply to: dictionaries as functions

    If you look at your dictionary you can see that your key is a symbol atom, so you have to index by a symbol. Once you have done that, you can pass the value as parameter. This syntax should work

    // Your dictionary

    q).test.ex

    | ::

    t1| {[x] x}

    t2| {[x] x}

    q).test.ex[`t1`t2]@'3 4

    3 4

  • unterrainer_ale

    Member
    November 28, 2024 at 4:51 pm in reply to: Column accepting multiple types

    You can create an untyped column by using below syntax:

    t:([] a:(); b:(); c:()) 

    However, the moment you get the first insert the types will be inferred from the first row you insert. Every successive insert that doesn’t align to the types of the first row will throw a type error. Apart from that, it’s pretty much one of the worst design decisions you can make. The power and speed comes from having typed columns and knowing how much memory needs to be assigned and knowing how big each memory block needs to be. Why not simply define the column as float? You can read about it here https://code.kx.com/q4m3/8_Tables/#82-empty-tables-and-schema

    q)meta t

    c| t f a

    -| -----

    a|

    b|

    c|

    q)`t insert (1;2;4.0)</p><p><span style="font-size: 1rem;">,0</span><br></p><p>q)t</p><p><span style="font-size: 1rem;">a b c</span><br></p><p>-----</p><p>1 2 4</p><p>q)meta t</p><p><span style="font-size: 1rem;">c| t f a</span><br></p><p>-| -----</p><p>a| j</p><p>b| j</p><p>c| f</p><p>q)`t insert (1;2;3)

    'type

    [0] `t insert (1;2;3)

    ^




  • unterrainer_ale

    Member
    November 19, 2024 at 8:37 pm in reply to: Removing quotation from a column name

    Reference for .Q.id

    https://code.kx.com/q/ref/dotq/#id-sanitize

  • unterrainer_ale

    Member
    November 19, 2024 at 8:37 pm in reply to: Removing quotation from a column name

    The syntax for xcols is `newName xcol tableName , because it looks like you are sending the query over a handle you have to do either h_feed “`newName xcol tableName” or h_feed(xcol;`newName;tableName)

    Note that xcol renames the first column to the first symbol. so if your update_date is at position n you need n-1 column names before on the left side. Not sure if that makes sense but you can read the documentation about xcol here https://code.kx.com/q/ref/cols/#xcol

    You can also use .Q.id to sanitise your column names

    (base) alexanderunterrainer@Alexanders-Laptop:~|⇒ cat table.csv

    “”update_date*””,goodName

    1,2

    3,4

    5,6

    q)t:(“II”;enlist csv) 0:`table.csv

    q)t

    “update_date*” goodName

    ———————–

    1 2

    3 4

    5 6

    q).Q.id t

    update_date goodName

    ——————–

    1 2

    3 4

    5 6

    or using xcol

    q)`newGoodName xcol t

    newGoodName goodName

    ——————–

    1 2

    3 4

    5 6

  • unterrainer_ale

    Member
    September 29, 2024 at 11:19 am in reply to: First Project Attempt

    I would add some comments or descriptions for the parameter inputs to the functions for those who don’t have a finance background or are not familiar with the Kelly Criterion.

  • unterrainer_ale

    Member
    September 18, 2024 at 12:19 pm in reply to: Environment variables in par.txt

    As per the documentation, the par.txt file should contain the path to the individual segments. I don’t think you can use environment variables. https://code.kx.com/q4m3/14_Introduction_to_Kdb%2B/#144-segmented-tables

    <code style=”display: inline !important;”>par.txt

    containing the paths of the physical locations of the segments, one segment path per line.”

  • unterrainer_ale

    Member
    September 13, 2024 at 8:52 am in reply to: window join on more than 2 columns ?

    Hi fav_pa,

    yes, a window join wj for several columns is possible. The syntax is

    wj[w;c;t;(q;(f0;c0);(f1;c1))]

    where w is your window, c are the columns you want to match on, in your case this would be sym, date time and trader type. As with the asof join, aj, the time column should be the last in your list, so I assume it’s sym,traderType,datetime (I am avoiding the symbol syntax because of the known UI issue).

    You can read more about wj here https://code.kx.com/q4m3/9_Queries_q-sql/#999-window-join

  • unterrainer_ale

    Member
    July 23, 2024 at 3:53 pm in reply to: Range Bar in kdb

    @laura would you mind formatting my answer? thanks

  • unterrainer_ale

    Member
    July 23, 2024 at 3:52 pm in reply to: Range Bar in kdb

    Hi rgiu70,

    not sure if this is what you are looking for, but if you have a table and just want to get the open, high, low, close by sym you can run the following query

    </p><p>q)t:([] sym:20?AAPLMSFTC; price:20?100.0)

    q)t

    sym price

    ————-

    MSFT 39.27524

    MSFT 51.70911

    C 51.59796

    AAPL 40.66642

    MSFT 17.80839

    C 30.17723

    MSFT 78.5033

    C 53.47096

    MSFT 71.11716

    AAPL 41.1597

    AAPL 49.31835

    MSFT 57.85203

    C 8.388858

    MSFT 19.59907

    C 37.5638

    AAPL 61.37452

    AAPL 52.94808

    C 69.16099

    AAPL 22.96615

    MSFT 69.19531

    q)exec ohlc!(first;max;min;last)@\:price by sym from t

    | o h l c

    —-| ———————————–

    AAPL| 40.66642 61.37452 22.96615 22.96615

    C | 51.59796 69.16099 8.388858 69.16099

    MSFT| 39.27524 78.5033 17.80839 69.19531

    q)

    `

  • unterrainer_ale

    Member
    July 16, 2024 at 7:46 pm in reply to: Using the partition type as a parameter

    Hi eohara_kdb, have you tried the same with a table in a q process and does this error only occur on a HDB?

  • unterrainer_ale

    Member
    June 27, 2024 at 4:00 pm in reply to: differ by in qsql

    Hi,

    I believe this is what you are looking for.

    q)t:([] sym:`a`a`a`b`b`c`c`a`b`c;price:1 1 2 3 4 5 5 8 9 7)
    
    q)t
    
    sym price
    
    ---------
    a 1
    a 1
    a 2
    b 3
    b 4
    c 5
    c 5
    a 8
    b 9
    c 7
    
    q)select from t where (differ;price) fby sym
    
    sym price
    
    ---------
    a 1
    a 2
    b 3
    b 4
    c 5
    a 8
    b 9
    c 7

     

    You can read more about fby here fby – Reference – kdb+ and q documentation – kdb+ and q documentation (kx.com)

  • unterrainer_ale

    Member
    June 18, 2024 at 12:26 pm in reply to: Best way to access to kdb+ personally on windows

    Hi,

    I just use terminal on my Mac to start a q process and then either directly work in the console or use a IDE QStudio, QPad, kdbstudio, IntelliJ or VS Code to connect to it. That works fine. You can do the same on Windows using CMD and the IDEs

  • unterrainer_ale

    Member
    July 17, 2024 at 12:50 pm in reply to: Using the partition type as a parameter

    I just replicated the error myself, so it looks like indeed, when you use the same name for the parameter of your functional select as the virtual column (date in this case) it doesn’t work. What you should keep in mind is that when you are on a hdb, the virtual column, date is actually loaded into memory, meaning, the variable date exists. If you just run date on your HDB it will output all available dates. This also impacts your second question, where you asked about count 0. You have an enlist in your where clause (enlist date), and on the HDB I tested, it actually returned 1 single record. If I run the same with enlist dt, it throws a length error

Page 1 of 2