urcaパッケージを使用した定常性検定

urcaパッケージについては、マニュアル参照
ざっとコードを追って、補足は追々後日しておく。

> getSymbols('YJ2489.T', src='yahooj') # アドウェイズの株価取得
[1] "YJ2489.T"

> head(YJ2489.T) # 株価確認
           YJ2489.T.Open YJ2489.T.High YJ2489.T.Low YJ2489.T.Close YJ2489.T.Volume YJ2489.T.Adjusted
2007-01-04           422           424          414            416          135500               416
2007-01-05           412           416          390            394          646000               394
2007-01-09           394           394          370            376          657000               376
2007-01-10           374           390          370            372          773000               372
2007-01-11           372           372          348            352          620000               352
2007-01-12           354           366          346            358          480000               358
> 

> YJ2489.close<-YJ2489.T$YJ2489.T.Adjusted #終値だけ選択
> head(YJ2489.close)
           YJ2489.T.Adjusted
2007-01-04               416
2007-01-05               394
2007-01-09               376
2007-01-10               372
2007-01-11               352
2007-01-12               358

次に、urcaパッケージをインストールしてKPSS検定を行う。
KPSSの説明はドキュメントから引用すると次のようになる。

Performs the KPSS unit root test, where the Null hypothesis is stationarity. The test types specify
as deterministic component either a constant "mu" or a constant with linear trend "tau".

Rプログラムは次のようになる。

> install.packages("urca") #パッケージインストール
> require(urca)             #パッケージ読み込み
> testResult <- ur.kpss(as.numeric(YJ2489.close)) #株価のKPSS検定
> summary(testResult) #検定結果参照

####################### 
# KPSS Unit Root Test # 
####################### 

Test is of type: mu with 8 lags. 

Value of test-statistic is: 12.6221 

Critical value for a significance level of: 
                10pct  5pct 2.5pct  1pct
critical values 0.347 0.463  0.574 0.739

検定結果を個別に見るには下記のようにする。

> testResult@teststat
[1] 12.62212
> testResult@cval
                10pct  5pct 2.5pct  1pct
critical values 0.347 0.463  0.574 0.739

一方、tseriesのadf.testを実施すると次のようになる。

> library(tseries)
> adf.test(YJ2489.close)

        Augmented Dickey-Fuller Test

data:  YJ2489.close
Dickey-Fuller = -2.3618, Lag order = 13, p-value = 0.4251
alternative hypothesis: stationary

リターンについては下記。

> YJ2489.close.returns <- diff(log(YJ2489.close))
> test_returns <- ur.kpss(as.numeric(YJ2489.close.returns))
> test_returns@teststat
[1] 0.1838311
> test_returns@cval
                10pct  5pct 2.5pct  1pct
critical values 0.347 0.463  0.574 0.739