11
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

『経済・ファイナンスデータの計量時系列分析』章末問題をRで解く-第1章時系列分析の基礎概念-

Last updated at Posted at 2016-11-04

『経済・ファイナンスデータの計量時系列分析』

の章末問題で「コンピュータを用いて」とあるものをRで解いています。

数式の問題は『経済・ファイナンスデータの計量時系列分析』章末問題を解く-第1章時系列分析の基礎概念-

#1.3

wn<-function(m, s) {
  df<-rnorm(100, mean = m, sd = sqrt(s))
  plot(df, type = 'l', main = sprintf('μ=%d, σ=%d', m, s))
  abline(h = as.integer(min(df)):as.integer(max(df)), col = 'gray', lty = 2)
}

set.seed(1)
par(mfrow = c(3, 2))
par(mar = c(2, 2, 2, 0.5))
wn(0, 1)
wn(2, 1)
wn(-2, 1)
wn(0, 2)
wn(0, 3)
wn(2, 2)

1_1.3.png

#1.5

data<-read.table("economicdata.txt", header=T)
data.ts<-ts(data[,2:7],start=c(1975,1),frequency=12)
  • (1)
par(mfrow=c(3,2))
par(mar = c(2, 3, 2, 0.5))
ts.plot(data.ts[,1], xlab="", ylab="", ylim=c(0,3500), main="TOPIX")
ts.plot(data.ts[,2], xlab="", ylab="", ylim=c(0,120), main="実効為替レート")
ts.plot(data.ts[,3], xlab="", ylab="", ylim=c(0,120), main="鉱工業生産指数")
ts.plot(data.ts[,4], xlab="", ylab="", ylim=c(0,120), main="CPI")
ts.plot(data.ts[,5], xlab="", ylab="", ylim=c(0,6), main="失業率")
ts.plot(data.ts[,6], xlab="", ylab="", ylim=c(0,14), main="コールレート")

1_1.5.1.png

##(2)(3)

par(mfrow=c(3,1))
topix.d<-diff(log(data$topix))
topix.d.ts<-ts(topix.d*100,start=c(1975,1),frequency=12)
ts.plot(topix.d.ts, ylim=c(-20,15), main="TOPIX")
abline(h=seq(-20,15,5), col="gray", lty=2)
exrate.d<-diff(log(data$exrate))
exrate.d.ts<-ts(exrate.d*100,start=c(1975,1),frequency=12)
ts.plot(exrate.d.ts, ylim=c(-8,12), main="実効為替レート")
abline(h=seq(-8,12,2), col="gray", lty=2)
indprod.d<-diff(log(data$indprod))
indprod.d.ts<-ts(indprod.d*100,start=c(1975,1),frequency=12)
ts.plot(indprod.d.ts, ylim=c(-5,5), main="鉱工業生産指数")
abline(h=-5:5, col="gray", lty=2)

1_1.5.2_3.png

#(4)

par(mfrow=c(1,1))
par(mar = c(3, 3, 3, 3))
acf(diff(log(data$indprod)), xlim=c(1,20), ylim=c(-0.5,0.5))
lag=seq(1,10)
box.t<-apply(as.matrix(lag),1,function(x) {tmp=Box.test(diff(log(data$indprod)),type="Ljung", lag=x); return(c(tmp$statistic, tmp$p.value))})
out<-data.frame(matrix(box.t[1,], nrow=1))
out<-rbind(out, box.t[2,])
colnames(out)<-lag
rownames(out)<-c('Q(m)', 'P')
out

1_1.5.4.png

                1            2            3            4            5
Q(m) 3.420025e+01 3.976335e+01 5.039731e+01 5.180377e+01 5.190793e+01
P    4.972263e-09 2.320056e-09 6.574763e-11 1.516132e-10 5.634492e-10
                6            7            8            9           10
Q(m) 5.445974e+01 5.446017e+01 5.745610e+01 5.793698e+01 5.884316e+01
P    5.958688e-10 1.907042e-09 1.466964e-09 3.342017e-09 5.995413e-09

#(5)

cf(diff(log(data$topix)), xlim=c(1,20), ylim=c(-0.5,0.5))
box.t<-apply(as.matrix(lag),1,function(x) {tmp=Box.test(diff(log(data$topix)),type="Ljung", lag=x); return(c(tmp$statistic, tmp$p.value))})
out<-data.frame(matrix(box.t[1,], nrow=1))
out<-rbind(out, box.t[2,])
colnames(out)<-lag
rownames(out)<-c('Q(m)', 'P')
out

1_1.5.5.png

                1            2            3            4            5
Q(m) 3.467592e+01 3.638552e+01 3.684399e+01 3.855135e+01 3.891405e+01
P    3.894192e-09 1.255984e-08 4.964713e-08 8.622952e-08 2.471338e-07
                6            7            8            9           10
Q(m) 3.987178e+01 3.996513e+01 4.019884e+01 4.442465e+01 4.596921e+01
P    4.827198e-07 1.278282e-06 2.941722e-06 1.178549e-06 1.452777e-06

⇒ 次は 『経済・ファイナンスデータの計量時系列分析』章末問題をRで解く-第2章ARMA過程-

11
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?