KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums KX Academy Fundamentals Capstone 2.1

  • Fundamentals Capstone 2.1

    Posted by msshaikh11 on December 4, 2023 at 12:00 am


    I need help with ex2.1  for the fundamental capstone project

    **2.1 In the `optRef` table, the `expiry` column is in a string format. Convert this into the kdb date format.**

    My solution:

    update expiry: $[“D”;expiry] from optRef

    I cast within the sql query using UPDATE and cast from string to date using $[x;y] which works except that I cannot keep the changes in my optRef table as it is not updating.



    msshaikh11 replied 3 months, 1 week ago 2 Members · 6 Replies
  • 6 Replies
  • gyorokpeter-kx

    December 5, 2023 at 12:00 am

    Apparently the exercise 1 test doesn’t really check the table, only that it exists.

    According to the description, getOptionRef takes a list of IDs, but you are passing in a symbol, and due to some bad luck this doesn’t result in a type error but the function returns all the rows matching your symbol which there are none.

  • gyorokpeter-kx

    December 5, 2023 at 12:00 am

    The update statement normally returns the modified table. If you want to save the result back to the in-memory table, you have two options:

    • use an assignment statement to overwrite the table with the result
    • pass the name of the table to update rather than its value

    The second option is explained at QSQL query templates | Basics | kdb+ and q documentation – Kdb+ and q documentation (kx.com).

    • msshaikh11

      December 5, 2023 at 12:00 am


      Thanks for the reply, you were right about using the assignment to update the table:

      optRef : update expiry: $[“D”;expiry] from optRef

      To make sure the change is applied to the table of the datatype for the expiry column to date. However I came across another problem (I think it might be the date format but not sure) : when I pass the ex2 test function ex2.1 fails, even though all the column have the correct datatypes.

      My output:

      option_id                    inst_id      opt_type         strike                expiry
      FB20200720C230         9                C                    230                  2020.07.20

      c |                 t f a
      ———|      —–
      option_id|  s
      inst_id      |  j
      opt_type |  s
      strike        |  j
      expiry       | d

      * Expected schema for the `optRef` table:

      |Column Name| Column Type
      |———| —–
      |option_id| symbol
      |inst_id | long
      |opt_type | symbol
      |strike | long
      |expiry | date



  • gyorokpeter-kx

    December 5, 2023 at 12:00 am

    The test checks for an exact match with the expected table, not just the schema. Can you check if you created the optRef table correctly? How many rows are there in the table?

    • msshaikh11

      December 5, 2023 at 12:00 am

      Yes, You are right.

      when I call the refServiceget handle for ex1.4 I get just the columns, so I have no observations.

      How I created optRef table:

      optRef: refServiceHandle(`getOptionRef,`uniqueOpts)

      I assumed my optRef table was correct as it passed the ex1 function test, but now I think I may have called the refServiceHandle function incorrectly and the optRef table wrong (ex1.4) as there are 0 rows.


  • msshaikh11

    December 5, 2023 at 12:00 am

    , Thank you so much for your help in solving this capstone ex2 problem which was linked another problem in ex1.4 that I didn’t know I had!

Log in to reply.