用SAS获取雅虎股票数据以及均线计算源码.docx

上传人:b****4 文档编号:3736439 上传时间:2022-11-25 格式:DOCX 页数:11 大小:92.62KB
下载 相关 举报
用SAS获取雅虎股票数据以及均线计算源码.docx_第1页
第1页 / 共11页
用SAS获取雅虎股票数据以及均线计算源码.docx_第2页
第2页 / 共11页
用SAS获取雅虎股票数据以及均线计算源码.docx_第3页
第3页 / 共11页
用SAS获取雅虎股票数据以及均线计算源码.docx_第4页
第4页 / 共11页
用SAS获取雅虎股票数据以及均线计算源码.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

用SAS获取雅虎股票数据以及均线计算源码.docx

《用SAS获取雅虎股票数据以及均线计算源码.docx》由会员分享,可在线阅读,更多相关《用SAS获取雅虎股票数据以及均线计算源码.docx(11页珍藏版)》请在冰豆网上搜索。

用SAS获取雅虎股票数据以及均线计算源码.docx

用SAS获取雅虎股票数据以及均线计算源码

用SAS获取雅虎股票数据以及均线的计算

第一要有一张股票基础表,包含股票代码等,用来读数。

如下

第二步:

建立stock永久SAS库

第三步:

运行程序

这个过程说明读取了数据,会在stock库下形成对应文件。

每个表有以下数据

下面是源代码:

获取历史数据以及五日、十日均线、十五日均线的计算

%macrogeturl(stockcode,fromdate,todate);

%leta=%sysevalf(%sysfunc(month(%sysfunc(inputn(&fromdate,yymmdd10.))))-1);

%letb=%sysfunc(day(%sysfunc(inputn(&fromdate,yymmdd10.))));

%letc=%sysfunc(year(%sysfunc(inputn(&fromdate,yymmdd10.))));

%letd=%sysevalf(%sysfunc(month(%sysfunc(inputn(&todate,yymmdd10.))))-1);

%lete=%sysfunc(day(%sysfunc(inputn(&todate,yymmdd10.))));

%letf=%sysfunc(year(%sysfunc(inputn(&todate,yymmdd10.))));

"

%mendgeturl;

%macrogetprice();

%letdsid=%sysfunc(open(hua.stock));

%put&dsid;

%letnum=%sysfunc(attrn(&dsid,nobs));

%if&num>0%then%do;

%doj=1690%to1890;

%letrc=%sysfunc(fetchobs(&dsid,&j));

 

%letstockcode=%sysfunc(getvarc(&dsid,5));

%letfromdate=1900-01-01;

%lettodate=2014-09-30;

%letdataset=s%sysfunc(substr(&stockcode,1,6));

filenamereadweburl%geturl(&stockcode,&fromdate,&todate);

DATAstock.&dataset;

FORMATrqyymmdd10.;

INFILEreadwebLRECL=32767DELIMITER=","firstobs=2;

INPUTrqyymmdd10.openhighlowclosevolumeadjclose@@;

range=high-low;

price=(high+low)/2;

if(volume>0);

procsort;

bydescendingrq;

RUN;

%end;

%end;

%letdsid=%sysfunc(close(&dsid));

%mendgetprice;

%getprice();

以上为历史数据获取,以下是均线的计算

%letstockcode=600033.ss;/*股票代码;*/

%letfromdate=2000-01-01;

%lettodate=%sysfunc(intnx(Day,"&sysdate"d,-1),yymmdd10);

%macrogeturl(stockcode,fromdate,todate);

%leta=%sysevalf(%sysfunc(month(%sysfunc(inputn(&fromdate,yymmdd10.))))-1);

%letb=%sysfunc(day(%sysfunc(inputn(&fromdate,yymmdd10.))));

%letc=%sysfunc(year(%sysfunc(inputn(&fromdate,yymmdd10.))));

%letd=%sysevalf(%sysfunc(month(%sysfunc(inputn(&todate,yymmdd10.))))-1);

%lete=%sysfunc(day(%sysfunc(inputn(&todate,yymmdd10.))));

%letf=%sysfunc(year(%sysfunc(inputn(&todate,yymmdd10.))));

"

*"

*"

%mendgeturl;

%put%geturl(&stockcode,&fromdate,&todate);

filenamereadweburl%geturl(&stockcode,&fromdate,&todate);

DATAstocktemp;

FORMATrqyymmdd10.;

INFILEreadwebLRECL=32767DELIMITER=","firstobs=2;

INPUTrqyymmdd10.openhighlowclosevolumeadjclose@@;

range=high-low;

price=(high+low)/2;

if(volume>0);

procsort;

bydescendingrq;

RUN;

dataday5;

setstocktemp(obs=5);

run;

dataday10;

setstocktemp(obs=10);

run;

dataday30;

setstocktemp(obs=30);

run;

dataday60;

setstocktemp(obs=60);

run;

dataday120;

setstocktemp(obs=120);

run;

dataday360;

setstocktemp(obs=360);

run;

procsqlnoprint;

selectmax(high),min(low),mean(price),mean(range),var(price)into:

highest,:

lowest,:

mprice,:

mrange,:

vpricefromstocktemp;

selectmax(high),min(low),mean(price),mean(range),var(price)into:

high5,:

low5,:

mprice5,:

mrange5,:

vprice5fromday5;

selectmax(high),min(low),mean(price),mean(range),var(price)into:

high10,:

low10,:

mprice10,:

mrange10,:

vprice10fromday10;

selectmean(price),mean(range),var(price)into:

mprice30,:

mrange30,:

vprice30fromday30;

selectmean(price),mean(range),var(price)into:

mprice60,:

mrange60,:

vprice60fromday60;

selectmean(price),mean(range),var(price)into:

mprice120,:

mrange120,:

vprice120fromday120;

selectmean(price),mean(range),var(price)into:

mprice360,:

mrange360,:

vprice360fromday360;

quit;

datalow;

formatstockcode$6.;

stockcode="&stockcode";

high5=&high5;

low5=&low5;

mprice5=&mprice5;

mrange5=&mrange5;

vprice5=&vprice5;

highest=&highest;

lowest=&lowest;

mprice=&mprice;

mrange=&mrange;

vprice=&vprice;

high10=&high10;

low10=&low10;

mprice10=&mprice10;

mrange10=&mrange10;

vprice10=&vprice10;

mprice30=&mprice30;

mrange30=&mrange30;

vprice30=&vprice30;

mprice60=&mprice60;

mrange60=&mrange60;

vprice60=&vprice60;

mprice120=&mprice120;

mrange120=&mrange120;

vprice120=&vprice120;

mprice360=&mprice360;

mrange360=&mrange360;

vprice360=&vprice360;

run;

procappendbase=hua.lowdatadata=low;

quit;

下面是附加的简单股票统计分析

procsqlnoprint;

createtablehua.yahooas

selectstock.yahoocodefromhua.lowpriceleftjoinhua.stockonlowprice.stockcode=stock.numcode;

delete*fromhua.lowdata;

quit;

%macrogeturl(stockcode,fromdate,todate);

%leta=%sysevalf(%sysfunc(month(%sysfunc(inputn(&fromdate,yymmdd10.))))-1);

%letb=%sysfunc(day(%sysfunc(inputn(&fromdate,yymmdd10.))));

%letc=%sysfunc(year(%sysfunc(inputn(&fromdate,yymmdd10.))));

%letd=%sysevalf(%sysfunc(month(%sysfunc(inputn(&todate,yymmdd10.))))-1);

%lete=%sysfunc(day(%sysfunc(inputn(&todate,yymmdd10.))));

%letf=%sysfunc(year(%sysfunc(inputn(&todate,yymmdd10.))));

"

%mendgeturl;

%macrogetdata(stockcode);

%letfromdate=2000-01-01;

%lettodate=%sysfunc(intnx(Day,"&sysdate"d,-1),yymmdd10);

filenamereadweburl%geturl(&stockcode,&fromdate,&todate);

DATAstocktemp;

FORMATrqyymmdd10.;

INFILEreadwebLRECL=32767DELIMITER=","firstobs=2;

INPUTrqyymmdd10.openhighlowclosevolumeadjclose@@;

range=high-low;

price=(high+low)/2;

if(volume>0);

procsort;

bydescendingrq;

RUN;

dataday5;

setstocktemp(obs=5);

run;

dataday10;

setstocktemp(obs=10);

run;

dataday30;

setstocktemp(obs=30);

run;

dataday60;

setstocktemp(obs=60);

run;

dataday120;

setstocktemp(obs=120);

run;

dataday360;

setstocktemp(obs=360);

run;

procsqlnoprint;

selectmax(high),min(low),mean(price),mean(range),var(price)into:

highest,:

lowest,:

mprice,:

mrange,:

vpricefromstocktemp;

selectmax(high),min(low),mean(price),mean(range),var(price)into:

high5,:

low5,:

mprice5,:

mrange5,:

vprice5fromday5;

selectmax(high),min(low),mean(price),mean(range),var(price)into:

high10,:

low10,:

mprice10,:

mrange10,:

vprice10fromday10;

selectmean(price),mean(range),var(price)into:

mprice30,:

mrange30,:

vprice30fromday30;

selectmean(price),mean(range),var(price)into:

mprice60,:

mrange60,:

vprice60fromday60;

selectmean(price),mean(range),var(price)into:

mprice120,:

mrange120,:

vprice120fromday120;

selectmean(price),mean(range),var(price)into:

mprice360,:

mrange360,:

vprice360fromday360;

quit;

datalow;

formatstockcode$6.;

stockcode="&stockcode";

high5=&high5;

low5=&low5;

mprice5=&mprice5;

mrange5=&mrange5;

vprice5=&vprice5;

highest=&highest;

lowest=&lowest;

mprice=&mprice;

mrange=&mrange;

vprice=&vprice;

high10=&high10;

low10=&low10;

mprice10=&mprice10;

mrange10=&mrange10;

vprice10=&vprice10;

mprice30=&mprice30;

mrange30=&mrange30;

vprice30=&vprice30;

mprice60=&mprice60;

mrange60=&mrange60;

vprice60=&vprice60;

mprice120=&mprice120;

mrange120=&mrange120;

vprice120=&vprice120;

mprice360=&mprice360;

mrange360=&mrange360;

vprice360=&vprice360;

run;

%mendgetdata;

%macroanalyse();

%letdsid=%sysfunc(open(hua.yahoo));

%letnum=%sysfunc(attrn(&dsid,nobs));

%if&num>0%then%do;

%doi=1%to#

%letrc=%sysfunc(fetchobs(&dsid,&i));

%letstockcode=%sysfunc(getvarc(&dsid,1));

%getdata(&stockcode);

%if&syserr^=0%then%do;

%do%while(&syserr^=0);

%put---------------------------------------------------------------------------&stockcode;

%getdata(&stockcode);

%end;

%end;

procappendbase=hua.lowdatadata=low;

quit;

%end;

%end;

%mendanalyse;

%analyse;

procsqlnoprint;

droptablehua.result;

createtablehua.resultas

selectlowprice.stockname,lowprice.price,lowprice.zongshizhi,lowdata.*fromhua.lowpriceleftjoinhua.lowdataonlowprice.stockcode=lowdata.stockcode;

quit;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1