Reputation: 21
I've used proc ARIMA to obtain forecasts for the next year of my data set and have an output dataset with these forecast values.
I took the logarithm of the original data for the forecasts so I need to obtain the true values by taking the exponential of the forecast values.
I want to have a plot that shows how the data has been forecasted and how it looks compare to the original data but I have no clue on how to do this.
code:
* Open the file;
data intel_stock;
infile 'path' dlm=',' firstobs=2;
input Date anydtdte10. Volume;
format Date date10.;
Timeref=_n_;
logvolume = log(Volume);
run;
* Plot the data ;
proc sgplot data=intel_stock;
series x=Timeref y=Volume/markers;
xaxis values=(1 to 5000 by 1);
run;
* Variation seems to increase greatly over time, hence we take the log of volume ;
proc sgplot data=intel_stock;
series x=Timeref y=logvolume/markers;
xaxis values=(1 to 5000 by 1);
run;
* Plot shows a good amount of variance removed ;
* selecting an ARIMA model ;
proc arima data=intel_stock;
identify var= logvolume(1); * first difference was taken to make the data stationary ;
estimate p = 2 q = 2 ;
forecast lead=12 interval=month id=Date out=forecast;
run;
* ARIMA(2,1,2) model was used;
Upvotes: 0
Views: 228
Reputation: 21
* Removes logarithm from volume, forecast, upper and lower 95% CIs;
data intel_forecast;
set forecast;
Volume = exp(logvolume);
l95 = exp(l95);
u95 = exp(u95);
forecast = exp(forecast + std*std/2);
run;
* plots forecast with the rest of the data ;
proc sgplot data=intel_forecast;
where date >= '1JAN18'D;
band Upper=u95 Lower=l95 x=Date
/ legendLabel="95% Confidence Limits" ;
scatter x=Date y=Volume;
series x=Date y=forecast
/ legendlabel="Forecast of Volume for the next 5 years";
run;
Upvotes: 0
Reputation: 27508
Use Proc ARIMA
option PLOTS=ALL
.
Example:
%if not %sysfunc(cexist(work.sasmacr.yahoo_stock_quotes.macro)) %then %do;
filename source url "https://www.devenezia.com/downloads/sas/macros/download.php?file=stock_quotes.sas";
%include source;
filename source;
%end;
%if not %sysfunc(exist(work.intc)) %then %do;
%yahoo_stock_quotes(symbol=INTC,start=11/01/2016)
data INTC;
set INTC;
Timeref=_n_;
logvolume = log(Volume);
run;
%end;
ods html file='intc.html';
proc sgplot data=INTC;
scatter x=Timeref y=Volume ;
run;
proc sgplot data=INTC;
scatter x=Timeref y=logvolume ;
run;
proc arima data=INTC plots=all;
title "INTC - ARIMA(2,1,2)";
identify var=logvolume(1); * first difference was taken to make the data stationary ;
estimate p = 2 q = 2 ;
forecast lead=12 interval=month id=Date out=forecast;
run;
quit;
ods html close;
Upvotes: 0