from.year<-2008 from.month<-4 to.year<-2016 to.month<-3 assets<-c("国内債券","国内株式","外国債券","外国株式") fundname<-c("SMT 国内債券インデックス・オープン","SMT TOPIXインデックス・オープン","SMT グローバル債券インデックス","SMTグローバル株式インデックス") explanatory<-c(64315081,64313081,64316081,64314081) par(mfcol=c(2,4),family = "TakaoExMincho") zougen<-rep(NA,4) for (i in 1:4){ data<-read.table(text = "",col.names =c("date","NAV")) num<-ceiling((12*(to.year-from.year)+(to.month-from.month+1))/20) for (j in 1:num){ read2 <- readHTMLTable(paste0("http://info.finance.yahoo.co.jp/history/?code=",explanatory[i],"&sy=",from.year,"&sm=",from.month,"&ey=",to.year,"&em=",to.month,"&tm=m&p=",j)) temp<- data.frame(date=paste0(gsub("月","",chartr("年","-",read2[[2]][,1])),"-01"), NAV=as.numeric(gsub(",","",read2[[2]][,2]))) data<-rbind(data,temp) } names(data)<-c("date",assets[i]) x<-coredata(xts(read.zoo(data))[,1]) if (i==1) { funddata<-as.xts(read.zoo(data)) names(funddata)<-assets[i] } else { fundtemp<-as.xts(read.zoo(data)) ; names(fundtemp)<-assets[i] funddata<-merge(funddata,fundtemp) } plot(ts(x,start=c(from.year,from.month),freq=12),lwd=2,xlab="",ylab="",las=1) abline(h=coredata(xts(read.zoo(data))["2014-10"]),col="blue",lty=2) text(par("usr")[1] * 0.6 + par("usr")[2]*0.4 ,coredata(xts(read.zoo(data))["2014-10"]),"2014年10月末基準価額",pos=3,col="blue") title(fundname[i]) index.quarterlast<-endpoints(as.xts(ts(x,start=c(from.year,from.month),freq=12)),on="quarters") SMT<-ts(coredata(as.xts(ts(x,start=c(from.year,from.month),freq=12))[index.quarterlast]),start=c(from.year,1),freq=4) dat<-as.vector(window(SMT,start=c(2008,4),end=c(2015,3))) growth.SMT<-(dat[2:length(dat)]-dat[1:length(dat)-1])/dat[1:length(dat)-1]*100 res<-lm(GPIF2[,assets[i]]~growth.SMT + 0) res$coefficients summary(res)$r.squared plot(growth.SMT,GPIF2[,assets[i]],pch=20,xlab=fundname[i],ylab=assets[i],las=1) tx <- par("usr")[1] * 0.925 + par("usr")[2]*0.075 ty <- par("usr")[3] * 0.1 + par("usr")[4]*0.9 abline(0,res$coefficients,col="red",lwd=2) title(paste0("前期比増減率(",assets[i],")")) text(tx,ty,substitute(italic(y) == a %.% italic(x)*" , "~~italic(R)^2~"="~r2, list(a = signif(coef(res),3),r2 = signif(summary(res)$r.squared,3))),pos=4,cex=1.8) dat<-as.vector(window(SMT,start=c(2015,3),end=c(2015,4))) ( zougen[i]<-(dat[2]-dat[1])/dat[1] *100 ) ( zougen[i]<-zougen[i] * res$coefficients ) } par(mfrow=c(1,1))
|