04-03-2017 12:08 PM
Using teh dataset below, is there a straightforward way of calculating:
(1) the largest price increase in any consecutive 30/360/720 day period. So the algorithm would need to check the price change of from every day to every other day within 30/360/720 days and output a maximum
(2) the largest price increase in a particular month
(3) the largest price increase in a particular year
(4) the correlation of price movements between January 2015 and January 2016 i.e. are price movements in Jan 2015 correlated with price movements in Jan 2016?
attrib date length=4 format=date9.;
do date = '1jan2015'd to '31dec2016'd;
price = int(ranuni(225465114) * 30) + 95;
04-03-2017 12:47 PM
I think you may need to expand on your definitions of 2 and 3.
2) the largest price increase in a particular month: Do you mean single day to day increase within calendar month, largest end of month compared with first of month, increase from previous month end, or something else.
Some of this may be easier if you have SAS/ETS available. Do you?
04-03-2017 12:52 PM
04-03-2017 05:00 PM
I assumed disjoint months. not sure what you want for output. proc sql; create table cart as select l.month ,max(abs(l.price - r.price)) as jandif from date as l full outer join date as r on l.month ne r.month and l.date ne r.date group by l.month ;quit; Up to 40 obs WORK.CART total obs=3 Obs MONTH JANDIF 1 1 29 2 2 28 3 3 29
04-03-2017 05:41 PM
How about providing a concrete (NOT random) 45 days of data and show us what the result for the 30 day problem would look like based on that data. That should not be to large to do by hand.
You may also need to be careful about "increase". What is the result for if the data only decreases over a given time interval?
04-04-2017 07:48 AM - edited 04-04-2017 08:04 AM
Thanks for your feedback.
I've attached an excel with two tabs:
The first shows the calculation in excel for calculating the max price increase (not decrease) in a calendar week (Mon-Sun) over a two month period.
The second is an expansion of the first example and shows how to calculate the max price increase in any 7 day consecutive period.
Once the above has been solved, it is straightforward expanding this to months/ bigger intervals.
You will see in both examples that the agorithm needs to calculate a matrix of price change and then max over the matrix
So to calculate the max price change in a calendar week you need to perform 21 calculations and take the max the get the max price change. If we wanted to do the same for January, you would need to perform 1,860 calculations.
Does this make sense?
04-04-2017 05:37 PM
See if this does the 7 days. Since the data is random it may not match expectations.
data have; attrib date length=4 format=date9.; do date = '1jan2015'd to '31dec2016'd; price = int(ranuni(225465114) * 30) + 95; PriceInc = dif(Price)/lag(price); If PriceInc<0 then PriceInc=.; Max7Day = max(priceInc,lag(priceinc),lag2(priceinc),lag3(priceinc),lag4(priceinc),lag5(priceinc),lag6(priceinc)); output; end; label PriceInc = "Percent increase from previous day" Max7Day = "Maximum daily price increase percent 7 days" ; format PriceInc Max7Day percent8.1; run;
If that at matches then some of what you requested may be possible with other report procedures and careful use of formats
proc tabulate data=have; class date; format date yymon.; var priceinc; tables date, priceinc*max*f=percent8.1; run;