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 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 17 Sep 2006 12:27:38 -0400
Reply-To:     wing wah <wing.tham03@PHD.WBS.AC.UK>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         wing wah <wing.tham03@PHD.WBS.AC.UK>
Subject:      using hash

Dear folks,

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.

Since i am trying to create a demand curve. any price lower than the bestbid price will have an accumulated quantity (look at the demand and supply curve). By doing so, I will have to think of a way to extract the price and arrange them as the bestbid, secondbid..... The best bid from the output from the simple code below will be the first price that is not '.' starting from right to left. The secondbid will be the next accumated quantity change after then bestbid from right to left. At least by doing this, i am not worried about how far the queue will stretch.

Firstly, I am wondering if this can be done more efficiently using 'hash'. Secondly, if the code below is a sensible one, from the output below how can i extract the bestbid, secondbid,... and the quantity?

Thank you in advance!

Wing

data given; input quote quantity ; cards;

0.6126 3 0.6126 -3 0.611 1 0.611 -1 0.6115 1 0.6115 -1 0.6103 1 0.6103 -1 0.6075 5 0.6075 -5 0.6061 19 0.609 2 0.6118 2 0.6075 5 0.6061 -19 0.6084 19 0.6118 -2 0.6115 1 0.6121 2 0.6121 -2 0.612 1 0.6118 2 0.6121 1 0.6121 -1 0.612 -1 0.612 5 0.6054 2 0.612 1 0.612 -1 0.61205 1 0.6116 5 0.61105 1 0.61105 -1 0.61205 -1 0.6123 1 0.6123 -1 0.612 2 0.612 2 0.612 -2 0.6116 -5 0.6115 -1 0.612 1 ;

data one (keep=maxi mini hi lo) ; retain maxi mini .; set given end=fin ; maxi = max(maxi, quote); mini=min(mini, quote); if fin then output ;

run;

%let lo =60540; /* found the max and min using datastep*/ %let hi =61260;

data roll3(drop = newpoint); set given; array v(&lo:&hi) v&lo-v&hi; retain v&lo-v&hi; bid=int(quote*100000); newpoint = missing(v(bid) ); do i = bid to &lo by -1; v(i) = sum(v(i),quantity); if v(i)<=0 then v(i) = .; end; run;


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