测试结果


简述

这里我们的目标是从中证800中筛选出预期收益会高于市场(沪深300指数收益)的股票,如果预期下期收益较大,则买进该股票,并且只持有一个月。

计算的指标包括:

以下所有的尝试的模型都是SVM,采用了R PACKAGE是e1071,参数设置如下:

#   fit=svm(excess.ret.lead1~.,data=train,kernal="polynomial",degree=2,
#       gamma=2^(-0),coef0=1,cost=4)

数据分为日度数据和月度数据,日数数据从13年7月1日至14年7月1日,而月度数据则是09年1月至14年5月,在月度数据中,指标主要是基本面的指标,而在日度数据中则计算了许多技术指标,对各种指标的预测效果分组做出尝试.



关于SVM的简介

fig1 fig2

由图,调节参数,定义类别为1和-1.当\( y_i=1 \)可使 \[ \mathbf{w}\mathbf{x_i}+\mathbf{b} \geq 1 \]

当\( y_i=-1 \)时,使得

\[ \mathbf{w}\mathbf{x_i}+\mathbf{b} \leq 1 \]

亦即: \[ y_i(\mathbf{w}\mathbf{x_i}+\mathbf{b}) \geq 1 \]

为获得最大决策面边缘,则我们的目标函数为:

\[ min \frac{\| \mathbf{w} \|^2}{2} \]

将之转化为拉格朗日函数:

\[ L_p=\frac{1}{2} \| \mathbf{w} \|^2 - \sum \lambda_i (y_i (\mathbf{w} * \mathbf{x_i}+\mathbf{b} )-1) \]


当原训练样本线性不可分时,可利用某个非线性变换将原数据空间中的样本点映射到更高维空间中,使得在此高维空间中的映射点线性可分。而通过使用核函数,我们可以使得变换后空间的点积可以表示为原空间点积的某个函数,使得计算可以在原空间上进行,而且计算的开销非常小.

因此,非线性的SVM的学习可定义如下:

在约束条件 \[ y_i(\mathbf{w}\mathbf{ \Phi(x_i)}+\mathbf{b}) \] 下,最小化边缘: \[ min \frac{\| \mathbf{w} \|^2}{2} \]

将之转化为拉格朗日优化问题进行求解.


类似于线性回归,将回归函数写成:

\[ f(x)= \mathbf{w} * \phi (\mathbf{x}) + b \]

通过将原空间映射到一个高维空间上,将低维空间上的非线性问题转化为高维空间的线性问题,并定义损失函数如下: 当\( | f(x_i) -y_i | < \epsilon \)时, \[ L_D(x,y,f(x))=0 \] 当$ | f(x_i) -y_i | \geq \epsilon$时, \[ L_D(x,y,f(x))= | f(x_i) -y_i | - \epsilon \]

并定义目标函数为: \[ min \ R(w,b)=\frac{\| \mathbf{w} \|^2}{2} + c \sum{L_D} \] 参数C通常需要用户自己决定.


日度数据

技术指标


plot of chunk unnamed-chunk-2plot of chunk unnamed-chunk-2plot of chunk unnamed-chunk-2


plot of chunk unnamed-chunk-3plot of chunk unnamed-chunk-3plot of chunk unnamed-chunk-3


\[ (R-RM)_{t+1} \thicksim (R-RM)_{t} +amount_t +换手率_t +OBV_t+ PVT_t + VMA_t \]

plot of chunk unnamed-chunk-4plot of chunk unnamed-chunk-4plot of chunk unnamed-chunk-4


\[ (R-RM)_{t+1} \thicksim (R-RM)_{t} +amount_t +换手率_t + VMA_t \]

plot of chunk unnamed-chunk-5plot of chunk unnamed-chunk-5plot of chunk unnamed-chunk-5


\[ (R-RM)_{t+1} \thicksim (R-RM)_{t}+OBV_t+ PVT_t \]

plot of chunk unnamed-chunk-6plot of chunk unnamed-chunk-6plot of chunk unnamed-chunk-6


plot of chunk unnamed-chunk-7plot of chunk unnamed-chunk-7plot of chunk unnamed-chunk-7

plot of chunk unnamed-chunk-8plot of chunk unnamed-chunk-8plot of chunk unnamed-chunk-8

plot of chunk unnamed-chunk-9plot of chunk unnamed-chunk-9plot of chunk unnamed-chunk-9

plot of chunk unnamed-chunk-10plot of chunk unnamed-chunk-10plot of chunk unnamed-chunk-10

基本面指标

这里的基本面指标包括股票本身的一些常见的财务指标:市盈率市净率市销率市现率,同时还计算了一些由此拓展出来的指标,包括SMB,HML,MOM等.

plot of chunk unnamed-chunk-11plot of chunk unnamed-chunk-11plot of chunk unnamed-chunk-11


月度数据

在对月度数据进行尝试的过程中,并没有计算技术指标,主要的指标还是基本面指标以及由其拓展出来的其他指标,结果如下: plot of chunk unnamed-chunk-12plot of chunk unnamed-chunk-12plot of chunk unnamed-chunk-12


SUMMARY

月数据

———-

指标的计算以及相应的函数

技术指标

包括今天在内的过去若干天收益的算术平均数,这里取的天数为10;

getMA<-function(temp,k){
  num=dim(temp)[1]
  temp$MA=NA

  for(i in (k+1):num){
     temp$MA[i]=mean(temp$ret[(i-k+1):i],na.rm=TRUE)
  }  

  for(j in 1:k){
    temp$MA[j]=mean(temp$ret[1:j],na.rm=TRUE)
  } 
  temp
}
getEMA<-function(temp,k,a){ 
  num=dim(temp)[1]
  temp$EMA=0
  if(!is.na(temp$ret[1])){
    temp$EMA[1]=temp$ret[1]
  }
  w=a/(k+1)
  for(i in 2:num){

    if(!is.na(temp$ret[i])){
    temp$EMA[i]=w*temp$ret[i]+(1-w)*temp$EMA[i-1]
    }
    else{
      temp$EMA[i]=temp$EMA[i-1]
    }
  }
  name=paste("EMA",k,sep="")
  names(temp)[which(names(temp)=="EMA")]=name
  temp
}

\[ MACD_T=EMA(12)_t - EMA(26)_t \]

getRSI<-function(temp,k){ 
  num=dim(temp)[1]
  temp$RSI=NA  
  for(i in (k+1):num){
    tem=temp[(i-k+1):i,]
    temp1=subset(tem,ret>0)
    temp2=subset(tem,ret<0) 
    temp$RSI[i]=sum(temp1$ret,na.rm=TRUE)/(sum(temp1$ret,na.rm=TRUE)+ +
                                    (-1)*sum(temp2$ret,na.rm=TRUE))
  }   
  for(i in 1:k){
    tem=temp[1:i,]
    temp1=subset(tem,ret>0)
    temp2=subset(tem,ret<0)
    temp$RSI[i]=sum(temp1$ret,na.rm=TRUE)/(sum(temp1$ret,na.rm=TRUE)+ +
                                    (-1)*sum(temp2$ret,na.rm=TRUE))
  } 
  temp
}

\[ WMS_t = (CLOSE-LOW)/(HIGH-LOW) \] 收盘价减去最低价与最高价减去最低价的比值

\[ OBV_t=OBV_{t-1}+sgn*(VOLUME_t) \] 上式中,OBV初始值取零,VOLUME为当日成交量.

getOBV<-function(temp){
  num=dim(temp)[1]
  temp$OBV=0  
  t=temp$ret/(abs(temp$ret))
  t[is.nan(t)|is.na(t)]=0
  for(i in 2:num){
    if(!is.na(temp$成交量[i])){
      temp$OBV[i]= temp$OBV[i-1]+t[i]*(temp$成交量[i])
    }
    else{
      temp$OBV[i]= temp$OBV[i-1]
    }
  }
  temp
}

收益乘以交易量的累加.

getPVT<-function(temp){ 
  x=(temp$ret)*(temp$成交量)
  x[is.na(x)]=0
  temp$PVT=cumsum(x)
  temp
}

基本面指标

前N个月中累积收益中的赢家(前30%)减去输家(后30%)在本月的平均收益之差。

getMOM<-function(data,td,q1,q2,k){

  # k为需要计算的动量月份数 
  N=length(td)
  MOM=rep(NA,N)

  c=c("简称","日期","ret","总市值","收盘价")
  tem=data[,c]

  ID=data$简称
  ID=ID[!duplicated(ID)]
  N_id=length(ID)

  tem1=NULL

  for(i in 1:N_id){
    temp=subset(tem,简称==ID[i])
    num=dim(temp)[1]
    if(num > 18){ 
      temp$cumret1=NA
      temp$cumret1[(k+2):num]=(  (temp$收盘价)[(k+1):(num-1)]-    +
                                   temp$收盘价[1:(num-(k+1))])/       +
        temp$收盘价[1:(num-(k+1))]

      tem1=rbind(tem1,temp)}
  }

  for(i in (k+2):N){  
    temp=subset(tem1,日期==td[i])
    temp$cumret1[is.na(temp$cumret1)]=mean(temp$cumret1,na.rm=TRUE)

    q =quantile(temp$cumret1,probs=c(q1,q2),na.rm=TRUE)

    t1=(temp$cumret1 < q[1])
    t2=(temp$cumret1 > q[2])

    m1=temp[t1,]
    m2=temp[t2,]

    MOM[i]= mean(m2$ret,na.rm=TRUE) - mean(m1$ret,na.rm=TRUE)
  } 
  mom=data.frame(td,MOM)
  names(mom)[2]=paste("MOM",k,sep="")
  mom
}

小市值规模股票较大市值股票收益之差,按总市值排序,50%分位点以下视为小股票,50%以上视为大股票.

getSMB<-function(data,td,q1,q2){
  SMB=NULL
  N=length(td)

  c=c("简称","日期","ret","总市值","市净率")
  tem<-data[,c]

#   flag<-tem$简称[(tem$市净率)<0]
#   flag<-flag[!duplicated(flag)]
#   
#   t=!(tem$简称%in%flag)
#   tem<-tem[t,]

  for(i in 1:N){
    temp=subset(tem,日期==td[i])

    q <-quantile(temp$总市值,probs=c(q1,q2),na.rm=TRUE)

    t1<-(temp$总市值<q[1])
    t2<-(temp$总市值>q[2])
    m1<-mean(temp$ret[t1],na.rm=TRUE)
    m2<-mean(temp$ret[t2],na.rm=TRUE)
    # SMB为小规模的股票收益减去大规模股票的收益
    SMB[i]=m1-m2
  } 
  smb=data.frame(td,SMB)
  smb
}