How to find the stock_id that raises the BUY signal constantly

Hi, Dear all:
  I want to find out the stock that raises the BUY signal from this Mon to Fri. such as I have the data:

StockidB/SDate

001B2017.02.20

002B2017.02.20

003S2017.02.21

001B2017.02.21

001B2017.02.22

003B2017.02.22

001B2017.02.23

002S2017.02.23

001B2017.02.24

003B2017.02.24

  It seems that Stockid-001 will matches the requirement.

  But how to find out within Q-sql? Many thanks for your tips!

Zheng

So you want stock which have Buy row fol all days from monday to friday?
Below query gives that result:

dt:2017.02.20+til 5

select from tbl where BS=`B, ({all dt in x};Date)fby Stockid

Below should work for you, and there’ll be many more ways too

//dummy data

q)a:(s:1 2 3 1 1 3 1 2 1 3;t:`$'“BBSBBBBSBB”;d:raze 2#'2017.01.31+20+til 5)

q)select distinct s by `week$d from a where s in where 5=count each d group s,(d mod 7) in 2+til 5

d         | s

----------| -

2017.02.20| 1

//join on another week

q)a,:update d+7 from a

q)select where 5=count each group s by week$d from a where (d mod 7) in 2+til 5,t=B

d         | s

----------| -

2017.02.20| 1

2017.02.27| 1

//insert some Bs for stock id 2 for days where it had no buy signal in the first week

q)a,:(s:4#2;t:4#`B;d:2017.02.21+til 4)

q)select where 5=count each group s by week$d from a where (d mod 7) in 2+til 5,t=B

d         | s

----------| —

2017.02.20| 1 2

2017.02.27| ,1

HTH,

Sean

Hi, Rahul:
  Thanks for your sample. I tried, it works.

  May I ask what the statement: “all dt in x” meaning?

Zheng

? 2017?2?24??? UTC+8??7:56:55?RAHUL ASATI???

So you want stock which have Buy row fol all days from monday to friday?
Below query gives that result:

dt:2017.02.20+til 5

select from tbl where BS=`B, ({all dt in x};Date)fby Stockid

Hi, Sean:
  Thanks for your example. It’s easy to understand.

  I tried it, it works.

Thanks very much!

Zheng

? 2017?2?24??? UTC+8??7:30:42?Sean O’Hagan???

Below should work for you, and there’ll be many more ways too

//dummy data

q)a:(s:1 2 3 1 1 3 1 2 1 3;t:`$'“BBSBBBBSBB”;d:raze 2#'2017.01.31+20+til 5)

q)select distinct s by `week$d from a where s in where 5=count each d group s,(d mod 7) in 2+til 5

d         | s

----------| -

2017.02.20| 1

//join on another week

q)a,:update d+7 from a

q)select where 5=count each group s by week$d from a where (d mod 7) in 2+til 5,t=B

d         | s

----------| -

2017.02.20| 1

2017.02.27| 1

//insert some Bs for stock id 2 for days where it had no buy signal in the first week

q)a,:(s:4#2;t:4#`B;d:2017.02.21+til 4)

q)select where 5=count each group s by week$d from a where (d mod 7) in 2+til 5,t=B

d         | s

----------| —

2017.02.20| 1 2

2017.02.27| ,1

HTH,

Sean

i’d do it this way

q)t:(s:1 2 3 1 1 3 1 2 1 3;sig:`$'“BBSBBBBSBB”;d:raze 2#'2017.01.31+20+til 5)

q)select from t where ({all x=`B};sig) fby s

OR

q)select from t where 5=({sum x=`B};sig) fby s

Hi Zheng,
‘x’ will be list of dates for a particular stock id.
fby will send date list for each stock id in function {all dt in x} and this function will then check if all dates(mon - fri) are present in current date list ‘x’ of stock id  or not.