library(readr)
library(zoo)
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(xts)
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
d.intel <- read_table(
  "D:/齐安静 教学/时间序列分析/北大/ftsdata/m-intcsp7309.txt",
  col_types=cols(
    .default=col_double(),
    date=col_date("%Y%m%d")
  ))
knitr::kable(d.intel[1:5,])
date intc sp
1973-01-31 0.010050 -0.017111
1973-02-28 -0.139303 -0.037490
1973-03-30 0.069364 -0.001433
1973-04-30 0.086486 -0.040800
1973-05-31 -0.104478 -0.018884
xts.intel <- xts(
  log(1 + d.intel[["intc"]]), d.intel[["date"]]
)
tclass(xts.intel) <- "yearmon"
ts.intel <- ts(c(coredata(xts.intel)), start=c(1973,1), frequency=12)
plot(ts.intel, ylab="log return", 
     main="Intel Stock Price Monthly Log Return")

forecast::Acf(ts.intel, main="ACF of log return")
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo

Box.test(ts.intel, lag=12, type="Ljung")
## 
##  Box-Ljung test
## 
## data:  ts.intel
## X-squared = 18.676, df = 12, p-value = 0.09665
t.test(as.vector(ts.intel))
## 
##  One Sample t-test
## 
## data:  as.vector(ts.intel)
## t = 2.3788, df = 443, p-value = 0.01779
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.00249032 0.02616428
## sample estimates:
## mean of x 
## 0.0143273
forecast::Acf(abs(ts.intel), 
  main="Intel对数收益率绝对值的ACF估计")

Box.test(abs(ts.intel), lag=12, type="Ljung")
## 
##  Box-Ljung test
## 
## data:  abs(ts.intel)
## X-squared = 124.91, df = 12, p-value < 2.2e-16
"archTest" <- function(x, m=10){
  # Perform Lagrange Multiplier Test for ARCH effect of a time series
  # x: time series, residual of mean equation
  # m: selected AR order

  y <- (x - mean(x))^2
  T <- length(x)
  atsq <- y[(m+1):T]
  xmat <- matrix(0, T-m, m)
  for (j in 1:m){
    xmat[,j] <- y[(m+1-j):(T-j)]
  }
  lmres <- lm(atsq ~ xmat)
  summary(lmres)
}

4.4.1 Intel公司股票月对数收益率ARCH效应的检验

Box.test((ts.intel - mean(ts.intel))^2, 
         lag=12, type="Ljung")
## 
##  Box-Ljung test
## 
## data:  (ts.intel - mean(ts.intel))^2
## X-squared = 92.939, df = 12, p-value = 1.332e-14
archTest(ts.intel - mean(ts.intel), m=12)
## 
## Call:
## lm(formula = atsq ~ xmat)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.07440 -0.01153 -0.00658  0.00395  0.35255 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.005977   0.002249   2.658 0.008162 ** 
## xmat1        0.093817   0.048147   1.949 0.052013 .  
## xmat2        0.153085   0.048102   3.183 0.001569 ** 
## xmat3        0.146087   0.048614   3.005 0.002815 ** 
## xmat4        0.023539   0.049126   0.479 0.632075    
## xmat5        0.007347   0.049107   0.150 0.881139    
## xmat6        0.010342   0.047027   0.220 0.826050    
## xmat7        0.057183   0.047027   1.216 0.224681    
## xmat8        0.014320   0.047079   0.304 0.761149    
## xmat9        0.007157   0.046968   0.152 0.878965    
## xmat10      -0.019742   0.046566  -0.424 0.671810    
## xmat11      -0.057537   0.046041  -1.250 0.212116    
## xmat12       0.161945   0.045965   3.523 0.000473 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.03365 on 419 degrees of freedom
## Multiple R-squared:  0.1248, Adjusted R-squared:  0.0997 
## F-statistic: 4.978 on 12 and 419 DF,  p-value: 9.742e-08

4.4.2 美元对欧元汇率日对数收益率ARCH效应的检验

d.useu <- read_table(
  "D:/齐安静 教学/时间序列分析/北大/ftsdata/d-useu9910.txt", 
  col_types=cols(.default=col_double())
)
str(d.useu)
## spc_tbl_ [2,930 × 4] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ year: num [1:2930] 1999 1999 1999 1999 1999 ...
##  $ mon : num [1:2930] 1 1 1 1 1 1 1 1 1 1 ...
##  $ day : num [1:2930] 4 5 6 7 8 11 12 13 14 15 ...
##  $ rate: num [1:2930] 1.18 1.18 1.16 1.17 1.16 ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   .default = col_double(),
##   ..   year = col_double(),
##   ..   mon = col_double(),
##   ..   day = col_double(),
##   ..   rate = col_double()
##   .. )
xts.useu <- with(d.useu, xts(rate, make_date(year, mon, day)))
xts.useu.lnrtn <- diff(log(xts.useu))[-1,]
eu <- c(coredata(xts.useu.lnrtn))
plot(xts.useu.lnrtn, main="", 
     major.ticks="years", minor.ticks=NULL, 
     grid.ticks.on="years",
     format.labels="%Y")

作ACF图:

forecast::Acf(eu, main="")

作Ljung-Box白噪声检验:

Box.test(eu, lag=20, type="Ljung")
## 
##  Box-Ljung test
## 
## data:  eu
## X-squared = 30.585, df = 20, p-value = 0.06091

检验对数收益率均值是否等于零

t.test(eu)
## 
##  One Sample t-test
## 
## data:  eu
## t = 0.20217, df = 2928, p-value = 0.8398
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.0002122342  0.0002610303
## sample estimates:
##    mean of x 
## 2.439805e-05
forecast::Acf(eu^2, main="")

对作PACF图:

pacf(eu^2, main="")

- 此PACF表现不像是低阶的AR。

对作Ljung-Box白噪声检验:

Box.test(eu^2, lag=20, type="Ljung")
## 
##  Box-Ljung test
## 
## data:  eu^2
## X-squared = 661.45, df = 20, p-value < 2.2e-16

对序列作Engle的拉格朗日乘子法检验:

archTest(eu, m=20)
## 
## Call:
## lm(formula = atsq ~ xmat)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -3.229e-04 -3.369e-05 -1.949e-05  9.360e-06  2.100e-03 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.281e-05  2.535e-06   5.054 4.60e-07 ***
## xmat1       -3.022e-02  1.858e-02  -1.626 0.103966    
## xmat2        9.441e-02  1.859e-02   5.080 4.02e-07 ***
## xmat3       -1.226e-02  1.867e-02  -0.657 0.511513    
## xmat4        5.309e-02  1.864e-02   2.848 0.004428 ** 
## xmat5        2.668e-03  1.864e-02   0.143 0.886202    
## xmat6        7.200e-02  1.862e-02   3.868 0.000112 ***
## xmat7        5.625e-02  1.866e-02   3.015 0.002594 ** 
## xmat8       -1.599e-03  1.869e-02  -0.086 0.931828    
## xmat9        6.060e-02  1.867e-02   3.245 0.001188 ** 
## xmat10       2.794e-02  1.867e-02   1.497 0.134592    
## xmat11       6.413e-02  1.867e-02   3.435 0.000602 ***
## xmat12       4.020e-02  1.867e-02   2.153 0.031439 *  
## xmat13       4.375e-02  1.869e-02   2.341 0.019299 *  
## xmat14       2.900e-02  1.867e-02   1.553 0.120458    
## xmat15       4.927e-02  1.863e-02   2.645 0.008222 ** 
## xmat16       5.349e-02  1.865e-02   2.868 0.004163 ** 
## xmat17       5.702e-02  1.865e-02   3.058 0.002251 ** 
## xmat18       1.873e-03  1.868e-02   0.100 0.920136    
## xmat19      -1.836e-02  1.859e-02  -0.987 0.323583    
## xmat20       5.844e-02  1.859e-02   3.144 0.001683 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.483e-05 on 2888 degrees of freedom
## Multiple R-squared:  0.09265,    Adjusted R-squared:  0.08636 
## F-statistic: 14.74 on 20 and 2888 DF,  p-value: < 2.2e-16