Home › Forums › KX Academy › fundamentals capstone 4.7
-
fundamentals capstone 4.7
Posted by Kal8na on April 13, 2024 at 1:43 pmIn 4.7 exercise I don’t understand how to implement the code for it. maybe I don’t understand what the question is asking. can you please explain this?
lestat-jin replied 6 months ago 4 Members · 5 Replies -
5 Replies
-
Hi @kal8na
Let me break down question 4.7 for you:
- Using your timeSeries dictionary that you created in ex 4.6, compare the correlation of edge against the correlation of qty then the correlation of edge against the correlation of numTrds. To do this you can use the keyword cor – cor – corelation coefficient | Reference | kdb+ and q documentation – Kdb+ and q documentation (kx.com)
- Store this data in a dictionary called edgeCor with the keys being edge, qty and numTrds and the values being their correlation with the edge series.
There are a few different ways this can be done but using iteration is included as a suggestion.
Let me know if you require further assistance.
Thanks,
Megan
code.kx.com
cor – corelation coefficient | Reference | kdb+ and q documentation - Kdb+ and q documentation
cor is a q keyword that calculates the correlation coefficient of two numeric lists.
-
just to borrow the thread as I’m stuck on this as well: so I managed to complete the task with script:
edgeCor:`edge`qty`numTrds!(1;cor[timeSeries[`edge];timeSeries[`qty]];cor[timeSeries[`edge];timeSeries[`numTrds]])
the output is a dictionary with type 99h and values of 1 0.8059053 0.7830214
however it failed the section testing with 4.7 error: “edgeCor Has Correct Format”
I didn’t implement it with iterators but I don’t think that is the reason it failed the test. not sure why it says incorrect format–do I need to output values in percentage terms (there is no way in Q to output a numeric in % without converting it into string first?)
any ideas please? thanks!
-
using a different approach and now it passed the section testing:
corKey:`edge`qty`numTrds
correlations:cor[timeSeries[edge]] each timeSeries[corKey]
edgeCor:corKey!correlations
the results visually identical, though the earlier approach failed with 4.7 format testing:
edgeCor:`edge`qty`numTrds! (1;cor[timeSeries[`edge];timeSeries[`qty]];cor[timeSeries[`edge];timeSeries[`numTrds]])
would be good to understand why (cannot see how the testing function 4.7 written so cannot debug…) Thanks.
P.S. apologies borrowing the thread, let me know if should create a separate discussion for this.
-
Hi,
Don’t worry about jumping on the thread, it’s good to have it on one thread to help others!
I ran your two solutions and then ran
type each edgeCor
on each.
And while the output dictionary looked the same for both outputs, using the input of “1” in your first attempt defaulted the types to:
edge | -7
qty | -9
numTrds| -9when the correct types should be (and are in your second attempt)
edge | -9
qty | -9
numTrds| -9Hope this helps!
Laura
-
I see, should be 1.0 in the manual construction, thanks a lot!
-
-
Log in to reply.