データをとれるようになったのでチャートを書いてみる
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