Rでチャートを書いてみる(7)

前回でマスターまで取得ができたので、このマスターを用い、全銘柄分のデータを取得することにします。

取得したデータはリレーショナルデータベースへ格納するのが一般的かと思いますので、ここは簡単に扱えるSQLiteに入れることにします。

SQLiteをインストール

MacOSXの場合には以下のコマンドで一発です

brew install sqlite

つぎにRSQLiteパッケージをインストールします

install.packages("RSQLite")

準備が整ったらスクリプトを用意しこれを実行します

(前回までのRFinaiceYJの拡張関数を実行しておくこと)

library(RSQLite)
drv<-dbDriver("SQLite")
con<-dbConnect(drv,dbname="stock.db")
rs<-dbSendQuery(con,"drop table historicalData")
rs<-dbSendQuery(con,"create table historicalData (date text,open real,high real,
	low real,close real,volume real,adj_close real,code text)")
rs<-dbSendQuery(con,"create unique index idx_historicalData on historicalData(code,date)")

stockMaster<-quoteStockMasterTsData()

for(code in stockMaster$code){
	#cat(paste("code=",code,"\n",sep=""))
	data<-quoteStockTsData(code,"2010-01-01")
	data<-transform(data,code=code)
	data$code<-as.character(data$code)
	data$date<-as.character(data$date)
	dbBeginTransaction(con)
	dbSendQuery(con,paste("delete from historicalData where code='",code,"'",sep=""))
	dbSendPreparedQuery(con,"insert into historicalData
		(date,open,high,low,close,volume,adj_close,code)
	 	values(:date, :open, :high, :low, :close, :volume, :adj_close, :code)",bind.data=data)
	dbCommit(con)
}

かなり時間がかかると思いますが無事SQLiteにはいっていることが確認できます

sqlite> select * from historicalData;
2010-01-04|293.0|294.0|290.0|291.0|28100.0|291.0|3076
2010-01-05|293.0|293.0|288.0|288.0|81500.0|288.0|3076
..
2014-08-19|1534.0|1536.0|1505.0|1505.0|22900.0|1505.0|3791
2014-08-20|1505.0|1520.0|1505.0|1516.0|7100.0|1516.0|3791
  • 2014-8-24

もう少し使い勝手よくしてみました

library(RSQLite)

# fromDate: yyyy-MM-dd
getStockHistricalData<-function(stockMaster,fromDate){
	drv<-dbDriver("SQLite")
	con<-dbConnect(drv,dbname="stock.db")
	rs<-dbSendQuery(con,"drop table historicalData")
	rs<-dbSendQuery(con,"create table historicalData (date text,open real,high real,
		low real,close real,volume real,adj_close real,code text)")
	rs<-dbSendQuery(con,"create unique index idx_historicalData on historicalData(code,date)")

	#stockMaster<-quoteStockMasterTsData()

	for(code in stockMaster$code){
		print(paste("code=",code,sep=""))
		tryCatch({
			data<-quoteStockTsData(code,fromDate)
			data<-transform(data,code=code)
			data$code<-as.character(data$code)
			data$date<-as.character(data$date)
			dbBeginTransaction(con)
			dbSendQuery(con,paste("delete from historicalData where code='",code,"'",sep=""))
			dbSendPreparedQuery(con,"insert into historicalData
				(date,open,high,low,close,volume,adj_close,code)
			 	values(:date, :open, :high, :low, :close, :volume, :adj_close, :code)",bind.data=data)
			dbCommit(con)
		},
		error = function(e){
			message(paste("ERROR:",code))
			message(e)
		
		})
	}
}

Rでチャートを書いてみる(6)

株価を利用する際には株価コードの一覧が必要となってきます。そこで調子に乗って株価コードの一覧を取得してみました

例によってRFinanceYJに追加する関数です

quoteStockMasterTsData <- function(){

	financial.data <- data.frame(NULL)

	function.stockMasterData<-function(hira){
		r <- NULL
		result.num <- 20
		master.data <- data.frame(NULL)
		start.num<-0
		while( result.num >= 20 ){
			start.num <- start.num + 1
			quote.table <- NULL
			quote.url <- paste('http://stocks.finance.yahoo.co.jp/stocks/qi/?js=',hira,'&p=',start.num,sep="")
		
			try( r <- xmlRoot(htmlTreeParse(quote.url,error=xmlErrorCumulator(immediate=F))), TRUE)
			if( is.null(r) ) stop(paste("Can not access :", quote.url))

			try( quote.table <- xpathApply(r,"//a[contains(@href,'/stocks/detail')]"), TRUE )
			
			if( is.null(quote.table) ){
				if( is.null(master.data) ){
					stop(paste("Can not quote :", x))
				}else{
					return(master.data)
				}
			}

			size <- xmlSize(quote.table)/3
			if(size==0){
					return(master.data)
			}
			for(i in 1:size){
				mtmp<-data.frame(code=xmlValue(quote.table[[i*3-2]]),name=xmlValue(quote.table[[i*3-1]]))
				mtmp$code<-as.character(mtmp$code)
				mtmp$name<-as.character(mtmp$name)
				master.data <- rbind(master.data,mtmp)
			}
			
			result.num <- xmlSize(quote.table)/3
			Sys.sleep(1)
		}
		return(master.data)
	}

	hiraList<-"あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよわ"
	for(i in 1:nchar(hiraList)){
		hira<-substring(hiraList,i,i)
		master.data<-function.stockMasterData(hira)
		financial.data<-rbind(financial.data,master.data)

	}
	financial.data <- financial.data[order(financial.data$code),]
	return(financial.data)	

}

YahooFinanceの銘柄名の頭文字から一覧を得るページがあるのでこちらからダウンロードするようにしました。

結果ですが、ページ数が多いので若干時間がかかります。

> stockMaster<-quoteStockMasterTsData()
> stockMaster
		 code																						 name
1		3076											 あい ホールディングス(株)
2		7013																			 (株)IHI
3		4812																				 ISID
4		9753											 アイエックス・ナレッジ(株)
..
3451 9927																	 (株)ワットマン
3452 2918																 わらべや日洋(株)
3453 3344										 (株)ワンダーコーポレーション
3454 7564																	 (株)ワークマン
3455 2429										 (株)ワールドホールディングス

全銘柄とれるようになりました!

  • 2014.8.17

銘柄コード純になるように修正してみました

Rでチャートを書いてみる(5)

いつの間にかQiitaに引用されていました。(^^!

http://qiita.com/HirofumiYashima/items/4b3a3a3e49be59d81e4f

うまく動かないとのことなので修正をしてみました。

RFinanceYJはYahooのHTML変更に振り回されているようで、うまく動かない場合が多いです。

> library(RFinanceYJ)
> quoteStockTsData("6758.t")
 以下にエラー order(financial.data$date) :	引数 1 がベクトルではありません 

どうもStockTsDataの↓の部分でテーブルの形を決まりきった物として扱っているので、Yahoo側のちょっとした変更(たとえば上の方になんか広告などを追加するとか)に負けてしまっています。

	extractQuoteTable <- function(r,type){
		if(type %in% c("fund","fx")){
			tbl <- r[[2]][[2]][[7]][[3]][[3]][[9]][[2]]
		}
		else{
			tbl <- r[[2]][[2]][[7]][[3]][[3]][[10]][[2]]
		}
		return(tbl)
	}
	
	while( result.num >= 51 ){
		start.num <- start.num + 1
		quote.table <- NULL
		quote.url <- paste('http://info.finance.yahoo.co.jp/history/?code=',x,start,end,'&p=',start.num,'&tm=',substr(time.interval,1,1),sep="")

..

		#try( quote.table <- r[[2]][[1]][[1]][[16]][[1]][[1]][[1]][[4]][[1]][[1]][[1]], TRUE )
		try( quote.table <- extractQuoteTable(r,type), TRUE )

Xpathで解析するようにし、若干の変更には耐えられるように修正してみました。この株価ページにはテーブルが3個あり、その2番目が株価のテーブルですので、最新版の0.3.1にまたまたパッチを当ててみました。こう書き換えます。

		#try( quote.table <- extractQuoteTable(r,type), TRUE )
		try( quote.table <- xpathApply(r,"//table")[[2]], TRUE )

この関数だけを読み込んでもだめなので全体を記述しそれをlibrary(RFinanceYJ)に続けて読んでやります

library(RFinanceYJ)
#API
quoteStockTsData <- function(x, since=NULL,start.num=0,date.end=NULL,time.interval='daily')
{
	time.interval <- substr(time.interval,1,1)
	function.stock <- function(quote.table.item){
		if( xmlSize(quote.table.item) < 5) return(NULL) 
		d <- convertToDate(xmlValue(quote.table.item[[1]]),time.interval)
		o <- as.number(xmlValue(quote.table.item[[2]]))
		h <- as.number(xmlValue(quote.table.item[[3]]))
		l <- as.number(xmlValue(quote.table.item[[4]]))
		c <- as.number(xmlValue(quote.table.item[[5]]))
		v <- ifelse(xmlSize(quote.table.item) >= 6,as.number(xmlValue(quote.table.item[[6]])),0)
		a <- ifelse(xmlSize(quote.table.item) >= 7,as.number(xmlValue(quote.table.item[[7]])),0)
		return(data.frame(date=d,open=o,high=h,low=l,close=c,volume=v, adj_close=a))
	}
	return(quoteTsData(x,function.stock,since,start.num,date.end,time.interval,type="stock"))
}
quoteFundTsData <- function(x, since=NULL,start.num=0,date.end=NULL,time.interval='daily')
{
	time.interval <- substr(time.interval,1,1)
	function.fund <- function(quote.table.item){
		d <- convertToDate(xmlValue(quote.table.item[[1]]),time.interval)
		if(time.interval=='monthly'){
			d <- endOfMonth(d)
		}
		c <- as.number(xmlValue(quote.table.item[[2]]))
		v <- as.number(xmlValue(quote.table.item[[3]]))
		return(data.frame(date=d,constant.value=c,NAV=v))
	}
	return(quoteTsData(x,function.fund,since,start.num,date.end,time.interval,type="fund"))
}
quoteFXTsData <- function(x, since=NULL,start.num=0,date.end=NULL,time.interval='daily')
{
	time.interval <- substr(time.interval,1,1)
	function.fx <- function(quote.table.item){
		d <- convertToDate(xmlValue(quote.table.item[[1]]),time.interval)
		o <- as.number(xmlValue(quote.table.item[[2]]))
		h <- as.number(xmlValue(quote.table.item[[3]]))
		l <- as.number(xmlValue(quote.table.item[[4]]))
		c <- as.number(xmlValue(quote.table.item[[5]]))
		return(data.frame(date=d,open=o,high=h,low=l,close=c))
	}
	return(quoteTsData(x,function.fx,since,start.num,date.end,time.interval,type="fx"))
}
######	private functions	#####
#get time series data from Yahoo! Finance.
quoteTsData <- function(x,function.financialproduct,since,start.num,date.end,time.interval,type="stock"){
	r <- NULL
	result.num <- 51
	financial.data <- data.frame(NULL)
	#start <- (gsub("([0-9]{4,4})-([0-9]{2,2})-([0-9]{2,2})","&c=\\1&a=\\2&b=\\3",since))
	#end	 <- (gsub("([0-9]{4,4})-([0-9]{2,2})-([0-9]{2,2})","&f=\\1&d=\\2&e=\\3",date.end))
	start <- (gsub("([0-9]{4,4})-([0-9]{2,2})-([0-9]{2,2})","&sy=\\1&sm=\\2&sd=\\3",since))
	end	 <- (gsub("([0-9]{4,4})-([0-9]{2,2})-([0-9]{2,2})","&ey=\\1&em=\\2&ed=\\3",date.end))

	if(!any(time.interval==c('d','w','m'))) stop("Invalid time.interval value")
	
	extractQuoteTable <- function(r,type){
		if(type %in% c("fund","fx")){
			tbl <- r[[2]][[2]][[7]][[3]][[3]][[9]][[2]]
		}
		else{
			tbl <- r[[2]][[2]][[7]][[3]][[3]][[10]][[2]]
		}
		return(tbl)
	}
	
	while( result.num >= 51 ){
		start.num <- start.num + 1
		quote.table <- NULL
		quote.url <- paste('http://info.finance.yahoo.co.jp/history/?code=',x,start,end,'&p=',start.num,'&tm=',substr(time.interval,1,1),sep="")
	
		#try( r <- xmlRoot(htmlTreeParse(quote.url,error=xmlErrorCumulator(immediate=F))), TRUE)	# これだと取得時にエラーが出た。。
		try(r<-htmlParse(quote.url))
		if( is.null(r) ) stop(paste("Can not access :", quote.url))

		#try( quote.table <- r[[2]][[1]][[1]][[16]][[1]][[1]][[1]][[4]][[1]][[1]][[1]], TRUE )
		#try( quote.table <- extractQuoteTable(r,type), TRUE )
		try( quote.table <- xpathApply(r,"//table")[[2]], TRUE )
		
		if( is.null(quote.table) ){
			if( is.null(financial.data) ){
				stop(paste("Can not quote :", x))
			}else{
				 financial.data <- financial.data[order(financial.data$date),]
				 return(financial.data)
			}
		}

		size <- xmlSize(quote.table)
		for(i in 2:size){
			financial.data <- rbind(financial.data,function.financialproduct(quote.table[[i]]))
		}
		
		result.num <- xmlSize(quote.table)
		Sys.sleep(1)
	}
	financial.data <- financial.data[order(financial.data$date),]
	return(financial.data)	
}
#convert string formart date to POSIXct object
convertToDate <- function(date.string,time.interval)
{
	#data format is different between monthly and dialy or weekly
	if(any(time.interval==c('d','w'))){
		result <- gsub("^([0-9]{4})([^0-9]+)([0-9]{1,2})([^0-9]+)([0-9]{1,2})([^0-9]+)","\\1-\\3-\\5",date.string)
	}else if(time.interval=='m'){
		result <- gsub("^([0-9]{4})([^0-9]+)([0-9]{1,2})([^0-9]+)","\\1-\\3-01",date.string)
	}
	return(as.POSIXct(result))
}
#convert string to number.
as.number <- function(string)
{
	return(as.double(as.character(gsub("[^0-9.]", "",string))))
}
#return end of month date.
endOfMonth <- function(date.obj)
{
	startOfMonth		 <- as.Date(format(date.obj,"%Y%m01"),"%Y%m%d")
	startOfNextMonth <- as.Date(format(startOfMonth+31,"%Y%m01"),"%Y%m%d")
	return(startOfNextMonth-1)
}

実行結果

> quoteStockTsData("6758.t",since="2010-01-01")
					 date	 open	 high		low	close		volume adj_close
1136 2010-01-04 2700.0 2744.0 2694.0 2731.0	 4004500		2731.0
1135 2010-01-05 2781.0 2782.0 2704.0 2719.0	 4894300		2719.0
1134 2010-01-06 2719.0 2757.0 2699.0 2744.0	 4270900		2744.0
1133 2010-01-07 2750.0 2764.0 2723.0 2743.0	 2899600		2743.0
1132 2010-01-08 2785.0 2809.0 2769.0 2809.0	 6981100		2809.0
..

長いヒストリカルデータも何のその!!

2014.8.19

HirofumiYashima様の指摘により修正してみました

なお、実行環境はMacOS10.9のR version 3.0.3 です

2015.1.20

こちらの記事はYahooの仕様変更によりとれなくなってしまいました

http://d.hatena.ne.jp/anagotan/20150120

こちらを参照ください

統計ソフトRを使用して株価チャートを簡単に作成(4)

ようやくチャートが描ける準備が整ったので分析に入ります。

まずは自分で作成した計算式で作成した値をチャートに書いてみます

library(RFinanceYJ)
library(quantmod)
stockCode<-"6758.t"
today<-Sys.Date()
sinceDate<-today-100 #100日分
stockData<-quoteStockTsData(stockCode,since=sinceDate)
colnames(stockData)<-c("Date","Open","High","Low","Close","Volume")
stockData.zoo<-read.zoo(stockData)
candleChart(stockData.zoo,theme="white")
#とりあえず平均値をチャート領域に書いてみる
mydata<-data.frame(Date=stockData$Date,Close=mean(stockData$Close))
mydata.zoo<-read.zoo(mydata)
addTA(mydata.zoo,on=1,col="red")

統計ソフトRを使用して株価チャートを簡単に作成(3)

データをとれるようになったのでチャートを書いてみる

library(quantmod)
library(RFinanceYJ)
stockCode<-"6758.t"
today<-Sys.Date()
dataTerm<-100 # 100日分取得
sinceDate<-today-dataTerm
colnames(stockData)<-c("Date","Open","High","Low","Close","Volume")
stockData.zoo<-read.zoo(stockData)
candleChart(stockData.zoo,theme="white")

ファイルにする場合はこちら

library(quantmod)
library(RFinanceYJ)
stockCode<-"6758.t"
today<-Sys.Date()
dataTerm<-100 # 100日分取得
sinceDate<-today-dataTerm
colnames(stockData)<-c("Date","Open","High","Low","Close","Volume")
stockData.zoo<-read.zoo(stockData)
pngDir<-"png/"
fileName<-paste(pngDir,stockCode,".png",sep="")
png(fileName,width=600,height=400)
candleChart(stockData.zoo,theme="white")
dev.off()

これをシェルでまわせば複数銘柄とれます

  • chart.R
stockCode<-commandArgs()[5]
library(quantmod)
library(RFinanceYJ)
today<-Sys.Date()
dataTerm<-100 # 100日分取得
sinceDate<-today-dataTerm
colnames(stockData)<-c("Date","Open","High","Low","Close","Volume")
stockData.zoo<-read.zoo(stockData)
pngDir<-"png/"
fileName<-paste(pngDir,stockCode,".png",sep="")
png(fileName,width=600,height=400)
candleChart(stockData.zoo,theme="white")
dev.off()
  • chart.sh
#!/bin/sh
codes="
6758
9501
9433
"
for code in $codes;do
R --vanilla --slave --args ${code}.t <	chart.R
done

統計ソフトRを使用して株価チャートを簡単に作成(2)

RFinanceYJパッケージですがどうやらYahoo側の変更のせいでうまく動かないみたいです

> stockCode<-"6758.t"
> quoteStockTsData(stockCode)
 以下にエラー as.POSIXlt.character(x, tz, ...) : 
	character string is not in a standard unambiguous format

いろいろ調べてみたところ、どうやら日付部分が日本語のためうまく処理できていないようでした。

ちょっといじったソースはこれ


quoteStockTsData <- function(x, since=NULL,start.num=0,date.end=NULL,time.interval='daily')
{
	function.stock <- function(quote.table.item){
		if( xmlSize(quote.table.item) < 5) return(NULL)
		d <- convertToDate(xmlValue(quote.table.item[[1]]),time.interval)
		o <- as.number(xmlValue(quote.table.item[[2]]))
		h <- as.number(xmlValue(quote.table.item[[3]]))
		l <- as.number(xmlValue(quote.table.item[[4]]))
		c <- as.number(xmlValue(quote.table.item[[5]]))
		v <- ifelse(xmlSize(quote.table.item) >= 6,as.number(xmlValue(quote.table.item[[6]])),0)
		return(data.frame(date=d,open=o,height=h,low=l,close=c,volume=v))
	}
	return(quoteTsData(x,function.stock,since,start.num,date.end,time.interval))
}
quoteFundTsData <- function(x, since=NULL,start.num=0,date.end=NULL,time.interval='daily')
{
	function.fund <- function(quote.table.item){
		d <- convertToDate(xmlValue(quote.table.item[[1]]),time.interval)
		if(time.interval=='monthly'){
			d <- endOfMonth(d)
		}
		c <- as.number(xmlValue(quote.table.item[[2]]))
		v <- as.number(xmlValue(quote.table.item[[3]]))
		return(data.frame(date=d,constant.value=c,NAV=v))
	}
	return(quoteTsData(x,function.fund,since,start.num,date.end,time.interval))
}
quoteFXTsData <- function(x, since=NULL,start.num=0,date.end=NULL,time.interval='daily')
{
	function.fx <- function(quote.table.item){
		d <- convertToDate(xmlValue(quote.table.item[[1]]),time.interval)
		o <- as.number(xmlValue(quote.table.item[[2]]))
		h <- as.number(xmlValue(quote.table.item[[3]]))
		l <- as.number(xmlValue(quote.table.item[[4]]))
		c <- as.number(xmlValue(quote.table.item[[5]]))
		return(data.frame(date=d,open=o,height=h,low=l,close=c))
	}
	return(quoteTsData(x,function.fx,since,start.num,date.end,time.interval))
}


quoteTsData <- function(x,function.financialproduct,since,start.num,date.end,time.interval){
	r <- NULL
	result.num <- 51
	quote.table.list <- list(NULL)
	quote.table <- NULL
	financial.data <- data.frame(NULL)
	start <- (gsub("([0-9]{4,4})-([0-9]{2,2})-([0-9]{2,2})","&c=\\1&a=\\2&b=\\3",since))
	end	 <- (gsub("([0-9]{4,4})-([0-9]{2,2})-([0-9]{2,2})","&f=\\1&d=\\2&e=\\3",date.end))

	if(!any(time.interval==c('daily','weekly','monthly'))) stop("Invalid time.interval value")
	
	while( result.num >= 51 ){
		quote.url <- paste('http://table.yahoo.co.jp/t?s=',x,start,end,'&y=',start.num,'&g=',substr(time.interval,1,1),sep="")
		try( r <- xmlRoot(htmlTreeParse(quote.url,encoding="EUC-JP",error=xmlErrorCumulator(immediate=F))), TRUE)
		if( is.null(r) ) stop(paste("Can not access :", quote.url))

		try( quote.table <- r[[2]][[1]][[1]][[13]][[1]][[1]][[1]][[4]][[1]][[1]][[1]], TRUE )
		if( is.null(quote.table) ) stop(paste("Can not quote :", x))

		size <- xmlSize(quote.table) 

		for(i in 2:size){
			financial.data <- rbind(financial.data,function.financialproduct(quote.table[[i]]))
		}	 
					
		result.num <- xmlSize(quote.table)
		start.num <- start.num + 50
		Sys.sleep(1)
	}
	financial.data <- financial.data[order(financial.data$date),]
	return(financial.data)
}

#convert string formart date to POSIXct object
convertToDate <- function(date.string,time.interval)
{
	#date.string <- iconv(date.string,"EUC-JP","UTF-8","")
	date.string<-gsub("日","",gsub("[年月]","-",date.string))
	#data format is different between monthly and dialy or weekly
	if(any(time.interval==c('daily','weekly'))){
		result <- gsub("^([0-9]{4})([^0-9]+)([0-9]{1,2})([^0-9]+)([0-9]{1,2})([^0-9]+)","\\1-\\3-\\5",date.string)
	}else if(time.interval=='monthly'){
		result <- gsub("^([0-9]{4})([^0-9]+)([0-9]{1,2})([^0-9]+)","\\1-\\3-01",date.string)
	}
	return(as.POSIXct(result))
}

#convert string to number.
as.number <- function(string)
{
	return(as.double(as.character(gsub("[^0-9.]", "",string))))
}
#return end of month date.
endOfMonth <- function(date.obj)
{
	startOfMonth		 <- as.Date(format(date.obj,"%Y%m01"),"%Y%m%d")
	startOfNextMonth <- as.Date(format(startOfMonth+31,"%Y%m01"),"%Y%m%d")
	return(startOfNextMonth-1)
}


これをRFinanceYJパッケージに続けて呼べばデータが取得できました

> 
> quoteStockTsData("6758.t")
				 date open height	low close	 volume
62 2013-03-25 1694	 1729 1662	1712 34382500
61 2013-03-26 1682	 1688 1660	1666 26291500
60 2013-03-27 1666	 1691 1663	1675 18503100
59 2013-03-28 1663	 1666 1587	1625 33812600
...

統計ソフトRを使用して株価チャートを簡単に作成(1)

統計ソフトのRには様々なパッケージがありExcelなどでは結構手間がかかることでもあっという間にできる場合があります

今回は株価チャートを作成してみました

まずはRのインストールから

環境

  • mac OS10.8.3
  • R 3.0.1

http://cran.r-project.org/

  1. こちらからMacOX用のものをダウンロード。(以前は32ビット、64ビットと分かれていたが統合されたみたい)
  2. インストールして起動
  3. チャート用のパッケージとデータダウンロード用のパッケージを入れる
> #プロキシサーバ越えの場合はこれを入れる
> Sys.setenv(http_proxy="http://proxyserver:port")
> 
> install.packages("quantmod")
> install.packages("RFinanceYJ")
> library(RFinanceYJ)
 要求されたパッケージ XML をロード中です 
> library(quantmod)
 要求されたパッケージ Defaults をロード中です 
 要求されたパッケージ xts をロード中です 
 要求されたパッケージ zoo をロード中です 

 次のパッケージを付け加えます: ‘zoo’ 

 以下のオブジェクトはマスクされています (from ‘package:base’) : 

		 as.Date, as.Date.numeric 

 要求されたパッケージ TTR をロード中です 
Version 0.4-0 included new data defaults. See ?getSymbols.
> stockData<-quoteStockTsData("6758.t")
 以下にエラー order(financial.data$date) :	引数 1 がベクトルではありません 

なぜかエラー。。。