%let gpath='.';
%let dpi=200;
ods html close;
ods listing gpath=&gpath image_dpi=&dpi;
/*--Define Macro--*/
%macro StockPlot(symbol=, name=, alpha=);
/*--Read data from CSV file as character values--*/
PROC IMPORT
DATAFILE="C:\Home\Invest\&symbol._2yr.csv"
OUT=&symbol._2yr(rename=(date=datec high=highc low=lowc open=openc close=closec volume=volc))
DBMS=csv REPLACE;
run;
/*--Convert data to numeric format--*/
data &symbol._2yr_data;
format date date7.;
label close='Close' date='Date';
keep date high low open close vol;
set &symbol._2yr;
date=input(datec, yymmdd10.);
close=input(closec, 8.4);
open=input(openc, 8.4);
high=input(highc, 8.4);
low=input(lowc, 8.4);
vol=input(volc, 14.4);
run;
/*--Draw the graph with linear fit and CLI--*/
ods graphics / reset width=5in height=3in imagename="&symbol._2Yr_1";
title "&name (&symbol) Daily Close (Alpha=&alpha) Degree=1 on &sysdate";
proc sgplot data=&symbol._2yr_data noautolegend subpixel;
series x=date y=close / y2axis ;
reg x=date y=close / y2axis nomarkers cli alpha=α
y2axis grid display=(nolabel);
xaxis grid display=(nolabel);
run;
/*--Draw the graph with quadratic fit and CLI--*/
ods graphics / reset width=5in height=3in imagename="&symbol._2Yr_2";
title "&name (&symbol) Daily Close (Alpha=&alpha) Degree=2 on &sysdate";
proc sgplot data=&symbol._2yr_data noautolegend subpixel;
series x=date y=close / y2axis;
reg x=date y=close / y2axis nomarkers degree=2 alpha=&alpha cli;
y2axis grid display=(nolabel);
xaxis grid display=(nolabel);
run;
/*--Draw the graph with 3rd power fit and CLI--*/
ods graphics / reset width=5in height=3in imagename="&symbol._2Yr_3";
title "&name (&symbol) Daily Close (Alpha=&alpha) Degree=3 on &sysdate";
proc sgplot data=&symbol._2yr_data noautolegend subpixel;
series x=date y=close / y2axis;
reg x=date y=close / y2axis nomarkers degree=3 alpha=&alpha cli;
y2axis grid display=(nolabel);
xaxis grid display=(nolabel);
run;
/*--Draw the HighLow graph with ith 3rd power fit and CLI--*/
ods graphics / reset width=5in height=3in imagename="&symbol._2Yr_4";
title "&name (&symbol) Daily Chart (Alpha=&alpha) Degree=3";
proc sgplot data=&symbol._2yr_data(obs=250) noautolegend subpixel;
highlow x=date high=high low=low / open=open close=close y2axis;
reg x=date y=close / y2axis nomarkers degree=3 alpha=&alpha cli;
y2axis grid display=(nolabel);
xaxis grid display=(nolabel);
run;
%mend;
/*--Display Graphs--*/
%stockplot(symbol=FB, name=Face Book, alpha=0.1);
%stockplot(symbol=QQQ, name=Powershares, alpha=0.1);
%stockplot(symbol=AVGO, name=Broadcom, alpha=0.1);