MBAlib百科对动量策略和逆转策略作了精致的的解说:

动量/逆转策略指的是价格看涨而买入胜券在握的结成。,卖空的人者/赢家的买卖策略。它的首要踏是:

  决定目的一份买卖作为买卖目标的扣押。

  其次,选择一段工夫作为表演评价期。,通常指值得买的东西结成的构成期或排序期。。

  三。计算各样品在构成期的成品率。。

  (4)着陆各样品在成形期的成品率显得庞大。,目的集市中全部的范本保密的的上扬、降序打扮打扮,以后把它们掉进空军大队。,在位的,最大生产能力组高地赢家结成。,生产能力最底下的的一组称为失败者结成。。

  构成期后或一段工夫后。,选择另独身工夫大量。,作为赢家和输家的接合的的持续工夫。。

  独身延续的或淬熄的时间。,不时反复 (1)行动。

  ⑦业绩评价。计算每个防腐处理公转的平衡放弃和t罪状量。,倘若T罪状量揭晓动量/逆转策略的放弃是S,了解内幕的人表现,动量/反向战术是成的。,研究院在动量/逆转景象。,不同的亦反。

我试着逐渐应用SAS来走完结束运算。:一份的扣押是完全A股在奇纳河。,构成期以P周表现。,结成坚持期用Q周表现。,这时是P.,Q仅占1。,2,3。随访t勘探必要使完备。。

这时,份量知识零碎收录2000多股A股的每日知识。。

* 份量是数不清的一份的每日知识。,选择2009年至2012长年累月度知识
data test1;
   set test;
       year=年(日期);
       month=month(date);
       week=week(date);
   keep id date year month week close ; 
   if    2009<=year<=2012 then output;
run;
*计算两年期间一份的日线知识大量,剔除较短知识;
proc freq data=test1 noprint ;
   table id /out=test2(keep=id count)   ;
run;
data test3;
   merge test1 test2;
   by id;
   if count<360  then delete ;
   if id eq 滞后(ID) do;
   ret_1=log(close)-log(lag(close));
   end;
run;

proc sort data=test3;by id;run;
*计算每支一份的周累计进项;
proc sql;
   create table test4 as
      select *,
	         sum(ret_1) as sum_ret
		 from test3	
		 group by id,year,month,week;
quit;
*计算日均放弃,对其举行排序,进而对2000多只一份举行分组;
proc sql;
   create table test5 as
      select distinct id,year,month,week,sum_ret
	     from test4;
quit;


*选定独身份量时点,例如以2011年1月第一周开始,找到该时点前p周到知识,
进而按照前P周到累计放弃举行排序,这时p取1,2,3;
data test6;
   set test5;
   if id eq lag(id) then do;
      ret_lag1=lag(sum_ret);
      ret_lag2=lag(sum_ret)+lag2(sum_ret);
      ret_lag3=ret_lag2+lag3(sum_ret);
   end;
run;
*考虑lag函数产生缺失值的问题,朕选取观测工夫点位2011年1月第一周;
data test7;
   set test6;
   if year=2011 & month=1 & week=1 then output;
run;

*对观测工夫点举行前P周到累计进项举行排序:升序:轮转策略;降序打扮:动量策略;
%macro rank(num);
%do i=1 %to #
proc rank data=test7 out=test7_&i group=14;
   var ret_lag&i;
   ranks group;
run;
data test_dong&i test_fan&i;
   set test7_&i;
   if group=0 then output test_fan&i;
   if group=13 then output test_dong&i;
run;

*从待选一份中选出动量结成一份,从观测日开始,计算持有结成内一份Q周的累计进项;

data new;
   set test6;
   if year<2011 then delete;
run;
*计算动量策略构成期为1周,持有期为1,2,3周到进项,同理可以计算
构成期为2/3周到动量策略;


data merge_d&i;
   merge test_dong&i(in=a) new(in=b);
   by id;
   if  a=1 & b=1 then output;
run;
proc expand data=merge_d&i out=d_&i;
   convert ret_lag1=ret1 / transform=(lead 2);
   convert ret_lag2=ret2 / transform=(lead 3);
   convert ret_lag3=ret3 / transform=(lead 4);
run;
data d_&i;
   set d_&i;
   if year=2011 & month=1 & week=1 then output;
run;

%end;
%mend;
%rank(3);

想出将下面信号接收的结成和沪深300说明的举行比对,反省其生产能力。。接下来朕必要计算上海和深圳300说明的I的放弃。,以后举行差别区别。。上海和深圳300说明的知识必要先下载。。

上海、深圳300说明的生产能力计算
data sz399300_1;
   set sz399300;
   year=year(var1);
   month=month(var1);
   week=week(var1);
   ret=dif(log(var5));
   drop var: ;
run;
   
proc sql;
   create table sz399300_2 as
      select distinct year,month,week,
	                  和(RET) as sum_ret
	     from sz399300_1
		 group by year,month,week ;
quit;

data sz399300_3;
   set sz399300_2;
   ret_lag1=lag(sum_ret);
   ret_lag2=lag(sum_ret)+lag2(sum_ret);
   ret_lag3=ret_lag2+lag3(sum_ret);
run;

proc expand data=sz399300_3 out=sz399300_4;
   convert ret_lag1=ret1 / transform=(lead 2);
   convert ret_lag2=ret2 / transform=(lead 3);
   convert ret_lag3=ret3 / transform=(lead 4);
run;
data sz399300_4;
   set sz399300_4;
   if year=2011 & month=1 & week=1 then output;
run;


上海、深圳300与值得买的东西结成进项的区别
%macro diff_hs(num);
%do i= 1 %to #
proc sql;
   create table d&i_need as
      select distinct a.year,a.month,a.week,
	         mean() as ret1,
			 mean() as ret2,
			 mean() as ret3
	  from d_&i as a
	  join sz399300_4 as b
	  on a.year=b.year;
quit;

proc sql;
   create table f&i_need as
      select distinct a.year,a.month,a.week,
	         mean() as ret1,
			 mean() as ret2,
			 mean() as ret3
	  from f_&i as a
	  join sz399300_4 as b
	  on a.year=b.year;
quit;

%end;
%mend;

%diff_hs(3);

以下是构成期和防腐处理期(P),q)以月表现的信号。:

libname yu E:TMP
* 份量是数不清的一份的每日知识。,选择2009年至2012长年累月度知识
data test1;
   set YU.test;
       year=年(日期);
       month=month(date);
   keep id date year month  close ; 
   if    2009<=year<=2012 then output;
run;
*计算两年期间一份的日线知识大量,剔除较短知识;
proc freq data=test1 noprint ;
   table id /out=test2(keep=id count)   ;
run;
data test3;
   merge test1 test2;
   by id;
   if count<360  then delete ;
   if id eq 滞后(ID) do;
   ret_1=log(close)-log(lag(close));
   end;
run;

proc sort data=test3;by id;run;
*计算每支一份的月累计进项;
proc sql;
   create table test4 as
      select distinct id,year,month,
	         sum(ret_1) as sum_ret
		 from test3	
		 group by id,year,month;
quit;

*选定独身份量时点,例如以2011年1月1日开始,找到该时点前p月到知识,
进而按照前P月到累计放弃举行排序,这时p取1,2,3,4,5,6;
data test5;
   set test4;
   if id eq lag(id) then do;
      ret_lag1=lag(sum_ret);
      ret_lag2=lag(sum_ret)+lag2(sum_ret);
      ret_lag3=ret_lag2+lag3(sum_ret);
	  ret_lag4=ret_lag3+lag4(sum_ret);
	  ret_lag5=ret_lag4+lag5(sum_ret);
	  ret_lag6=ret_lag5+lag6(sum_ret);
   end;
run;

*考虑lag函数产生缺失值的问题,朕选取观测工夫点位2011年1月第一周;
data test6;
   set test5;
   if year=2011 & month=10  then output;
run;

*对观测工夫点举行前P周到累计进项举行排序:升序:轮转策略;降序打扮:动量策略;
%macro rank(num);
%do i=1 %to #
proc rank data=test6 out=test6_&i group=14;
   var ret_lag&i;
   ranks group;
run;
data test_dong&i test_fan&i;
   set test6_&i;
   if group=0 then output test_fan&i;
   if group=13 then output test_dong&i;
run;

*从待选一份中选出动量结成一份,从观测日开始,计算持有结成内一份Q周的累计进项;

data new;
   set test6;
   if year<2011 then delete;
run;
*计算动量策略构成期为1周,持有期为1,2,3周到进项,同理可以计算
构成期为2/3周到动量策略;


data merge_d&i;
   merge test_dong&i(in=a) new(in=b);
   by id;
   if  a=1 & b=1 then output;
run;
proc expand data=merge_d&i out=d_&i;
   convert ret_lag1=ret1 / transform=(lead 2);
   convert ret_lag2=ret2 / transform=(lead 3);
   convert ret_lag3=ret3 / transform=(lead 4);
   convert ret_lag4=ret4 / transform=(lead 5);
   convert ret_lag5=ret5 / transform=(lead 6);
   convert ret_lag6=ret6 / transform=(lead 7);
run;
data d_&i;
   set d_&i;
   if year=2011 & month=10  then output;
run;

data merge_f&i;
   merge test_fan&i(in=a) new(in=b);
   by id;
   if  a=1 & b=1 then output;
run;
proc expand data=merge_f&i out=f_&i;
   convert ret_lag1=ret1 / transform=(lead 2);
   convert ret_lag2=ret2 / transform=(lead 3);
   convert ret_lag3=ret3 / transform=(lead 4);
   convert ret_lag4=ret4 / transform=(lead 5);
   convert ret_lag5=ret5 / transform=(lead 6);
   convert ret_lag6=ret6 / transform=(lead 7);
run;
data f_&i;
   set f_&i;
   if year=2011 & month=10  then output;
run;
%end;
%mend;
%rank(6);

上海、深圳300说明的生产能力计算
data sz399300_1;
   set YU.sz399300;
   year=year(var1);
   month=month(var1);
   ret=dif(log(var5));
   drop var: ;
run;
   
proc sql;
   create table sz399300_2 as
      select distinct year,month,
	                  和(RET) as sum_ret
	     from sz399300_1
		 group by year,month ;
quit;

data sz399300_3;
   set sz399300_2;
   ret_lag1=lag(sum_ret);
   ret_lag2=lag(sum_ret)+lag2(sum_ret);
   ret_lag3=ret_lag2+lag3(sum_ret);
   ret_lag4=ret_lag3+lag4(sum_ret);
   ret_lag5=ret_lag4+lag5(sum_ret);
   ret_lag6=ret_lag5+lag6(sum_ret);
run;

proc expand data=sz399300_3 out=sz399300_4;
   convert ret_lag1=ret1 / transform=(lead 2);
   convert ret_lag2=ret2 / transform=(lead 3);
   convert ret_lag3=ret3 / transform=(lead 4);
   convert ret_lag4=ret4 / transform=(lead 5);
   convert ret_lag5=ret5 / transform=(lead 6);
   convert ret_lag6=ret6 / transform=(lead 7);
run;
data sz399300_4;
   set sz399300_4;
   if year=2011 & month=10  then output;
run;


%macro diff_hs(num);
%do i= 1 %to #
proc sql;
   create table d_need&i as
      select distinct a.year,a.month,
	         mean() as ret1,
			 mean() as ret2,
			 mean() as ret3,
	         mean() as ret4,
			 mean() as ret5,
			 mean() as ret6
	  from d_&i as a
	  join sz399300_4 as b
	  on a.year=b.year;
quit;

proc sql;
   create table f_need&i as
      select distinct a.year,a.month,
	         mean() as ret1,
			 mean() as ret2,
			 mean() as ret3,
			 mean() as ret4,
			 mean() as ret5,
			 mean() as ret6
	  from f_&i as a
	  join sz399300_4 as b
	  on a.year=b.year;
quit;

%end;
%mend;

%diff_hs(6);


data final_d9; 
   set d_need:;
run;
data final_f9;
   set f_need:;
run;
proc datasets library=work;
   delete d_: f_: merge_: Sz399300: test: new;
run;
quit;

倘若在日本单位份量,可以轻蔑地改建一下。:

E::份量国际A股知识,上海和深圳300说明的SZ399 300知识
libname gao E:TMP
data test1;
   set gao.test;
   if id eq 滞后(ID) do;
      RIt = DIF(完全关闭)/滞后(完全关闭)
   end;
   if 年(日期)<2009 then delete; 
   keep id date ret close;
run;

*计算两年期间一份的日线知识大量,剔除较短知识;
proc freq data=test1 noprint ;
   table id /out=test2(keep=id count)   ;
run;
data test3;
   merge test1 test2;
   by id;
   if count<360  then delete ;
run;

*选定独身份量时点,例如以2011年1月5日,计算前P日累计放弃并举行排序,
这时p取21,42;
proc expand data=test3 out=test4 method=none;
   by id;
   convert ret =ret_lag1 / transformout=(movsum 21);
   convert ret =ret_lag2 / transformout=(movsum 42);   
run;
*选定份量日;
data test5;
   set test4;
   if date="05jan2012"d then output;
run;

*以05jan2011日前21/42日累计放弃举行排序,生产动量结成和逆转结成;
%macro rank(num);
%do i=1 %to #
proc rank data=test5 out=test5_&i group=10;
   var ret_lag&i;
   ranks group;
run;
data test_dong&i test_fan&i;
   set test5_&i;
   if group=0 then output test_fan&i;
   if group=9 then output test_dong&i;
run;

*从待选一份中选出动量结成一份,从观测日开始,计算持有结成内一份Q日的累
计进项;

data new;
   set test4;
   if date<"05jan2012"d then delete;
run;
*计算动量策略构成期为1,持有期为1,2,3进项,同理可以计算
构成期为2/3到动量策略;

data merge_d&i;
   merge test_dong&i(in=a) new(in=b);
   by id;
   if  a=1 & b=1 then output;
run;
proc expand data=merge_d&i out=d_&i;
   convert ret_lag1=ret1 / transform=(lead 21);
   convert close=close21 / transform=(lead 21);
   convert ret_lag2=ret2 / transform=(lead 42);
   convert close=close42 / transform=(lead 42);

run;

data d_&i;
   set d_&i;
   if date="05jan2012"d  then output;
run;

data merge_f&i;
   merge test_fan&i(in=a) new(in=b);
   by id;
   if  a=1 & b=1 then output;
run;
proc expand data=merge_f&i out=f_&i;
   convert ret_lag1=ret1 / transform=(lead 21);
   convert close=close21 / transform=(lead 21);
   convert ret_lag2=ret2 / transform=(lead 42);
   convert close=close42 / transform=(lead 42);
run;
data f_&i;
   set f_&i;
   if date="05jan2012"d then output;
run;
%end;
%mend;
%rank(2);


上海、深圳300说明的生产能力计算

data sz399300_1;
   set gao.sz399300(rename=(var1=date var5=close));
   RIt = DIF(完全关闭)/滞后(完全关闭)
   drop var: ;
run;

proc expand data=sz399300_1 out=sz399300_2 method=none;
   convert ret =ret_lag1 / transformout=(sum 21);
   convert ret =ret_lag2 / transformout=(sum 42); 
run;

proc expand data=sz399300_2 out=sz399300_3;
   convert ret_lag1=ret1 / transform=(lead 21);
   convert close=close21 / transform=(lead 21);
   convert ret_lag2=ret2 / transform=(lead 42);
   convert close=close42 / transform=(lead 42);
run;
data sz399300_4;
   set sz399300_3;
   c0=close*300;
   c21=close21*300;
   C42=close42*300;
   if date="05jan2012"d  then output;
run;


%macro diff_hs(num);
%do i= 1 %to #
proc sql;
   create table d_need&i as
      select distinct a.date,
	         mean() as ret1,
			 mean() as ret2,
            (sum((ceil()/)*21) -c21)/c0 as r21,	
            (sum((ceil()/)*42) -c42)/c0 as r42

	  from d_&i as a
	  join sz399300_4 as b
	  on a.date=b.date;
quit;

proc sql;
   create table f_need&i as
      select distinct a.date,
	         mean() as ret1,
			 mean() as ret2,
            (sum((ceil()/)*21) -c21)/c0 as r21,	
            (sum((ceil()/)*42) -c42)/c0 as r42
	  from f_&i as a
	  join sz399300_4 as b
	  on a.date=b.date;
quit;

%end;
%mend;

%diff_hs(2);



data final_d1; 
   set d_need:;
run;
data final_f1;
   set f_need:;
run;

Leave a Comment

电子邮件地址不会被公开。 必填项已用*标注