Analysis

日経平均株価と東京市場ドル円レート(Source:日本銀行,日本経済新聞社)

分析設計

[1] "USDJPY"
         Date   Open   High    Low  Close Center  Index CloseToOpen HighToLow     MA25 DeviationRate Close:Diff(lag=1) Close:Ratio(lag=1)
56 2019-10-21 108.41 108.58 108.29 108.57 108.49 104.92       0.148     0.268 107.8452          0.67             -0.08             -0.074
57 2019-10-23 108.49 108.50 108.25 108.38 108.38 104.80      -0.101     0.231 107.8640          0.48             -0.19             -0.175
58 2019-10-24 108.64 108.75 108.57 108.70 108.61 105.02       0.055     0.166 107.8936          0.75              0.32              0.295
59 2019-10-25 108.61 108.71 108.60 108.62 108.70 104.93       0.009     0.101 107.9132          0.65             -0.08             -0.074
60 2019-10-28 108.75 108.79 108.68 108.74 108.76 104.60      -0.009     0.101 107.9348          0.75              0.12              0.110
61 2019-10-29 108.98 109.07 108.85 108.86 108.97 104.63      -0.110     0.202 107.9672          0.83              0.12              0.110
62 2019-10-30 108.88 108.88 108.82 108.86 108.84 104.53      -0.018     0.055 108.0044          0.79              0.00              0.000
63 2019-10-31 108.80 108.88 108.59 108.61 108.83 105.29      -0.175     0.267 108.0448          0.52             -0.25             -0.230
64 2019-11-01 108.01 108.06 107.89 107.96 107.98 104.99      -0.046     0.158 108.0716         -0.10             -0.65             -0.598
65 2019-11-05 108.71 108.84 108.54 108.79 108.77 104.01       0.074     0.276 108.1156          0.62              0.83              0.769
66 2019-11-06 109.15 109.18 108.92 108.98 109.06 104.24      -0.156     0.239 108.1608          0.76              0.19              0.175
67 2019-11-07 108.92 109.12 108.65 108.96 108.70 103.83       0.037     0.433 108.2048          0.70             -0.02             -0.018
68 2019-11-08 109.28 109.40 109.15 109.29 109.35 104.06       0.009     0.229 108.2424          0.97              0.33              0.303
69 2019-11-11 109.20 109.25 108.92 108.96 109.03 104.35      -0.220     0.303 108.2936          0.62             -0.33             -0.302
70 2019-11-12 109.05 109.29 108.99 109.24 109.14     NA       0.174     0.275 108.3740          0.80              0.28              0.257
[1] "NIKKEI"
         Date     Open     High      Low    Close CloseToOpen HighToLow     MA25 DeviationRate Close:Diff(lag=1) Close:Ratio(lag=1)
56 2019-10-21 22541.22 22581.28 22515.73 22548.90       0.034     0.291 21919.80          2.87             56.22              0.250
57 2019-10-23 22619.77 22648.81 22457.89 22625.38       0.025     0.850 21954.43          3.06             76.48              0.339
58 2019-10-24 22725.44 22780.99 22704.33 22750.60       0.111     0.338 21984.93          3.48            125.22              0.553
59 2019-10-25 22753.24 22819.92 22715.13 22799.81       0.205     0.461 22016.87          3.56             49.21              0.216
60 2019-10-28 22854.44 22896.22 22830.57 22867.27       0.056     0.288 22053.13          3.69             67.46              0.296
61 2019-10-29 22950.79 23008.43 22935.35 22974.13       0.102     0.319 22090.31          4.00            106.86              0.467
62 2019-10-30 22953.17 22961.23 22827.93 22843.12      -0.479     0.584 22120.88          3.26           -131.01             -0.570
63 2019-10-31 22910.10 22988.80 22875.50 22927.04       0.074     0.495 22154.00          3.49             83.92              0.367
64 2019-11-01 22730.49 22852.72 22705.60 22850.77       0.529     0.648 22187.23          2.99            -76.27             -0.333
65 2019-11-05 23118.79 23328.52 23090.94 23251.99       0.576     1.029 22235.38          4.57            401.22              1.756
66 2019-11-06 23343.51 23352.56 23246.57 23303.82      -0.170     0.456 22292.38          4.54             51.83              0.223
67 2019-11-07 23283.14 23336.00 23253.32 23330.32       0.203     0.356 22355.35          4.36             26.50              0.114
68 2019-11-08 23550.04 23591.09 23313.41 23391.87      -0.672     1.191 22415.62          4.36             61.55              0.264
69 2019-11-11 23422.13 23471.82 23323.02 23331.84      -0.385     0.638 22477.75          3.80            -60.03             -0.257
70 2019-11-12 23336.37 23545.70 23312.25 23520.01       0.787     1.001 22564.88          4.23            188.17              0.806

単位根検定・共和分検定

  • CADFtest {CADFtest}
  • ca.po {urca}
$USDJPY_CloseToOpen

    ADF test

data:  x
ADF(0) = -8.8814, p-value = 0.000000003056
alternative hypothesis: true delta is less than 0
sample estimates:
  delta 
-1.2002 


$NIKKEI_CloseToOpen

    ADF test

data:  x
ADF(0) = -7.7126, p-value = 0.00000009768
alternative hypothesis: true delta is less than 0
sample estimates:
    delta 
-1.081941 

######################################## 
# Phillips and Ouliaris Unit Root Test # 
######################################## 

Test of type Pu 
detrending of series none 


Call:
lm(formula = z[, 1] ~ z[, -1] - 1)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.34967 -0.10363  0.00013  0.09728  0.88498 

Coefficients:
        Estimate Std. Error t value Pr(>|t|)  
z[, -1]  0.11350    0.05861   1.937   0.0576 .
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.1753 on 59 degrees of freedom
Multiple R-squared:  0.05976,   Adjusted R-squared:  0.04383 
F-statistic:  3.75 on 1 and 59 DF,  p-value: 0.0576


Value of test-statistic is: 56.669 

Critical values of Pu are:
                  10pct    5pct    1pct
critical values 20.3933 25.9711 38.3413

最小二乗法

  • lm {stats}
  • dwtest {lmtest}
  • ks.test {stats}
  • confint {stats}
  • Box.test {stats}
  • 切片項\(\neq0\)
MODEL INFO:
Observations: 60
Dependent Variable: USDJPY_CloseToOpen
Type: OLS linear regression 

MODEL FIT:
F(1,58) = 2.89, p = 0.09
R2 = 0.05
Adj. R2 = 0.03 

Standard errors: OLS
---------------------------------------------------------------
                           Est.    2.5%   97.5%   t val.      p
------------------------ ------ ------- ------- -------- ------
(Intercept)                0.01   -0.04    0.06     0.40   0.69
NIKKEI_CloseToOpen         0.11   -0.02    0.23     1.70   0.09
---------------------------------------------------------------

    Durbin-Watson test

data:  OLS_Model
DW = 2.4001, p-value = 0.9428
alternative hypothesis: true autocorrelation is greater than 0

    One-sample Kolmogorov-Smirnov test

data:  ResidualsOLS
D = 0.11662, p-value = 0.3601
alternative hypothesis: two-sided
                         2.5 %    97.5 %
(Intercept)        -0.03858099 0.0576007
NIKKEI_CloseToOpen -0.01884990 0.2302638

    Box-Ljung test

data:  ResidualsOLS
X-squared = 6.4738, df = 10, p-value = 0.774
  • 切片項\(=0\)
MODEL INFO:
Observations: 60
Dependent Variable: USDJPY_CloseToOpen
Type: OLS linear regression 

MODEL FIT:
F(1,59) = 3.75, p = 0.06
R2 = 0.06
Adj. R2 = 0.04 

Standard errors: OLS
---------------------------------------------------------------
                           Est.    2.5%   97.5%   t val.      p
------------------------ ------ ------- ------- -------- ------
NIKKEI_CloseToOpen         0.11   -0.00    0.23     1.94   0.06
---------------------------------------------------------------

    Durbin-Watson test

data:  OLS_Model_no_intercept
DW = 2.4001, p-value = 0.9555
alternative hypothesis: true autocorrelation is greater than 0

    One-sample Kolmogorov-Smirnov test

data:  ResidualsOLS_no_intercept
D = 0.10604, p-value = 0.4775
alternative hypothesis: two-sided
                          2.5 %    97.5 %
NIKKEI_CloseToOpen -0.003778254 0.2307707

    Box-Ljung test

data:  ResidualsOLS_no_intercept
X-squared = 6.5177, df = 10, p-value = 0.7701

一般化最小二乗法

  • 切片項\(\neq0\)
Generalized least squares fit by REML
  Model: USDJPY_CloseToOpen ~ NIKKEI_CloseToOpen 
  Data: USDJPY_NIKKEI 
        AIC       BIC   logLik
  -24.64596 -16.40419 16.32298

Correlation Structure: ARMA(0,1)
 Formula: ~1 
 Parameter estimate(s):
    Theta1 
-0.1936757 

Coefficients:
                        Value  Std.Error   t-value p-value
(Intercept)        0.00854908 0.01942382 0.4401339  0.6615
NIKKEI_CloseToOpen 0.11512555 0.06002453 1.9179749  0.0600

 Correlation: 
                   (Intr)
NIKKEI_CloseToOpen -0.373

Standardized residuals:
        Min          Q1         Med          Q3         Max 
-2.03887548 -0.63716408 -0.05367713  0.50168842  4.99335286 

Residual standard error: 0.1756226 
Degrees of freedom: 60 total; 58 residual

    One-sample Kolmogorov-Smirnov test

data:  ResidualsGLS
D = 0.12027, p-value = 0.3242
alternative hypothesis: two-sided
                          2.5 %     97.5 %
(Intercept)        -0.029520901 0.04661906
NIKKEI_CloseToOpen -0.002520375 0.23277147

    Box-Ljung test

data:  ResidualsGLS
X-squared = 6.528, df = 10, p-value = 0.7691
  • 切片項\(=0\)
Generalized least squares fit by REML
  Model: USDJPY_CloseToOpen ~ NIKKEI_CloseToOpen - 1 
  Data: USDJPY_NIKKEI 
        AIC       BIC   logLik
  -32.51563 -26.28302 19.25781

Correlation Structure: ARMA(0,1)
 Formula: ~1 
 Parameter estimate(s):
    Theta1 
-0.2075424 

Coefficients:
                       Value Std.Error  t-value p-value
NIKKEI_CloseToOpen 0.1255419 0.0550368 2.281054  0.0262

Standardized residuals:
        Min          Q1         Med          Q3         Max 
-1.99364254 -0.60342188 -0.03806715  0.54805576  5.08338114 

Residual standard error: 0.1748436 
Degrees of freedom: 60 total; 59 residual

    One-sample Kolmogorov-Smirnov test

data:  ResidualsGLS_no_intercept
D = 0.10441, p-value = 0.4972
alternative hypothesis: two-sided
                        2.5 %   97.5 %
NIKKEI_CloseToOpen 0.01767176 0.233412

    Box-Ljung test

data:  ResidualsGLS_no_intercept
X-squared = 6.6045, df = 10, p-value = 0.7622

散布図・QQプロット・残差の時系列推移

  • (注意)線形回帰の傾き(\(a\))、切片(\(b\))それぞれの検定統計量、p値に関わらず\(y=ax+b\)とした回帰直線やその残差を散布図、QQプロット等にプロットしています。
  • 散布図とQQプロット

  • 残差の自己相関(ACF)

  • 残差の自己相関(PACF)

ダウ平均株価と日経平均株価(Source:Yahoo Finance,FRED,日本経済新聞社)

時系列チャート

  • Source:
  • (注意) 欠損値(休場日)は原系列にスプライン補間を掛けた上で前日比を算出している。
  • 対象期間:2019-07-10~2019-11-12
  • サンプルサイズ:n=90

単位根検定・共和分検定

  • CADFtest {CADFtest}
  • ca.po {urca}
単位根検定
$DOW30

    ADF test

data:  x
ADF(0) = -2.2161, p-value = 0.4746
alternative hypothesis: true delta is less than 0
sample estimates:
     delta 
-0.1034051 


$NIKKEI225

    ADF test

data:  x
ADF(0) = -1.6868, p-value = 0.7489
alternative hypothesis: true delta is less than 0
sample estimates:
   delta 
-0.05076 


$DOW30_Change

    ADF test

data:  x
ADF(0) = -10.673, p-value = 0.0000000000006135
alternative hypothesis: true delta is less than 0
sample estimates:
    delta 
-1.142745 


$NIKKEI225_Change

    ADF test

data:  x
ADF(0) = -9.1791, p-value = 0.00000000006072
alternative hypothesis: true delta is less than 0
sample estimates:
    delta 
-1.001935 
共和分検定
[1] "DOW30 × NIKKEI225"

######################################## 
# Phillips and Ouliaris Unit Root Test # 
######################################## 

Test of type Pu 
detrending of series none 


Call:
lm(formula = z[, 1] ~ z[, -1] - 1)

Residuals:
    Min      1Q  Median      3Q     Max 
-1329.2  -452.1   127.6   660.0  1254.6 

Coefficients:
        Estimate Std. Error t value            Pr(>|t|)    
z[, -1] 1.233871   0.003503   352.2 <0.0000000000000002 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 720.5 on 89 degrees of freedom
Multiple R-squared:  0.9993,    Adjusted R-squared:  0.9993 
F-statistic: 1.24e+05 on 1 and 89 DF,  p-value: < 0.00000000000000022


Value of test-statistic is: 4.9671 

Critical values of Pu are:
                  10pct    5pct    1pct
critical values 20.3933 25.9711 38.3413

相互相関関数

  • ggCcf {forecast}

ベクトル自己回帰モデル

  • VARselect {vars}
  • VAR {vars}

VAR Estimation Results:
========================= 
Endogenous variables: DOW30, NIKKEI225 
Deterministic variables: const 
Sample size: 89 
Log Likelihood: -1182.561 
Roots of the characteristic polynomial:
1.006 0.7532
Call:
VAR(y = obj, p = selected_lag, type = "const")


Estimation results for equation DOW30: 
====================================== 
DOW30 = DOW30.l1 + NIKKEI225.l1 + const 

               Estimate Std. Error t value            Pr(>|t|)    
DOW30.l1        0.81397    0.07072  11.510 <0.0000000000000002 ***
NIKKEI225.l1    0.09041    0.04472   2.022              0.0463 *  
const        3027.78392 1295.39907   2.337              0.0217 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 222.8 on 86 degrees of freedom
Multiple R-Squared: 0.8339, Adjusted R-squared:  0.83 
F-statistic: 215.9 on 2 and 86 DF,  p-value: < 0.00000000000000022 


Estimation results for equation NIKKEI225: 
========================================== 
NIKKEI225 = DOW30.l1 + NIKKEI225.l1 + const 

                Estimate  Std. Error t value            Pr(>|t|)    
DOW30.l1         0.12905     0.05162   2.500              0.0143 *  
NIKKEI225.l1     0.94502     0.03264  28.952 <0.0000000000000002 ***
const        -2239.19240   945.52931  -2.368              0.0201 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 162.6 on 86 degrees of freedom
Multiple R-Squared: 0.9653, Adjusted R-squared: 0.9645 
F-statistic:  1196 on 2 and 86 DF,  p-value: < 0.00000000000000022 



Covariance matrix of residuals:
          DOW30 NIKKEI225
DOW30     49650      6086
NIKKEI225  6086     26452

Correlation matrix of residuals:
           DOW30 NIKKEI225
DOW30     1.0000    0.1679
NIKKEI225 0.1679    1.0000

VAR Estimation Results:
========================= 
Endogenous variables: DOW30_Change, NIKKEI225_Change 
Deterministic variables: const 
Sample size: 89 
Log Likelihood: -195.162 
Roots of the characteristic polynomial:
0.2833 0.1576
Call:
VAR(y = obj, p = selected_lag, type = "const")


Estimation results for equation DOW30_Change: 
============================================= 
DOW30_Change = DOW30_Change.l1 + NIKKEI225_Change.l1 + const 

                    Estimate Std. Error t value Pr(>|t|)
DOW30_Change.l1     -0.11766    0.10714  -1.098    0.275
NIKKEI225_Change.l1  0.08530    0.11956   0.713    0.478
const                0.03504    0.09284   0.377    0.707


Residual standard error: 0.8691 on 86 degrees of freedom
Multiple R-Squared: 0.01827,    Adjusted R-squared: -0.00456 
F-statistic: 0.8002 on 2 and 86 DF,  p-value: 0.4525 


Estimation results for equation NIKKEI225_Change: 
================================================= 
NIKKEI225_Change = DOW30_Change.l1 + NIKKEI225_Change.l1 + const 

                     Estimate Std. Error t value      Pr(>|t|)    
DOW30_Change.l1      0.534594   0.078339   6.824 0.00000000118 ***
NIKKEI225_Change.l1 -0.008002   0.087424  -0.092         0.927    
const                0.080920   0.067886   1.192         0.237    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 0.6355 on 86 degrees of freedom
Multiple R-Squared: 0.3523, Adjusted R-squared: 0.3372 
F-statistic: 23.39 on 2 and 86 DF,  p-value: 0.000000007756 



Covariance matrix of residuals:
                 DOW30_Change NIKKEI225_Change
DOW30_Change           0.7554           0.1016
NIKKEI225_Change       0.1016           0.4039

Correlation matrix of residuals:
                 DOW30_Change NIKKEI225_Change
DOW30_Change            1.000            0.184
NIKKEI225_Change        0.184            1.000

グレンジャー因果

  • causality {vars}
Dow → Nikkei

    Granger causality H0: DOW30_Change do not Granger-cause NIKKEI225_Change

data:  VAR object var_result
F-Test = 46.568, df1 = 1, df2 = 172, p-value = 0.000000000145
Nikkei → Dow

    Granger causality H0: NIKKEI225_Change do not Granger-cause DOW30_Change

data:  VAR object var_result
F-Test = 0.50897, df1 = 1, df2 = 172, p-value = 0.4766

インパルス応答

  • irf {vars}

空売り比率と日経平均株価(Source:日本取引所グループ、日本経済新聞社)

業種別空売り集計

  • 2019年11月12日
  • 「空売り合計:比率」は100から「実注文:比率」を減じた数値としています。

空売り合計:比率:2019年11月12日
N 業種名 空売り合計:比率
1 水産・農林業 31.6
2 鉱業 29.8
3 建設業 38.1
4 食料品 43.9
5 繊維製品 37.3
6 パルプ・紙 45
7 化学 41.8
8 医薬品 39.2
9 石油・石炭製品 40.1
10 ゴム製品 45.7
11 ガラス・土石製品 39.3
12 鉄鋼 44.1
13 非鉄金属 30.2
14 金属製品 47.2
15 機械 44.4
16 電気機器 40.4
17 輸送用機器 35.3
18 精密機器 39.5
19 その他製品 41.9
20 電気・ガス業 46.1
21 陸運業 36.2
22 海運業 32.6
23 空運業 32
24 倉庫・運輸関連業 35.2
25 情報・通信業 39.4
26 卸売業 35
27 小売業 38.8
28 銀行業 39.7
29 証券、商品先物取引業 38.9
30 保険業 34.5
31 その他金融業 38.5
32 不動産業 36.7
33 サービス業 38.6
34 その他(33業種外) 43.7

空売り比率の時系列推移

  • 2019-07-01 ~ 2019-11-12

時系列推移
Date 11-12 11-11 11-08 11-07 11-06 11-05 11-01 10-31
実注文:比率 60.2 58.6 59.6 59.1 59.9 62.8 60.7 62
空売り(価格規制あり):比率 33.9 36.8 35.4 35.2 34.3 32.1 34.1 33.2
空売り(価格規制なし):比率 5.9 4.5 5 5.7 5.8 5.1 5.2 4.7
空売り合計:比率 39.8 41.4 40.4 40.9 40.1 37.2 39.3 38

日経平均株価と空売り比率

時系列推移

  • 対象期間:2019-07-01 ~ 2019-11-12

単位根検定/共和分検定

  • CADFtest {CADFtest}
  • ca.po {urca}
  • 各系列の“_change“は前営業日との差。
  • 対象期間: 2019-07-01 ~ 2019-11-12,90days
### 単位根検定 ###

$NIKKEI225.close

    ADF test

data:  x
ADF(0) = -1.2007, p-value = 0.9039
alternative hypothesis: true delta is less than 0
sample estimates:
      delta 
-0.03512931 


$ShortSalerRatio

    ADF test

data:  x
ADF(1) = -4.7994, p-value = 0.0009933
alternative hypothesis: true delta is less than 0
sample estimates:
     delta 
-0.6567251 


$NIKKEI225.close_change

    ADF test

data:  x
ADF(1) = -5.5484, p-value = 0.00006898
alternative hypothesis: true delta is less than 0
sample estimates:
     delta 
-0.8621279 


$ShortSalerRatio_change

    ADF test

data:  x
ADF(1) = -9.7729, p-value = 0.000000000008436
alternative hypothesis: true delta is less than 0
sample estimates:
    delta 
-1.832976 
### 共和分検定 ###


######################################## 
# Phillips and Ouliaris Unit Root Test # 
######################################## 

Test of type Pu 
detrending of series none 


Call:
lm(formula = z[, 1] ~ z[, -1] - 1)

Residuals:
    Min      1Q  Median      3Q     Max 
-4304.0 -1113.6   -42.9  1619.7  5176.2 

Coefficients:
        Estimate Std. Error t value            Pr(>|t|)    
z[, -1]  485.909      5.023   96.73 <0.0000000000000002 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 2114 on 89 degrees of freedom
Multiple R-squared:  0.9906,    Adjusted R-squared:  0.9905 
F-statistic:  9357 on 1 and 89 DF,  p-value: < 0.00000000000000022


Value of test-statistic is: 0.502 

Critical values of Pu are:
                  10pct    5pct    1pct
critical values 20.3933 25.9711 38.3413

最小二乗法

  • lm {stats}
  • dwtest {lmtest}
  • ks.test {stats}
  • confint {stats}
  • Box.test {stats}
  • Ljung-Box 検定のラグは15としている。
  • 対象期間: 2019-07-01 ~ 2019-11-12,90days
  • 切片項\(\neq0\)

Call:
lm(formula = NIKKEI225.close_change ~ ShortSalerRatio_change, 
    data = datadf)

Residuals:
    Min      1Q  Median      3Q     Max 
-365.21  -64.13   10.40   88.07  312.19 

Coefficients:
                       Estimate Std. Error t value       Pr(>|t|)    
(Intercept)              21.542     15.267   1.411          0.162    
ShortSalerRatio_change  -32.139      4.546  -7.069 0.000000000353 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 144.8 on 88 degrees of freedom
Multiple R-squared:  0.3622,    Adjusted R-squared:  0.3549 
F-statistic: 49.97 on 1 and 88 DF,  p-value: 0.0000000003527

    Durbin-Watson test

data:  OLS_Model
DW = 1.5236, p-value = 0.01242
alternative hypothesis: true autocorrelation is greater than 0

    One-sample Kolmogorov-Smirnov test

data:  ResidualsOLS
D = 0.081884, p-value = 0.5545
alternative hypothesis: two-sided
                            2.5 %    97.5 %
(Intercept)             -8.798715  51.88248
ShortSalerRatio_change -41.174065 -23.10392

    Box-Ljung test

data:  ResidualsOLS
X-squared = 18.426, df = 15, p-value = 0.241
  • 切片項\(=0\)

Call:
lm(formula = NIKKEI225.close_change ~ ShortSalerRatio_change - 
    1, data = datadf)

Residuals:
    Min      1Q  Median      3Q     Max 
-343.08  -42.45   31.59  109.72  333.30 

Coefficients:
                       Estimate Std. Error t value       Pr(>|t|)    
ShortSalerRatio_change  -32.341      4.569  -7.078 0.000000000324 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 145.6 on 89 degrees of freedom
Multiple R-squared:  0.3601,    Adjusted R-squared:  0.353 
F-statistic: 50.09 on 1 and 89 DF,  p-value: 0.0000000003239

    Durbin-Watson test

data:  OLS_Model_no_intercept
DW = 1.4915, p-value = 0.01084
alternative hypothesis: true autocorrelation is greater than 0

    One-sample Kolmogorov-Smirnov test

data:  ResidualsOLS_no_intercept
D = 0.13936, p-value = 0.05487
alternative hypothesis: two-sided
                           2.5 %    97.5 %
ShortSalerRatio_change -41.41995 -23.26132

    Box-Ljung test

data:  ResidualsOLS_no_intercept
X-squared = 18.361, df = 15, p-value = 0.2442

一般化最小二乗法

  • 切片項\(\neq0\)
Generalized least squares fit by REML
  Model: NIKKEI225.close_change ~ ShortSalerRatio_change 
  Data: datadf 
       AIC      BIC    logLik
  1139.807 1149.717 -565.9037

Correlation Structure: AR(1)
 Formula: ~1 
 Parameter estimate(s):
      Phi 
0.2394295 

Coefficients:
                           Value Std.Error   t-value p-value
(Intercept)             22.76542 19.468581  1.169342  0.2454
ShortSalerRatio_change -31.05767  3.882167 -8.000087  0.0000

 Correlation: 
                       (Intr)
ShortSalerRatio_change 0.027 

Standardized residuals:
        Min          Q1         Med          Q3         Max 
-2.54639845 -0.45533191  0.06583147  0.59407462  2.15824107 

Residual standard error: 145.1337 
Degrees of freedom: 90 total; 88 residual

    One-sample Kolmogorov-Smirnov test

data:  ResidualsGLS
D = 0.076677, p-value = 0.637
alternative hypothesis: two-sided
                           2.5 %    97.5 %
(Intercept)            -15.39229  60.92314
ShortSalerRatio_change -38.66658 -23.44876

    Box-Ljung test

data:  ResidualsGLS
X-squared = 18.742, df = 15, p-value = 0.2257
  • 切片項\(=0\)
Generalized least squares fit by REML
  Model: NIKKEI225.close_change ~ ShortSalerRatio_change - 1 
  Data: datadf 
       AIC      BIC    logLik
  1146.949 1154.415 -570.4747

Correlation Structure: AR(1)
 Formula: ~1 
 Parameter estimate(s):
      Phi 
0.2402981 

Coefficients:
                           Value Std.Error   t-value p-value
ShortSalerRatio_change -31.17751  3.886788 -8.021408       0

Standardized residuals:
       Min         Q1        Med         Q3        Max 
-2.3817276 -0.2972401  0.2229670  0.7497023  2.3081148 

Residual standard error: 145.4638 
Degrees of freedom: 90 total; 89 residual

    One-sample Kolmogorov-Smirnov test

data:  ResidualsGLS_no_intercept
D = 0.13565, p-value = 0.06619
alternative hypothesis: two-sided
                           2.5 %    97.5 %
ShortSalerRatio_change -38.79547 -23.55955

    Box-Ljung test

data:  ResidualsGLS_no_intercept
X-squared = 18.709, df = 15, p-value = 0.2272

残差

  • 時系列推移
  • 自己相関
  • 時系列推移

  • 自己相関

ドル円レートと日経平均株価:ベイズ推定:線形回帰モデル

\[\rm{NIKKEI}\sim\rm{Normal}(\beta_0 + \beta_1 \cdot \rm{USDJPY},\sigma)\]

# 数値はいずれも前月比(%)
head(df)
         Date NIKKEI USDJPY
12 2016-12-01   7.78   7.12
13 2017-01-01   0.67  -1.05
14 2017-02-01  -0.03  -1.45
15 2017-03-01   0.79  -0.05
16 2017-04-01  -3.12  -2.59
17 2017-05-01   5.29   1.94
tail(df)
         Date NIKKEI USDJPY
42 2019-06-01  -0.75  -1.58
43 2019-07-01   2.53   0.15
44 2019-08-01  -4.46  -1.81
45 2019-09-01   4.63   1.06
46 2019-10-01   2.84   0.65
47 2019-11-01   4.89   0.73
apply(df[, -1], 2, adf.test)
$NIKKEI

    Augmented Dickey-Fuller Test

data:  newX[, i]
Dickey-Fuller = -3.7917, Lag order = 3, p-value = 0.03245
alternative hypothesis: stationary


$USDJPY

    Augmented Dickey-Fuller Test

data:  newX[, i]
Dickey-Fuller = -4.7309, Lag order = 3, p-value = 0.01
alternative hypothesis: stationary
# 最尤推定
summary(lm(NIKKEI ~ USDJPY), confint = T, ci.width = 0.95)

Call:
lm(formula = NIKKEI ~ USDJPY)

Residuals:
    Min      1Q  Median      3Q     Max 
-4.7556 -1.4572  0.1821  1.2423  5.7758 

Coefficients:
            Estimate Std. Error t value  Pr(>|t|)    
(Intercept)   0.7812     0.4268   1.830     0.076 .  
USDJPY        1.2588     0.2304   5.463 0.0000043 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 2.56 on 34 degrees of freedom
Multiple R-squared:  0.4675,    Adjusted R-squared:  0.4518 
F-statistic: 29.84 on 1 and 34 DF,  p-value: 0.000004299
Gaussian <- "
  data{
    int N;
    vector[N] NIKKEI;
    vector[N] USDJPY;
  }
  parameters{
    real beta0;
    real beta1;
    real <lower = 0> sigma;
  }
  model{
    for(i in 1:N)
      NIKKEI[i] ~ normal(beta0 + beta1*USDJPY[i], sigma);
  }
  generated quantities{
    vector[N] pred_NIKKEI;
    real log_lik[N];
    for (i in 1:N){
      pred_NIKKEI[i] = normal_rng(beta0 + beta1*USDJPY[i], sigma);
      log_lik[i] = normal_lpdf(NIKKEI[i] | beta0 + beta1*USDJPY[i], sigma);
    }
  }
"
datalist <- list(N = N, NIKKEI = NIKKEI, USDJPY = USDJPY)
iter <- 1400
warmup <- 400
chains <- 3
fit <- stan(model_code = Gaussian, data = datalist, iter = iter, warmup = warmup, thin = 1, chains = chains)
summary(fit)$summary[c("beta0", "beta1", "sigma"), ]
           mean     se_mean        sd       2.5%       25%       50%      75%    97.5%    n_eff      Rhat
beta0 0.7817339 0.008645929 0.4468053 -0.1199323 0.4844077 0.7847294 1.072775 1.647716 2670.627 1.0001996
beta1 1.2600906 0.004499158 0.2441040  0.7806433 1.0954390 1.2620763 1.420930 1.733098 2943.657 0.9999622
sigma 2.6734301 0.007850652 0.3480554  2.0993973 2.4355424 2.6347859 2.888736 3.428350 1965.556 1.0002817
traceplot(fit) + theme(axis.text.x = element_text(size = 5), axis.text.y = element_text(size = 5), strip.text.x = element_text(size = 5), legend.title = element_text(size = 5), legend.text = element_text(size = 5))

# EAP:事後期待値
df_result <- rstan::extract(fit)$pred_NIKKEI %>% data.frame() %>% gather() %>% dplyr::mutate(id = rep(c(1:N), each = (iter - warmup) * chains)) %>% group_by(id) %>% dplyr::summarize(pred_EAP = mean(value), pred_lower = quantile(value, 0.025), pred_upper = quantile(value, 0.975)) %>% dplyr::ungroup() %>% cbind(data.frame(NIKKEI, USDJPY))
head(df_result)
  id   pred_EAP pred_lower pred_upper NIKKEI USDJPY
1  1  9.7803861   3.393467  16.158289   7.78   7.12
2  2 -0.6456243  -6.160500   4.616786   0.67  -1.05
3  3 -1.0664634  -6.496158   4.441089  -0.03  -1.45
4  4  0.7544332  -4.326904   6.008703   0.79  -0.05
5  5 -2.5165578  -8.008327   3.028394  -3.12  -2.59
6  6  3.1894930  -2.192086   8.799057   5.29   1.94
tail(df_result)
   id   pred_EAP pred_lower pred_upper NIKKEI USDJPY
31 31 -1.2495888  -6.699634   4.270056  -0.75  -1.58
32 32  0.9253778  -4.640626   6.425180   2.53   0.15
33 33 -1.5855537  -7.161076   3.671686  -4.46  -1.81
34 34  2.1105128  -3.099838   7.567190   4.63   1.06
35 35  1.5627999  -3.698246   6.738786   2.84   0.65
36 36  1.6579247  -3.719906   7.019581   4.89   0.73