-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Ferenc Bodon edited this page May 2, 2019
·
91 revisions
Q is an excellent programming language that is widely used in the financial industry. Take a look here to get a quick overview of the language.
Below tables contain Python (including libraries Numpy and pandas) equivalent of a Q command. If you don't find something then probably there is no syntactic difference, for example, indexing a list is l[i]
in both Python and Q.
command | Q | Python | Q example | Python example | comment | |
---|---|---|---|---|---|---|
performance | ||||||
codes verbosity | ([] a: 8 * til 4) |
pd.DataFrame({'a': 8 * np.array(range(4))}) |
||||
using [], (), {} | optional | mandatory | ||||
P | learning curve | |||||
PP | external libraries |
command | Q | Python | Q example | Python example | comment | |
---|---|---|---|---|---|---|
boolean constants |
1b 0b
|
True False
|
||||
generic null | :: |
None |
||||
typed null |
0N, 0n, `, " " , etc |
not supported | ||||
infinite values |
0W, -0W, 0w , etc. |
math.inf |
||||
type symbol/category | ` |
not supported | `foo`bar |
Python supports enum by class Enum, but it there you need to provide the list of values during object creation. In Q symbol `foo is represented by an integer and all Q process contain a symbol map. This is a flexible, memory efficient and convenient feature |
||
P | complex number | not supported | j |
3 + 4j |
command | Q | Python | Q example | Python example | comment | |
---|---|---|---|---|---|---|
P | tuples | not supported | comma is the separator | 3, 1.0, "hello" |
||
set | not supported | set |
{2, 3 , 2 , 4} |
Q's set functions e.g. inter , distinct serve set purpose |
||
tables | ([] ) |
DataFrame in library pandas | ([] col1: 1 2; col2: 3 4) |
pd.DataFrame( {'col1': [1, 2], 'col2': [3, 4]}) |
In Q data structure table is part of the language | |
PP | Class | not supported | Class | class ClassName: ... |
command | Q | Python | Q example | Python example | comment | |
---|---|---|---|---|---|---|
assignment | : |
= |
a: 3 |
a= 3 |
||
tuple unpacking | not supported | supported | x, y = 1, 2 |
|||
variable assignment inside an expression | supported | not supported | z*2+ (z: 3), 4 |
|||
comparison | = |
== |
3 = 5 |
3 == 5 |
||
integer division | div |
// |
7 div 5 |
7 // 5 |
||
non-integer division | % |
/ |
10 % 3 |
10 / 3 |
||
length of list/dictionary/table | count |
len |
count l |
len(l) |
||
Q | applying monadic function on a list | each |
map |
f each l |
map(f, l) |
You can omit keyword each in Q if f handles lists as input (most built in functions like neg , log , etc.) for example log li works fine. Python is not that flexible, try math.log(li)
|