Skip to content

Instantly share code, notes, and snippets.

@tota
Last active December 16, 2015 11:39
Show Gist options
  • Save tota/5429232 to your computer and use it in GitHub Desktop.
Save tota/5429232 to your computer and use it in GitHub Desktop.
library(gdata)
library(quantmod)
title <- c("Date", "Open", "High", "Low", "Close", "Settlement Price", "Equivalent Rate", "Divident Equivalent", "Trading Volume", "Open Interest")
pastNKYJPY <- read.xls("http://www.tfx.co.jp/mkinfo/document/nky.xls", pattern="20101122")
thisMonthNKYJPY <- read.xls("http://www.click365.jp/cfd/data/cfdfile.xls", sheet=3)[,1:11][,-7]
thisMonthNKYJPY <- thisMonthNKYJPY[1:nrow(thisMonthNKYJPY)-1,]
thisMonthNKYJPY <- na.omit(thisMonthNKYJPY)
names(pastNKYJPY) <- title
names(thisMonthNKYJPY) <- title
lastDay <- strptime(last(thisMonthNKYJPY$Date), "%Y%m%d")
filename <- "PRT-010-CSV-015"
filename <- paste(filename, format(as.Date(lastDay) + 1, "%Y%m%d"), sep="-")
filename <- paste(filename, "CSV", sep=".")
url <- "http://www.tfx.co.jp/kawase/document/"
url <- paste(url, filename, sep="/")
latest <- read.csv(url, header=FALSE, fileEncoding="CP932")[2,]
rownames(latest) <- c(1:nrow(latest))
latest <- latest[setdiff(colnames(latest), c("V1", "V3", "V4", "V5", "V6", "V8", "V10", "V12", "V14", "V16"))]
names(latest) <- title
NKYJPY <- rbind(pastNKYJPY, thisMonthNKYJPY, latest)
#NKYJPY$Date <- as.Date(strptime(NKYJPY$Date, "%Y%m%d"))
NKYJPY$Date <- as.POSIXct(strptime(NKYJPY$Date, "%Y%m%d"), 'Asia/Tokyo')
NKYJPY[,2:ncol(NKYJPY)] <- sapply(NKYJPY[,2:ncol(NKYJPY)], as.numeric)
NKYJPY.xts <- as.xts(read.zoo(NKYJPY[,c("Date", "Open", "High", "Low", "Close", "Trading Volume")]))
chartSeries(NKYJPY.xts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment