Skip to content

Instantly share code, notes, and snippets.

@ac00std ac00std/stock price
Last active Aug 15, 2017

Embed
What would you like to do?
stock price
##########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
You can’t perform that action at this time.