2017年12月25日月曜日

calculate NIKKEI225





getSymbols("^GSPC")
getSymbols("NIKKEI225",src="FRED") # download nikkei 225
getSymbols("YJUSDJPY",src="yahooj")
N225 <- NIKKEI225  
k3 <-  "2007-01-01::2017-11-30"
result <- summary(lm(to.monthly(N225[k3])[,4] ~  to.monthly(GSPC[k3])[,4] + to.monthly(YJUSDJPY[k3])[,4]))
result$coefficients[2]*last(GSPC)[,4]+result$coefficients[3]*last(YJUSDJPY)[,4]+result$coefficients[1]
beep(2)

# or

getFX("USD/JPY")
YJUSDJPY <- USDJPY


> k3 <-  "2007-01-01::2017-11-30"
> result <- summary(lm(to.monthly(N225[k3])[,4] ~  to.monthly(GSPC[k3])[,4] + to.monthly(YJUSDJPY[k3])[,4]))
 警告メッセージ:
 to.period(x, "months", indexAt = indexAt, name = name, ...) で:
  missing values removed from data
>
> result

Call:
lm(formula = to.monthly(N225[k3])[, 4] ~ to.monthly(GSPC[k3])[,
    4] + to.monthly(YJUSDJPY[k3])[, 4])

Residuals:
     Min       1Q   Median       3Q      Max
-1997.11  -433.52    25.52   484.71  2025.68

Coefficients:
                                Estimate Std. Error t value Pr(>|t|) 
(Intercept)                   -9833.6019   476.8960  -20.62   <2e-16 ***
to.monthly(GSPC[k3])[, 4]         4.6365     0.1847   25.11   <2e-16 ***
to.monthly(YJUSDJPY[k3])[, 4]   161.7323     5.9325   27.26   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 755.9 on 128 degrees of freedom
Multiple R-squared:  0.9661, Adjusted R-squared:  0.9656
F-statistic:  1826 on 2 and 128 DF,  p-value: < 2.2e-16

> result$coefficients[2]*last(GSPC)[,4]+result$coefficients[3]*last(YJUSDJPY)[,4]+result$coefficients[1]
           GSPC.Close
2017-12-22   20925.53
>

0 件のコメント: