楼主: liu022
1997 3

求助:判断数据的周期 [推广有奖]

  • 0关注
  • 6粉丝

已卖:181份资源

讲师

64%

还不是VIP/贵宾

-

威望
0
论坛币
879 个
通用积分
7.4013
学术水平
23 点
热心指数
18 点
信用等级
21 点
经验
3667 点
帖子
430
精华
1
在线时间
375 小时
注册时间
2007-5-21
最后登录
2025-10-22

楼主
liu022 发表于 2011-7-21 14:26:22 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
大家好!
       今天在算上证指数的周期。但是我没想出来算法来判断。要求:
            1) 波峰波谷交替出现
            2) 波峰波谷之间涨跌幅在20%以上。


      我的想法是滚动寻找前后45天的最大值和最小值,然后删除重复的波峰和波谷,然后再删除波谷大于相邻波峰的记录。但是这样做和绘图直接判断的结果并不一致。

      我尝试了两天,没能成功。请高手帮忙指点迷津:

数据在附件中。

我的程序代码如下:

libname data ".";
proc datasets lib=work kill;quit;
data Index;
set data.index;
if indexcd=1;
index=Clsindex;
keep date index ;
run;
%let dstin=index;
%let window=45;/*采用月份来衡量*/

data _null_;
       set &dstin. nobs=t;
       call symput("n",t);
       stop;
run;
%put &n.;
data dst;
set &dstin.;
xx=1;
run;
%macro split;
data dstout;
set _null_;
run;
%do k=1 %to &n.;
/*dm 'out; clear; log; clear;'; */
data h;
set dst;
if _n_ =&k.;
format d yymmdd10.;
d=date;
drop date;
run;
data tst;
merge dst h;
by xx;
run;
data tst;
set tst;
if abs(date-d)<&window.;
run;
proc sql;
create table topbottom as
select max(index) as max, min(index) as min
from tst;
quit;
data topbottom;
set  topbottom;
xx=1;
run;
data d;
merge tst topbottom;
by xx;
if index=min then bt=1;else bt=0;
if index=max then top=1;else top=0;
if bt=1 or top=1;
keep date bt top;
run;
data dstout;
set dstout d;
run;
%end;
%mend;
%split;
proc sort data=dstout nodup;by date;run;
/*删除连续的波峰和波谷*/
data s;
merge dstout(in=a) &dstin;
by date;
if a=1;
run;
data s;
set s;
if bt^=lag(bt) then x+1;
run;
proc means data=s noprint;
var index;
class x;
output out=out min=min max=max;
run;
data m;
merge s out;
by x;
drop _type_ _freq_;
run;
data m;
set m;
if (bt=1 and index=min) or (top=1 and index=max);
drop x min max;
run;
/*删除相邻记录:波峰低于波谷*/
data m;
set m;
if bt=1 and index>lag(index) then delete;
if top=1 and index<lag(index) then delete;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:datasets dataset libname symput delete 求助 数据 判断 周期

沙发
liu022 发表于 2011-7-21 19:55:58
自己顶下,没人回复啊~~~~~~~~~~~~~~~~

藤椅
jasonscut 在职认证  发表于 2011-7-23 11:27:10
你的问题看明白都要花点时间.

你得奖励些包子,而且重重有奖才行,重赏之下,必有勇夫!
北美统计金融博士

板凳
liu022 发表于 2011-7-23 15:10:35
3# jasonscut

呵呵~我也没有太多论坛币~

本着交流的想法来的。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-16 06:15