2007年9月19日星期三

通过#R来绘制局部行情的K线图

方法一:本地数据作图

首先进入 R console. 装载 quantmod  xts .
准备好的 csv 格式的数据样例如下。文件名为 r.csv
01/08/2007 00:59:00,1.930250,1.930350,1.929300,1.929600,-60
01/08/2007 01:59:00,1.929600,1.930100,1.926250,1.928050,-60
01/08/2007 02:59:00,1.928050,1.929700,1.927700,1.927800,-60
01/08/2007 03:59:00,1.927800,1.928350,1.927200,1.928250,-60
01/08/2007 04:59:00,1.928250,1.929600,1.928250,1.929000,-60
01/08/2007 05:59:00,1.929000,1.929250,1.928650,1.929250,-60
01/08/2007 06:59:00,1.929250,1.930850,1.928700,1.930650,-60
01/08/2007 07:59:00,1.930650,1.933100,1.930250,1.933000,-60
01/08/2007 08:59:00,1.933000,1.934350,1.931050,1.931100,-60
01/08/2007 09:59:00,1.931100,1.934750,1.930350,1.934000,-60
01/08/2007 10:59:00,1.934000,1.934650,1.932300,1.932400,-60



> library(quantmod)     # 装载 quantmod
> quotes <- read.csv2("r.csv", header = FALSE, sep = ",", dec=".")
> x <- xts(as.matrix(quotes[,-1]),as.POSIXct(paste(quotes[,1]),format='%m/%d/%Y %H:%M'))
> colnames(x) <- c('Open','High','Low','Close','Volume')
> candleChart(x,TA=NULL)  # 画蜡烛图
> barChart(x,TA=NULL)     # 画竹线图

下面就是根据这些数据生成的 蜡烛图截图

原文链接

方法二:抓取网上数据作图

> install.packages('quantmod') # 安装quantmod包
> require(quantmod) #引用quantmod包
> getSymbols("GOOG",src="yahoo",from="2013-01-01", to='2013-04-24') #从雅虎财经获取google的股票数据
> chartSeries(GOOG,up.col='red',dn.col='green')  #显示K线图
> addMACD() #增加MACD图

原文链接

没有评论:

发表评论