考虑数据中 IBM 股票的日简单收益率,检验收益率是否服从正态分布。
library(fBasics)
setwd("D:\\New_Folder\\Study_Programming\\R_Programme\\R-Financial-Time-Series\\Tsay3 data")
da=read.table("d-ibm3dx7008.txt",header=T)
# header=T 表示第一行为变量名称,如果不这么设置(header=F),那么需要重新定义变量名称
dim(da) # Find size of 'da',共9845行数据,5个变量
## [1] 9845 5
da[1,] # See the firSt row of the data.
## Date rtn vwretd ewretd sprtrn
## 1 19700102 0.000686 0.012137 0.03345 0.010211
ibm=da[,2] # Obtain IBM simple returns.
sibm=ibm*100 # Percentage simple returns.
basicStats(sibm) # basicStats:基本统计量
## sibm
## nobs 9845.000000
## NAs 0.000000
## Minimum -22.963000
## Maximum 13.163600
## 1. Quartile -0.857100
## 3. Quartile 0.883300
## Mean 0.040161
## Median 0.000000
## Sum 395.387600
## SE Mean 0.017058
## LCL Mean 0.006724
## UCL Mean 0.073599
## Variance 2.864705
## Stdev 1.692544
## Skewness 0.061399
## Kurtosis 9.916359
s1=skewness(sibm)
t1=s1/sqrt(6/dim(da)[1]) # Compute the test statistic 检验统计量
t1
## [1] 2.487093
## attr(,"method")
## [1] "moment"
pv=2*(1-pnorm(t1)) # Compute t-value
pv
## [1] 0.01287919
## attr(,"method")
## [1] "moment"
libm=log(ibm+1)*100 # Turn to log returns in percentages.
# libm: percentage of log return
t.test(libm) # t.test: test H0:if libm is zero
##
## One Sample t-test
##
## data: libm
## t = 1.5126, df = 9844, p-value = 0.1304
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## -0.007641473 0.059290531
## sample estimates:
## mean of x
## 0.02582453
结果显示p值>0.05,不能拒绝原假设
indicating that the daily simple returns of IBM stock are significantly skewed to the right at the 5% level.
normalTest(libm,method = 'jb') # JB statistics in testing normality
##
## Title:
## Jarque - Bera Normalality Test
##
## Test Results:
## STATISTIC:
## X-squared: 60921.9343
## P VALUE:
## Asymptotic p Value: < 2.2e-16
结果显示p值<0.05,拒绝原假设,即不服从正态性。
(From the output, the excess kurtosis is high, indicating that the daily simple returns of IBM stock have heavy tails.)