R学习笔记:quantmod取得股票数据并画出图表(2)


原文:http://www.quantmod.com/examples/charting/

    如果说有一个R领域有点欠缺的话,那就是用标准的财务图表工具来可视化金融、财务数据。quantmod提供了一个解决方案。

基本操作:

getSymbols("GS") #下载数据 
chartSeries(last(GS, '6 months')) 

结果:


稍微升级点:

barChart(GS,theme='white.mono',bar.type='hlc') 

下面这个是彩色的:

candleChart(last(GS, '6 months'),multi.col=TRUE,theme='white')

linechart:

lineChart(last(GS, '6 months'),line.type='h',TA=NULL) 

可以看到,各种各样的选项可供选择,真的好灵活。

形式参数:颜色,裁剪,刻度。

通过调整参数,看看结果的不同。

chartSeries(GS) #全部数据

改下数据子集。

candleChart(GS,subset='2007-12::2008') #07年十二月至08年最后

小改变:

candleChart(GS,theme='white', type='candles') 
reChart(major.ticks='months',subset='first 16 weeks') # reChart 用于修改前面的图表

技术分析

目前TTR包和quantmod包提供的一些指示器(指标):


指标TTR 名称quantmod 名称
Welles Wilder's Directional Movement IndicatorADXaddADX
Average True RangeATRaddATR
Bollinger BandsBBandsaddBBands
Bollinger Band WidthN/AaddBBands
Bollinger %bN/AaddBBands
Commodity Channel IndexCCIaddCCI
Chaiken Money FlowCMFaddCMF
Chande Momentum OscillatorCMOaddCMO
Double Exponential Moving AverageDEMAaddDEMA
Detrended Price OscillatorDPOaddDPO
Exponential Moving AverageEMAaddEMA
Price EnvelopeN/AaddEnvelope
Exponential Volume Weigthed Moving AverageEVWMAaddEVWMA
Options and Futures ExpirationN/AaddExpiry
Moving Average Convergence DivergenceMACDaddMACD
MomentummomentumaddMomentum
Rate of ChangeROCaddROC
Relative Strength IndicatorRSIaddRSI
Parabolic Stop and ReverseSARaddSAR
Simple Moving AverageSMAaddSMA
Stocastic Momentum IndexSMIaddSMI
Triple Smoothed Exponential OscillatorTRIXaddTRIX
VolumeN/AaddVo
Weighted Moving AverageWMAaddWMA
Williams %RWPRaddWPR
ZLEMAZLEMAaddZLEMA

试一试。

TA=NULL表示什么指标都不画。last(GS, '6 months'),是为了使数据量小一点,要不糊成一片,看不出效果。

chartSeries(last(GS, '6 months'), TA=NULL) 


下面我们增加指标。

chartSeries(last(GS, '6 months'), theme="white", TA="addVo();addBBands();addCCI()")

这次画出非常惊艳的图:


一行一行来,也可以得到上面的效果:

chartSeries(last(GS, '6 months'), theme="white") #draw the chart 
addVo() #add volume 
addBBands() #add Bollinger Bands 
addCCI() #add Commodity Channel Index

quantmod两个最新功能

addTA

newTA

chartSeries(last(GS, '6 months'), TA=NULL) 

#Then add the Open to Close price change 
#using the quantmod OpCl function 

addTA(OpCl(last(GS, '6 months')),col='blue', type='h')

# Using newTA it is possible to create your own 
# generic TA function --- let's call it addOpCl 
# 
addOpCl <- newTA(OpCl,col='green',type='h') 

addOpCl() 

关于chartSeries 和 quantmod 的当前以及未来的可视化工具,可说的内容太多了。今天到此结束。



  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值