Skip to content

Commit

Permalink
improved tsort implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
stevan apter committed Dec 12, 2017
1 parent 0f6b195 commit c115627
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
11 changes: 3 additions & 8 deletions c.q
Expand Up @@ -15,14 +15,9 @@

/ websocket communications
.hg.J:0Ni

$[.z.K<3.3;
[.z.pc:{[w]$[w=.hg.J;.hg.J:0Ni;w=.hg.K;.hg.K:0Ni]};
.z.po:{.hg.J:.z.w;neg[.hg.K](1#`fn)!1#`set}];
[.z.pc:{[w]if[w=.hg.K;.hg.K:0Ni]};
.z.wc:{[w]if[w=.hg.J;.hg.J:0Ni]};
.z.wo:{.hg.J:.z.w;neg[.hg.K](1#`fn)!1#`set}]];

.z.pc:{[w]if[w=.hg.K;.hg.K:0Ni]}
.z.wc:{[w]if[w=.hg.J;.hg.J:0Ni]}
.z.wo:{.hg.J:.z.w;neg[.hg.K](1#`fn)!1#`set}
.z.ws:{.hg.rcv .hg.sym .j.k x}

/ client utilities
Expand Down
11 changes: 6 additions & 5 deletions d.q
Expand Up @@ -2,7 +2,7 @@

\e 1

sym:50
sym:1000
per:.005

traders:get`:pnl/traders
Expand Down Expand Up @@ -80,7 +80,7 @@ trader:`chico`harpo`groucho`zeppo`moe`larry`curly`shemp`abbott`costello
sector:`energy`materials`industrials`financials`healthcare`utilities`infotech
strategy:`statarb`pairs`mergerarb`house`chart`indexarb
n:100000
n:10000000
t:([N:til n]
symbol:n?symbol;
sector:n?sector;
Expand All @@ -107,6 +107,10 @@ O.columns.wprice:`USD
O.columns.pnl:`USD
O.columns.quantity:`QTY
S:()!()
S[`g_]:`a
S[`pnl]:`D
/ update
.z.ts:{
t[::;`quantity]+:-1 1[n?2]*n?100;t[::;`price]+:-.5+n?1.; / inputs to pnl
Expand All @@ -115,6 +119,3 @@ O.columns.quantity:`QTY
.hg.upd`;
}
2 changes: 2 additions & 0 deletions deprecated/q.q
@@ -0,0 +1,2 @@
k)\d .j
k)J:(($`0`1)!$`false`true;s;{$[in["w";x 1 2]|~#x;"null";x]};s;j;{s@[x;&"."=8#x;:;"-"]};s)1 2 5 10 11 12 16h bin
2 changes: 1 addition & 1 deletion t.q
Expand Up @@ -107,7 +107,7 @@ sort:{[t;g;s;w]$[count s;tsort[t;$[count w 0;();g];key s]get s;(::)]}

tsort:{[t;g;c;o]
if[0=count g;:0,1+msort[1_t;c]o];
if[`g_~first -1_c;c:`G_,1_c;t:update G_:?[l_>1;first 0#g_;g_]from t];
if[`g_~first -1_c;c:`G_,1_c;t[`G_]:@[t`g_;where 1<t`l_;first 0#]];
n:reverse exec i by L_ from s:dsort[t;g;c;o]where L_>0;
0,raze$[1=count n;s[`I_]n;merge[s;g]/[();key n;get n]]}

Expand Down

0 comments on commit c115627

Please sign in to comment.