楼主: xuchao_wuxi
1861 5

[程序分享] 求助:如何筛选一段时间内未出现连续10个交易日没有交易的债券数据 [推广有奖]

  • 0关注
  • 1粉丝

已卖:1051份资源

博士生

16%

还不是VIP/贵宾

-

威望
0
论坛币
48528 个
通用积分
3.3007
学术水平
2 点
热心指数
3 点
信用等级
2 点
经验
3814 点
帖子
104
精华
0
在线时间
176 小时
注册时间
2007-8-5
最后登录
2019-9-19

楼主
xuchao_wuxi 发表于 2017-8-27 11:06:13 |AI写论文
100论坛币
求助:最近在编程,对2014年1月1日到2017年6月30日所有债券交易数据进行筛选,筛选规则是:把这段时间内没有出现过连续10个交易日无交易的债券选出来,现有数据中,如果当天该债券没有交易,则当天的交易数据中不含该债券,若有交易,则含该债券,并包括对应的交易量(volume)
现在的数据格式是:

date

code

name

volume

duration

tudu

highprice

lowprice

price

2016/3/31

136083.SH

15浙交02

16000.40

8.1792

77.2523

105.7164

101.5964

105.7164

2016/3/31

118489.SZ

16奥园01

15000.00

3.4304

13.7358

100.8910

100.8910

100.8910



求大神指导,如何用SAS程序进行处理。

最佳答案

关键词:交易日 DateCode Duration volume ration

沙发
deem 学生认证  发表于 2017-8-27 11:06:14
  1. *simulate bond trading data;
  2. data bond;
  3.         format date mmddyy10.;
  4.         do code=1 to 5;
  5.                 do date=20000 to 20200 by 2;
  6.                         output;
  7.                 end;
  8.         end;
  9.        
  10.         do code=6 to 10;
  11.                 do date=20000 to 20200;
  12.                         output;
  13.                 end;
  14.         end;
  15. run;


  16. *generate trading date calendar;
  17. proc sql;
  18.         create table trading_date as
  19.         select distinct date from bond
  20.         order by date;
  21.         quit;
  22.        
  23. data trading_date;
  24.         set trading_date;
  25.         index+1;
  26.         run;
  27.        
  28. *reindex bond data by trading date;
  29. proc sql;
  30.         create table bond2 as
  31.         select b.index, a.* from bond a right join trading_date b
  32.         on a.date = b.date
  33.         order by code, date;
  34.         quit;

  35. * count continuous trading date;       
  36. data bond3;
  37.         set bond2;
  38.         by code;
  39.         retain continuous_sign 0;
  40.         if index=lag(index)+1 then continuous_count+1;
  41.         else continuous_count=1;
  42.         if first.code then continuous_count=0;
  43.         run;
  44.        

  45. proc sql;
  46.         create table bond4 as
  47.         select code, max(continuous_count) as max_count from bond3
  48.         group by code
  49.         having max(continuous_count)<10;
  50.         quit;
  51.        

  52.        
  53.        
复制代码

藤椅
deem 学生认证  发表于 2017-8-27 14:11:18
  1. *simulate bond trading data;
  2. data bond;
  3.         format date mmddyy10.;
  4.         do code=1 to 5;
  5.                 do date=20000 to 20200 by 2;
  6.                         output;
  7.                 end;
  8.         end;
  9.        
  10.         do code=6 to 10;
  11.                 do date=20000 to 20200;
  12.                         output;
  13.                 end;
  14.         end;
  15. run;


  16. *generate trading date calendar;
  17. proc sql;
  18.         create table trading_date as
  19.         select distinct date from bond
  20.         order by date;
  21.         quit;
  22.        
  23. data trading_date;
  24.         set trading_date;
  25.         index+1;
  26.         run;
  27.        
  28. *reindex bond data by trading date;
  29. proc sql;
  30.         create table bond2 as
  31.         select b.index, a.* from bond a right join trading_date b
  32.         on a.date = b.date
  33.         order by code, date;
  34.         quit;

  35. * count continuous trading date;       
  36. data bond3;
  37.         set bond2;
  38.         by code;
  39.         retain continuous_sign 0;
  40.         if index=lag(index)+1 then continuous_count+1;
  41.         else continuous_count=1;
  42.         if first.code then continuous_count=0;
  43.         run;
  44.        

  45. proc sql;
  46.         create table bond4 as
  47.         select code, max(continuous_count) as max_count from bond3
  48.         group by code
  49.         having max(continuous_count)<10;
  50.         quit;
  51.        

  52.        

  53.        
复制代码


板凳
xuchao_wuxi 发表于 2017-8-29 14:14:55
deem 发表于 2017-8-27 14:11
我想要的是:把没有出现过连续10个交易日无交易的债券选出来,即,如果有一只债券在2014年1月1日到2017年6月30日中,出现过连续10个交易日无交易,则把这只债券剔除。

报纸
yyun723 发表于 2017-8-29 15:37:07
先得到一个交易日列表,然后和日数据做笛卡尔积,设一个字段tag,交易量为0的设成1,再按代码日期排序,用expand移动10步tag累加,tag等于10的过滤

地板
xuchao_wuxi 发表于 2017-8-29 20:56:03
deem 发表于 2017-8-27 14:11
你的答案对我编程很有帮助。感谢。

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

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