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 (October 2009, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 20 Oct 2009 17:08:50 +0200
Reply-To:     Daniel FernŠndez <fdezdan@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Daniel FernŠndez <fdezdan@GMAIL.COM>
Subject:      Re: Loop calculus equivalent to Lag function
Comments: To: Akshaya <akshaya.nathilvar@gmail.com>
In-Reply-To:  <67f588aa0910200744x1d413e94r940b989e6f6bb727@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Akshaya, sorry I did not tell you, I have not ETS.

BTW, what I want is to be able to execute calculus over concrete rows that meet one or more conditions. My intention is to complicate this condition is some way as those who do some basic type of algorithmic trading decisions (not for my own pocket) and nice financial reports (percent gains /loss since lowest year price, top best stock performers etc etc...

here ORCL raw data 180 last days: data orcl; input Date ddmmyy10. High Low Close; cards; 02/02/2009 17.1 16.51 16.9 03/02/2009 17.06 16.5 17.05 04/02/2009 17.63 17.05 17.21 05/02/2009 17.7 16.74 17.62 06/02/2009 18.07 17.48 17.97 09/02/2009 18.09 17.82 18.05 10/02/2009 18.09 17.24 17.58 11/02/2009 18.01 17.57 17.8 12/02/2009 17.61 16.94 17.55 13/02/2009 17.96 17.43 17.72 17/02/2009 17.34 16.81 16.96 18/02/2009 17.51 17 17.24 19/02/2009 17.37 16.8 16.83 20/02/2009 16.75 16.34 16.56 23/02/2009 16.68 15.82 15.86 24/02/2009 16.5 15.75 16.44 25/02/2009 16.57 16.01 16.24 26/02/2009 16.37 15.78 15.78 27/02/2009 15.83 15.41 15.54 02/03/2009 15.69 15.14 15.2 03/03/2009 15.45 14.97 15.01 04/03/2009 15.48 14.85 14.96 05/03/2009 15.28 14.52 14.53 06/03/2009 14.86 14.14 14.47 09/03/2009 14.7 13.8 13.85 10/03/2009 15.19 14 15.09 11/03/2009 15.46 14.73 15.34 12/03/2009 15.68 15.08 15.63 13/03/2009 15.7 15.28 15.56 16/03/2009 15.8 14.83 14.9 17/03/2009 15.6 14.65 15.4 18/03/2009 16.09 15.07 15.83 19/03/2009 18.09 17.35 17.37 20/03/2009 17.71 17 17.1 23/03/2009 18.25 17.26 18.25 24/03/2009 18.22 17.7 17.91 25/03/2009 18.34 17.7 18.09 26/03/2009 18.68 18.18 18.68 27/03/2009 18.45 17.93 18.01 30/03/2009 17.7 17.25 17.66 31/03/2009 18.39 17.82 18.07 01/04/2009 18.68 17.73 18.58 02/04/2009 19.3 18.65 18.82 03/04/2009 19.45 18.87 19.29 06/04/2009 19.11 18.69 19.11 07/04/2009 18.86 18.36 18.54 08/04/2009 18.76 18.33 18.57 09/04/2009 19.2 18.79 19.11 13/04/2009 19.23 18.86 19.06 14/04/2009 19.01 18.61 18.87 15/04/2009 18.74 18.11 18.59 16/04/2009 19.29 18.58 19.18 17/04/2009 19.45 18.73 19.06 20/04/2009 19.08 17.73 18.82 21/04/2009 19.85 18.64 19.53 22/04/2009 19.75 19.09 19.35 23/04/2009 19.71 19.14 19.68 24/04/2009 20.18 19.65 19.79 27/04/2009 20.28 19.52 19.77 28/04/2009 19.93 19.51 19.74 29/04/2009 19.8 19.41 19.6 30/04/2009 19.94 19.04 19.34 01/05/2009 19.44 19.12 19.34 04/05/2009 19.44 18.96 18.97 05/05/2009 19.19 18.68 19.01 06/05/2009 19.19 18.69 19.06 07/05/2009 19.15 18.19 18.42 08/05/2009 18.78 18.12 18.32 11/05/2009 18.83 18.04 18.56 12/05/2009 18.67 18.08 18.38 13/05/2009 18.34 17.97 18.07 14/05/2009 18.58 18.1 18.46 15/05/2009 18.74 18.35 18.42 18/05/2009 18.94 18.47 18.92 19/05/2009 19.21 18.77 18.97 20/05/2009 19.4 18.88 18.94 21/05/2009 18.83 18.35 18.57 22/05/2009 19.09 18.44 18.65 26/05/2009 19.2 18.28 19.07 27/05/2009 19.45 18.91 18.99 28/05/2009 19.37 18.83 19.21 29/05/2009 19.6 19.16 19.59 01/06/2009 20.02 19.6 19.92 02/06/2009 20.44 19.77 20.35 03/06/2009 20.51 20.09 20.34 04/06/2009 20.67 20.27 20.61 05/06/2009 20.9 20.51 20.71 08/06/2009 21.07 20.53 20.87 09/06/2009 21.2 20.83 20.99 10/06/2009 21.19 20.43 20.74 11/06/2009 21.2 20.66 20.94 12/06/2009 21 19.47 20.85 15/06/2009 20.65 20 20.22 16/06/2009 20.27 19.68 19.69 17/06/2009 20.17 19.7 19.94 18/06/2009 20.46 19.98 20.25 19/06/2009 20.92 20.37 20.66 22/06/2009 20.75 19.93 19.97 23/06/2009 20.21 19.73 19.87 24/06/2009 21.75 20.78 21.26 25/06/2009 21.71 21.13 21.63 26/06/2009 21.54 21.15 21.24 29/06/2009 21.71 21.22 21.5 30/06/2009 21.75 21.28 21.42 01/07/2009 22 21.62 21.74 02/07/2009 21.34 20.86 21.04 06/07/2009 21.04 20.5 20.67 07/07/2009 20.78 20.12 20.18 08/07/2009 20.79 19.79 20.57 09/07/2009 20.77 20.18 20.32 10/07/2009 20.63 20.19 20.49 13/07/2009 20.73 20.12 20.72 14/07/2009 20.72 20.28 20.63 15/07/2009 21.53 20.77 21.51 16/07/2009 21.77 21.34 21.64 17/07/2009 21.74 21.4 21.74 20/07/2009 21.83 21.34 21.51 21/07/2009 22 21.43 21.93 22/07/2009 21.98 21.63 21.75 23/07/2009 22.4 21.59 22.2 24/07/2009 22.48 21.91 22.33 27/07/2009 22.31 21.75 21.98 28/07/2009 22.32 21.72 22.24 29/07/2009 22.28 21.83 22.01 30/07/2009 22.47 21.91 22.14 31/07/2009 22.42 22.07 22.13 03/08/2009 22.38 22 22.3 04/08/2009 22.28 21.69 21.89 05/08/2009 21.85 21.18 21.44 06/08/2009 21.94 21.09 21.21 07/08/2009 21.84 21.37 21.43 10/08/2009 21.41 21.03 21.25 11/08/2009 21.41 21.03 21.28 12/08/2009 22.1 21.25 21.88 13/08/2009 22.03 21.77 21.99 14/08/2009 22.08 21.66 21.96 17/08/2009 21.75 21.37 21.4 18/08/2009 21.96 21.31 21.58 19/08/2009 21.84 21.2 21.78 20/08/2009 22.05 21.61 21.94 21/08/2009 22.14 21.74 22.11 24/08/2009 22.49 22.04 22.32 25/08/2009 22.55 22.2 22.23 26/08/2009 22.26 22 22.2 27/08/2009 22.21 21.78 22.16 28/08/2009 22.61 22.1 22.16 31/08/2009 22.19 21.73 21.88 01/09/2009 22.31 21.67 21.94 02/09/2009 22.03 21.68 21.77 03/09/2009 21.6 21.22 21.56 04/09/2009 22.1 21.54 21.97 08/09/2009 22.12 21.77 21.88 09/09/2009 22.58 21.88 22.52 10/09/2009 22.8 22.46 22.76 11/09/2009 22.95 22.67 22.86 14/09/2009 22.93 22.6 22.72 15/09/2009 22.88 22.6 22.66 16/09/2009 22.61 21.98 22.13 17/09/2009 21.77 21.32 21.52 18/09/2009 21.87 21.57 21.62 21/09/2009 21.82 21.5 21.57 22/09/2009 21.71 21.35 21.41 23/09/2009 21.47 21.05 21.13 24/09/2009 21.35 21.06 21.17 25/09/2009 21.2 20.83 20.86 28/09/2009 21.34 20.83 21.17 29/09/2009 21.38 21.1 21.12 30/09/2009 21.2 20.65 20.84 01/10/2009 20.75 20.1 20.36 02/10/2009 20.64 20.24 20.34 05/10/2009 20.68 20.16 20.39 06/10/2009 20.6 20.3 20.54 07/10/2009 20.95 20.47 20.57 08/10/2009 21.06 20.59 20.8 09/10/2009 21.03 20.66 20.74 12/10/2009 20.92 20.6 20.72 13/10/2009 20.98 20.65 20.91 14/10/2009 21.5 21.12 21.19 15/10/2009 21.32 20.99 21.32 16/10/2009 22.03 21.18 21.81 ;; run;

Daniel

2009/10/20 Akshaya <akshaya.nathilvar@gmail.com>: > > Did you consider about time series procedure like Proc Expand to calculate > moving averages? > Proc expand data= orcl_alerts out=need(drop=time); > convert close=sma9/tin=(setmiss 0) tout=(movave 9); > format sma 6.2; > Run; > > AkshayA! > > > On Tue, Oct 20, 2009 at 7:36 AM, Daniel Fern√°ndez <fdezdan@gmail.com> > wrote: >> >> hi, >> >> I have been using Lag function to resolve a function that takes into >> account >> the stock closed prices (stock quotes) for the last 9 days. , i.e. I >> calculate the simple moving average of last 9 days for ORACLE 'orcl' stock >> data. >> here the source data in a 'csv' file: >> http://ichart.finance.yahoo.com/table.csv? >> s=ORCL&d=9&e=20&f=2009&g=d&a=2&b=2&c=1988&ignore=.csv >> >> Executing the following code I get what I need but I am not so >> enthusiastic >> about >> using Lag function for the new created variable 'sma9', >> is there other way/method to get the same needed formula >> in a data step inside a Do Until loop? >> I am enjoying to calculate conditional alerts signals for stock price time >> series, >> but first I have to search for a more efficient coding before complicating >> those >> conditional alert signals. >> >> Here my code: >> >> * LAST 180 'ORCL' QUOTES; >> data orcl; >> set orcl (keep= date high low close obs=180); >> run; >> * intead of calculating the classical percent gains/loss from beginning >> of year, I desire to calculate it since the lowest close price for last >> 400 >> days >> until highest close price and perhaps others calculus as current gain/loss >> since lowest close; >> proc sql; >> create table lowest_orcl_quote as >> select * from orcl >> having close = min(close); >> quit; >> proc sql; >> create table highest_orcl_quote as >> select * from orcl as h >> join lowest_orcl_quote as l >> on h.date > l.date >> having h.close = max(h.close); >> quit; >> >> *we mark this day with alerts; >> *first, we need to sort ascending order by date; >> proc sort data=orcl; by date; run; >> proc sort data=lowest_orcl_quote; by date; run; >> proc sort data=highest_orcl_quote; by date; run; >> data orcl_alerts; >> length alert $6.; >> merge lowest_orcl_quote (in=a) >> highest_orcl_quote (in=b) >> orcl (in=c); >> by date; >> if a then alert='BOTTOM'; >> if b then alert='TOP'; >> run; >> >> >> >> data need; >> length alert $6.; >> do until(alert ='TOP'); *date=date()); *other optional calculus; >> set orcl_alerts end=fin; >> by date; >> if prev_close = . then invest_return = .; >> else invest_return = (close - prev_close) / prev_close; >> * 'sma9' has the meaning of Simple Moving Average 9 days; >> * for more details: >> http://www.traderslog.com/movingaverages.htm >> http://web.streetauthority.com/terms/simpleandexponentialmovingavera >> ges.asp; >> sma9= mean(close,lag(close),lag2(close),lag3(close),lag4(close), >> lag5(close),lag6(close),lag7 >> (close),lag8(close)); >> if close < sma9 then Sell_signal= -1; else Sell_signal=0; >> output; >> if alert ='BOTTOM' then prev_close = close; >> end; >> drop prev_close; >> format invest_return percent8.1 sma9 6.2; >> run; >> >> >> thank you very much for your attention in advance, >> Daniel FernŠndez. >> Barcelona. > >


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