Fundamentals Capstone 2.1

https://learninghub.kx.com/forums/topic/fundamentals-capstone-2-1

Hi,

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.

 

 

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.

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).

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?

, 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!

 

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

 

 

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.

 

exercise 1 passes.

exercise 2.1 fails

i used

optRef
optRef:update expiry:"D"$expiry from optRef
count optRef
meta optRef

count optRef returns 99, as in 1.4 (i guess correct)

the 20th date inside date type, has not transformed to 02, so i guess its correct as well)

the column is now type date

i do not know why it fails, but i am at this stage so long…

i need the answer, in order to proceed, please

Hi @ntzioras.dim ,

What did meta optRef return?

If you are still stuck on this exercise, feel free to DM me your code and I can run through it to see what’s going wrong.

Thanks,

Laura

Hello lkerr2,

thank you for the eagerness!

Below is the whole code of ex1,2 :

Hi @ntzioras.dim thanks for forwarding that.

count optRef should return 100. Your code all looks fine except for the first line. To load in the database you should run

system"l ",getenv[`HOME],"/fundamentals_capstone_dbs/"

Can you try again using that and see if your 2.1 passes?

Thanks,

Laura

Hello lkerr2 and thank you for your last response,

i sent you the current code:

Hi, the first thing I notice is your line

uniqueOpts: distinct exec option_id from trade

will not work - I’m not sure how that is working for you as it’s throwing a nyi error. You need to select from the table before you can exec on partitioned on-disk tables.

I also don’t see where you load the messages csv - did you use the table importer?

All tests for section 1 and 2 pass when I run through it with those couple of things corrected.

Hope this helps,

Laura