-
Notifications
You must be signed in to change notification settings - Fork 55
/
md.q
52 lines (46 loc) · 1.29 KB
/
md.q
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/ empty tables
ref:.util.sattr 1!flip `id`px`ts`qs`vol`rfr!"jffjff"$\:()
prices:.util.sattr flip `id`px`time!"jfp"$\:()
price:.util.sattr 1!prices
trades:.util.sattr flip `id`ts`tp`time!"jjfp"$\:()
trade:.util.sattr 1!trades
quotes:.util.sattr flip `id`bs`bp`ap`as`time!"jjffjp"$\:()
quote:.util.sattr 1!quotes
\d .md
/ update the current price for id
updp:{[id;tm]
.log.dbg "updating price for ", string id;
p:`price id;
r:`ref id;
z:.stat.norminv rand 1f;
f:.stat.gbm[r `vol;r `rfr;(tm-p `time)%365D06;z];
p:`id`px`time!(id;f*p `px;tm);
`price`prices upsert\: p;
}
/ update the current quote for id
updq:{[id;tm]
.log.dbg "updating quote for ", string id;
px:`price[id;`px];
r:`ref id;
q:`id`time!(id;tm);
q,:`bp`ap!.sim.tickrnd[r `ts] px;
q,:`bs`as!1+2?r `qs;
`quote`quotes upsert\: q;
}
/ update the current trade price for id
updt:{[id;tm]
if[not id in key `quote;:(::)];
.log.dbg "updating trade for ", string id;
q:`quote id;
t:`id`time!(id;tm);
t,:`ts`tp!.sim.trd[rand 0b;rand 1f] . q `bs`bp`ap`as;
`trade`trades upsert\: t;
}
/ dump all md.q tables in partitioned database format
dump:{[db;tm]
dt:"d"$tm;
.log.inf "dumping tables in ", 1_ string ` sv db,`$string dt;
0!/:`price`quote`trade;
.Q.dpft[db;dt;`id] each`price`quote`trade`prices`quotes`trades;
1!/:`price`quote`trade;
}