LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2006, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 14 Sep 2006 22:50:45 -0400
Reply-To:     "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Subject:      Re: Smarter dynamic code than this hard corded one

You may not need "dynamic code". You do need to exploit arrays and looping. Associative arrays (hashes) seem particularly appropriate.

A reflexive join in SQL is also a possibility.

How large is the data set? How many observations in the series? How many different securities?

On Thu, 14 Sep 2006 10:02:29 -0400, wing wah <wing.tham03@PHD.WBS.AC.UK> wrote:

>Hi folks, > >As i am rather incompetent with logic. I am trying to reconstruct the real >time orderbook in financial market. If the quotes below are bid price that >is posted by traders, i am interested to rank the posted quote as the >bestbid secondbid thirdbid fourthbid and so on. The quantity of each rank >(bestbid, secondbid,....) is sum of accumulated quantity of those rank >before it. i.e. quantity of bestbid=quantity of bestbid, accumulated >quantity of secondbid=quantity of secondbid+quantity of bestbid, and so >on... I hope the output of the code will provide a clearer explanation of >the logic behind what i am trying to construct. >However, the dataset that i have is huge and the queue or rank sometime >goes up to 1000 (for our case here, the rank is only 5). For a rank of 5, >the code is pretty long as seen by my inefficient coding. I am hoping for >some advices on how i can more smartly do this that can accomodate for >longer queue (number of rank - bestbid, secondbid, ....thousandthbid) as >the data set increases. Thanks in advance. > >Wing > > > >data given; > input quantity quote @@; > cards; > 2 11.1 2 11.1 2 12.2 > 3 13.3 -3 11.1 3 10.1 > 4 14.4 4 11.1 4 12.2 > -5 11.1 5 16.6 -3 10.1 > 6 13.3 >; > > > > > > > >data ootest; >retain bestbid b_vol1 bid2 b_vol2 bid3 b_vol3 bid4 b_vol4 bid5 >b_vol5 bid6 b_vol6 ; >retain obestbid ob_vol1 obid2 ob_vol2 obid3 ob_vol3 obid4 ob_vol4 >obid5 ob_vol5 obid6 ob_vol6 ; >set given; >if (_n_ eq 1) then do; > > bestbid=quote; > b_vol1=quantity; > end; > else do; > select; > when (obestbid eq .) do; > bestbid=quote; > b_vol1=quantity; > end; > > when (quote eq obestbid & >quantity=-ob_vol1) do; > bestbid=bid2; > b_vol1=ob_vol2+quantity; > bid2=obid3; > b_vol2=ob_vol3+quantity; > bid3=obid4; > b_vol3=ob_vol4+quantity; > bid4=obid5; > b_vol4=ob_vol5+quantity; > bid5=obid6; > b_vol5=ob_vol6+quantity; > end; > > when (quote eq obestbid) do; > b_vol1=ob_vol1+quantity; > b_vol2=ob_vol2+quantity; > b_vol3=ob_vol3+quantity; > b_vol4=ob_vol4+quantity; > b_vol5=ob_vol5+quantity; > b_vol6=ob_vol6+quantity; > end; > > when (quote gt obestbid) do; > bestbid=quote; > b_vol1=quantity; > bid2=obestbid; > b_vol2=ob_vol1+quantity; > bid3=obid2; > b_vol3=ob_vol2+quantity; > bid4=obid3; > b_vol4=ob_vol3+quantity; > bid5=obid4; > b_vol5=ob_vol4+quantity; > bid6=obid5; > b_vol6=ob_vol5+quantity; > end; > > > when (quote eq obid2 & >ob_vol1=ob_vol2+quantity) do; > bid2=obid3; > b_vol2=ob_vol3+quantity; > bid3=obid4; > b_vol3=ob_vol4+quantity; > bid4=obid5; > b_vol4=ob_vol5+quantity; > bid5=obid6; > b_vol5=ob_vol6+quantity; > end; > > when (quote eq obid2) do; > b_vol2=ob_vol2+quantity; > b_vol3=ob_vol3+quantity; > b_vol4=ob_vol4+quantity; > b_vol5=ob_vol5+quantity; > b_vol6=ob_vol6+quantity; > end; > > > when (quote gt obid2) do; > bid2=quote; > b_vol2=ob_vol1+quantity; > bid3=obid2; > b_vol3=ob_vol2+quantity; > bid4=obid3; > b_vol4=ob_vol3+quantity; > bid5=obid4; > b_vol5=ob_vol4+quantity; > bid6=obid5; > b_vol6=ob_vol5+quantity; > end; > > otherwise do; > select; > > when (obid2 eq .) do; > bid2=quote; > b_vol2=ob_vol1+quantity; > end; > > when (quote eq obid3 & >ob_vol2=ob_vol3+quantity) do; > bid3=obid4; > b_vol3=ob_vol4+quantity; > bid4=obid5; > b_vol4=ob_vol5+quantity; > bid5=obid6; > b_vol5=ob_vol6+quantity; > end; > > when (quote eq obid3) do; > b_vol3=ob_vol3+quantity; > b_vol4=ob_vol4+quantity; > b_vol5=ob_vol5+quantity; > b_vol6=ob_vol6+quantity; > end; > > when (quote gt obid3) do; > bid3=quote; > b_vol3=ob_vol2+quantity; > bid4=obid3; > b_vol4=ob_vol3+quantity; > bid5=obid4; > b_vol5=ob_vol4+quantity; > bid6=obid5; > b_vol6=ob_vol5+quantity; > end; > > > otherwise do; > select; > when (obid3 eq .) do; > bid3=quote; > b_3vol=ob_2vol+quantity; > end; > > when (quote eq obid4 & >ob_vol3=ob_vol4+quantity) do; > bid4=obid5; > b_vol4=ob_vol5+quantity; > bid5=obid6; > b_vol5=ob_vol6+quantity; > end; > > when (quote eq obid4) do; > b_vol4=ob_vol4+quantity; > b_vol5=ob_vol5+quantity; > b_vol6=ob_vol6+quantity; > end; > > when (quote gt obid4) do; > bid4=quote; > b_vol4=ob_vol3+quantity; > bid5=obid4; > b_vol5=ob_vol4+quantity; > bid6=obid5; > b_vol6=ob_vol5+quantity; > end; > > otherwise do; > select; > when (obid4 eq .) do; > bid4=quote; > b_vol4=ob_vol3+quantity; > end; > > > > when (quote eq obid5 & >ob_vol4=ob_vol5+quantity) do; > bid5=obid6; > b_vol5=ob_vol6+quantity; > end; > > when (quote eq obid5) do; > b_vol5=ob_vol5+quantity; > b_vol6=ob_vol6+quantity; > end; > > when (quote gt obid5) do; > bid5=quote; > b_vol5=ob_vol4+quantity; > bid6=obid5; > b_vol6=ob_vol5+quantity; > end; > > when (obid5 eq .) do; > bid5=quote; > b_vol5=ob_vol4+quantity; > end; > > when (quote eq obid6) do; > b_vol6=ob_vol6+quantity; > end; > > when (obid6 eq .) do; > bid6=quote; > b_vol6=ob_vol5+quantity; > end; > otherwise; > end; > end; > end;end;end;end;end;end; > >output ootest; >array current bestbid b_: bid:; >array previous obestbid ob_: obid:; >do over previous; >previous=current; >end; >run; > > >output: > >bestbid b_vol1 bid2 b_vol2 bid3 b_vol3 bid4 b_vol4 bid5 b_vol5 >11.1 2 > >11.1 4 > >12.2 2 11.1 6 > >13.3 3 12.2 5 11.1 9 > >13.3 3 12.2 5 11.1 6 > >13.3 3 12.2 5 11.1 6 10.1 9 > >14.4 4 13.3 7 12.2 9 11.1 10 10.1 13 > >14.4 4 13.3 7 12.2 9 11.1 14 10.1 17 > >14.4 4 13.3 7 12.2 13 11.1 18 10.1 21 > >14.4 4 13.3 7 12.2 13 10.1 16 > >16.6 5 14.4 9 13.3 12 12.2 18 10.1 21 > >16.6 5 14.4 9 13.3 12 12.2 18 > >16.6 5 14.4 9 13.3 18 12.2 24


Back to: Top of message | Previous page | Main SAS-L page