k3 <- "2007-01-01:
# or
k3 <- paste
k3
# downlo
# getSymbol
getSymbols('YJUSDJPY', src="yahooj",auto.assign=TRUE)
N225 <- NIKKEI225
# resu
result_nikkei
plot(merge(as.xts(predict(result_nikkei),index(residuals(result_nikkei))),to.monthly(N225[k3])[,4],residuals(result_nikkei)),main=paste(paste("NIKKEI225 =",round(result_nikkei$coefficients[2],4),"* GSPC +",round(result_nikkei$coefficients[3],2),"*USDJPY +",round(result_nikkei$coefficients[1],2))))
tmp.legend <- paste("R Squared is ",round(summary(result_nikkei)$r.squared,4)," \n","DF is ",round(summary(result_nikkei)$df[2],0),sep=' ')
addLegend(legend.loc = "topleft", legend.names = tmp.legend,col=3)
Call:
4]
Residuals:
Min 1Q Median 3Q Max
-1875.41 -473.74 -12.89 507.10 1855.32
Coefficients:
Estimate Std. Error t value
(Intercept) -9864.4555 499.7539 -19.74 <2e-16 ***
---
Residual standard error: 792.4 on 131 degrees of freedom
Multiple R-squared: 0.9655, Adjusted R-squared: 0.965
F-statistic: 1832 on 2 and 131 DF, p-value: < 2.2e-16
>
Call:
4], mean) + apply
Residuals:
Min 1Q Median 3Q Max
-1992.66 -510.50 51.79 469.11 2524.40
Coefficients:
Estimate Std. Error t value
(Intercept) -1.017e+04 2.593e+02 -39.24 <2e-16 ***
---
Residual standard error: 754.9 on 445 degrees of freedom
(132 observations deleted due to
Multiple R-squared: 0.9674, Adjusted R-squared: 0.9673
F-statistic: 6612 on 2 and 445 DF, p-value: < 2.2e-16
result <- lm(apply.weekly(N225[k3],mean) ~ apply.weekly(GSPC[k3][,4],mean) + apply.weekly(YJUSDJPY[k3][,4],mean))
tmp.main <- paste("NIKKEI225 =",round(result$coefficients[2],4),"* GSPC +",round(result$coefficients[3],2),"*USDJPY +",round(result$coefficients[1],2))
nikkei_week <- na.omit(apply.weekly(N225[k3],mean))
predict_nikkei_week <- predict(lm(apply.weekly(N225[k3],mean) ~ apply.weekly(GSPC[k3][,4],mean) + apply.weekly(YJUSDJPY[k3][,4],mean)))
if(length(nikkei_week) > length(predict_nikkei_week)){
plot(merge(last(nikkei_week,n=length(predict_nikkei_week),predict_nikkei_week)),main=tmp.main)
}else{
plot(merge(nikkei_week,last(predict_nikkei_week,n=length(nikkei_week))),main=tmp.main)
}
# add legend at topleft
#
#
addLegend(legend.loc = "topleft", legend.names = paste("R Squared",round(summary(result)$r.squared,4),sep=':'),col=2)
or
tmp.legend <- paste("R Squared is ",round(summary(result)$r.squared,4)," \n","DF is ",round(summary(result)$df[2],0),sep=' ')
addLegend(legend.loc = "topleft", legend.names = tmp.legend,col=3)
use grid.ticks.on='months' to show grid on monthly basis.
0 件のコメント:
コメントを投稿