アットウィキロゴ

ドル-円(日次)

米ドル/日本円の為替データ


分析1(途中)


概要

  • データの期間:2008年11月26日から2009年11月26日まで
  • 用いたデータ・日時データの終値
    • =一番下にある"usdjpy1126-20082009.csv"というファイル

1. Rによる時系列モデルの推測・作成・検定

(1)ACF/PACFの確認


#読み込みからACF
/PACFの確認
DY1126 <- read.table("usdjpy1126-20082009.csv",sep=",")#ファイルの読み込み
#念のためデータの確認
DY1126
summary(DY1126)
as.ts(DY1126)#結果(Start = 1 End = 244 Frequency = 1)

#グラフの作成
ts.plot(DY1126,xlab='26/11/2008-6/11/2009',ylab='USD/JPY',main="daily USD/JPY,2008-2009")
par(mfrow=c(1,2))
acf(DY1126 ,main="米ドル/日本円")
pacf(DY1126 ,main="米ドル/日本円")

  • 出てきた画像(大きさ未調整)
    • 時系列データ
    • ACF,PACFデータ(コレログラム)

(2)モデルの推計


#ARモデルの検証 #引き続きRのコード
#コレログラムの形状よりAR
モデルに近いと予測される。
#よって以下の操作を行う

(DY1126.ar <-ar(DY1126)) #ユールウォーカー法によるモデル推定
summary(DY1126.ar)

  • (DY1126.ar <-ar(DY1126))の結果(係数・残差の分散)


Call:
ar(x = DY1126)

Coefficients:
    1  
0.9593

Order selected 1 sigma^2 estimated as 0.9219

  • summary(DY1126.ar)の結果


           Length Class  Mode     
order 1 -none- numeric
ar 1 -none- numeric
var.pred 1 -none- numeric
x.mean 1 -none- numeric
aic 24 -none- numeric
n.used 1 -none- numeric
order.max 1 -none- numeric
partialacf 23 -none- numeric
resid 244 -none- numeric
method 1 -none- character
series 1 -none- character
frequency 1 -none- numeric
call 2 -none- call
asy.var.coef 1 -none- numeric

(3)モデルの診断


#以上の結果よりAR
モデルに近いと推測される。
#また係数の結果より下記の式
(1)を導出する。
# y(t)=  0.9593084*y(t-1)+ e(t)
# ※(t)は変数の時期を示す。
#以下の残差の検定を行う

Box.test(DY1126.ar$res, type="Ljung")#H0:(帰無仮説)データは無作為である。
#(対立仮説)テータは無作為でない
Box.test(DY1126.ar$res, type="Pierce")
#あるいはBox
.test(DY1126, lag = 1, type = c("Box-Pierce", "Ljung-Box")

  • Box.test(DY1126.ar$res, type="Ljung")の結果


       Box-Ljung test

data: DY1126.ar$res
X-squared = 0.0769, df = 1, p-value = 0.7815

  • Box-Pierce testの結果


       Box-Pierce test

data: DY1126
X-squared = 224.5465, df = 1, p-value < 2.2e-16


2. Rによる単位根



#単位根検定
library(tseries)
ts1126 <- ts(DY1126)
PP.test(ts1126, lshort = TRUE)#Phillips-Perron検定
adf.test(ts1126)
adf.test(diff(ts1126))$p.value #1階の差分をとった場合

  • Unit Root Testの結果


Phillips-Perron Unit Root Test

data: ts1126
Dickey-Fuller = -2.3446, Truncation lag parameter = 4, p-value = 0.4309

  • ADFの結果


       Augmented Dickey-Fuller Test

data: ts1126
Dickey-Fuller = -1.9255, Lag order = 6, p-value = 0.6072
alternative hypothesis: stationary

  • ADFの結果(ラグあり)


[1] 0.01
警告メッセージ: 
In adf.test(diff(ts1126)) : p-value smaller than printed p-value


3.

  • arimaモデル
  • 係数を求めるプログラム 参考:ttp://mjin.doshisha.ac.jp/R/34/34.html
    • (3,1,1)までで確認


#数字を大きくすると収束しないケースもあり
…。
#スペースが入ると文字化けするので左寄せで表記

data<-DY1126; T<-0
for(p in 1:3)
for(d in 0:1)
for(q in 0:1){
fit<-arima(data,order=c(p,d,q))
T<-T+1
if(T==1){
minaic<-fit$aic
orderP<-p; orderD<-d;orderQ<-q;
}else{
if (fit$aic<-minaic){
orderP<-p; orderD<-d;orderQ<-q;
}
}
}
#計算後
…、
cat("結果: p=",orderP,"d=",orderD,"q=",orderQ,"AIC=",minaic,"\n");

    • 結果


結果: p= 3 d= 1 q= 1 AIC= 612.5965

    • (4,1,1)までで確認


#スペースが入ると文字化けするので左寄せで表記

data<-DY1126; T<-0
for(p in 0:4)
for(d in 0:1)
for(q in 0:1){
fit<-arima(data,order=c(p,d,q))
T<-T+1
if(T==1){
minaic<-fit$aic
orderP<-p; orderD<-d;orderQ<-q;
}else{
if (fit$aic<-minaic){
minaic<- fit$aic;
orderP<-p; orderD<-d;orderQ<-q;
}
}
}
#計算後
…、
cat("結果: p=",orderP,"d=",orderD,"q=",orderQ,"AIC=",minaic,"\n");

    • (4,1,1)の結果


結果: p= 4 d= 1 q= 1 AIC= 1291.704

    • ちなみに(5,1,1)だと…。


結果: p= 5 d= 1 q= 1 AIC= 1291.704


分析2(途中)

  • 2008年6月23日から2009年11月26日まで
  • 終値
  • 使用コード


#以下Rのコード
DY <- read.table("USDJPNowarine.csv",sep=",")#ファイルの読み込み
ts.plot(DY)
#まずは自己相関
  • 偏自己相関を調べる。
par(mfrow=c(1,2))
acf(DY,main="米ドル/日本円")
pacf(DY,main="米ドル/日本円")
#下に出てきたファイル画像 #大きさ未調整
。ブラウザによってはでかすぎw


#引き続きRのコード
#コレログラムの形状よりAR
モデルに近いと予測される。
#-こちらも参照
(DY.ar <-ar(DY)) #「ユールウォーカー法によるモデル推定」
summary(DY.ar) #「項目リスト」
#arモデルに関しては #以下結果
「ユールウォーカー法によるモデル推定」

Call:
ar(x = DY)

Coefficients:
    1       2  
0.8992 0.0814

Order selected 2 sigma^2 estimated as 1.636

「項目リスト」
            Length Class  Mode     
order 1 -none- numeric
ar 2 -none- numeric
var.pred 1 -none- numeric
x.mean 1 -none- numeric
aic 26 -none- numeric
n.used 1 -none- numeric
order.max 1 -none- numeric
partialacf 25 -none- numeric
resid 350 -none- numeric
method 1 -none- character
series 1 -none- character
frequency 1 -none- numeric
call 2 -none- call
asy.var.coef 4 -none- numeric

#以下続く
最終更新:2010年07月10日 01:24