Last active
August 15, 2017 11:04
-
-
Save ac00std/f790766af28a585686e31fba3f5ac93f to your computer and use it in GitHub Desktop.
stock price
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##########stock price########## | |
code=8604 ##野村HDの株価を指定 | |
year=2016 #2016年を指定 | |
#http://k-db.com/からスクレイピングを行います。 | |
url=paste("http://k-db.com/stocks/",code,"-T/1d/",year,"?download=csv",sep="") | |
stock_data=read.table(url,sep=",", skip=1) | |
date=rev(stock_data[["V1"]]) | |
stock=rev(stock_data[["V5"]]) | |
##########topix########## | |
url_topix=paste("http://k-db.com/indices/I102/1d/",year,"?download=csv",sep="") | |
topix_data=read.table(url_topix,sep=",", skip=1) | |
topix=rev(topix_data[["V5"]]) | |
##########data########## | |
x=diff(log(topix)) | |
y=diff(log(stock)) | |
data=data.frame(x = x, y = y) | |
plot(x, type="o", ann=F, ylim=c(-0.1, 0.1), col=rgb(1,0,0), pch=0) | |
par(new=T) | |
plot(y, type="o", ann=F, ylim=c(-0.1, 0.1), col=rgb(0,1,0), pch=1) | |
plot(topix/topix[1]-1, type="o", ann=F,ylim=c(-0.5, 0.1), col=rgb(1,0,0), pch=0) | |
par(new=T) | |
plot(stock/stock[1]-1, type="o", ann=F,ylim=c(-0.5, 0.1), col=rgb(0,1,0), pch=1) | |
##########log normal dist########## | |
m.lm <- lm(y ~ x , data = data) | |
summary(m.lm) | |
##########RSLN dist########## | |
library(MSwM) | |
m.mswm <- msmFit(m.lm, k = 2, sw = c(TRUE, TRUE, TRUE)) | |
summary(m.mswm) | |
plotReg(m.mswm, c('x'), regime = 1) | |
plotProb(m.mswm, which = 1) | |
plotDiag(m.mswm, which = 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment