之前折腾一系列装R的帖子,其实我最初的目的就是升级一下R的版本,使之能安装上quantmod,R的量化金融建模与交易框架(Quantitative Financial Modelling & Trading Framework for R)。
其实这玩意是啥,干啥的,我一点也不知道,只是因为有问到了这个东西,我想试一下而已,比如说最起码的安装。这次折腾完新版本的R,来体验一下这个东东吧。
安装
安装是超级简单的啦,在R环境中执行以下指令即可:
install.packages('quantmod')
因为我使用的是普通的账户,所以会提示如下信息:
我推荐使用非安装时使用的账户或者超级权限账户来玩R,这样就会创建一个个人库,一旦我们玩坏了,直接rm -rf *
删除,重新来玩即可,还不破坏我的R安装环境。
之后会提示选择CRAN镜像(CRAN mirrors),这个根据你的地理位置大致选一个能觉得访问挺快的就好,部分截图如下:
敲入镜像编号等安装就行了
可见它还装入一堆其它依赖包。
因为我使用的是源码编译,所以安装每个包都要编译一些文件,不过相比装R,还是很快的,不出异常的话很快就会完成。
需要注意的是,因为我之前使用过不同方法Build R ,然后还试过安装quantmod,在重新安装之前,我需要rm -rf *
个人目录下的R库,否则会安装失败。
加载
安装之后,我们需要首先加载软件包,才能使用其内的各种指令和功能等。
library(quantmod)
加载成功,说明我装的没啥问题。
加载数据
加载股票数据
getSymbols("AAPL",src="yahoo")
查看数据(注意不要加双引号)
head(AAPL)
tail(AAPL)
绘图
使用如下指令可以绘制这个股票的时间和价格曲线
chartSeries(AAPL, TA=NULL)
barChart(AAPL)
其它柱状图啥的我就不演示了,因为我根本不知道是啥意思。
技术指标
chartSeries(AAPL)
addMACD()
除了知道这是一种技术指标,我就啥也不知道了。😵
chartSeries(AAPL)
addMACD()
addADX()
除了赞叹一声好看,我还能说啥?
好了,就体验到这吧,我是根本玩不来啦😭
相关链接
- 学R:准备工作
- 继续学R:安装软件包
- 继续学R:另一款在线R环境
- 继续学R:R的6大基本数据类型(原子向量)
- 继续学R:Vector(向量) Part 1, 多元素向量创建&类型
- 继续学R:Vector(向量) Part 2, 多元素向量访问 & 计算长度
- 继续学R:Vector(向量) Part 3, 多元素向量的操作(算术操作&排序)
- 继续学R:List(列表) Part 1, 创建列表&命名&访问
- 继续学R:List(列表) Part 2, 列表的操作
- 继续学R:Matrices(矩阵) Part 1,创建矩阵&命名&访问
- 继续学R:Matrices(矩阵) Part 2,矩阵访问方式&矩阵操作&进阶操作
- 继续学R:在Linux下源码方式装R / Installing R from source
- 继续学R:重新装R / Installing R from source (2) 又掉坑里了😭
- 继续学R:重新装R / Installing R from source (3) 再也不装R了
- Quantitative Financial Modelling & Trading Framework for R
- A Guide On R Quantmod Package: How To Get Started?
o神o神,我惊恐的发现,您老人家每天坚持学R,发帖赚的钱应该比写这本书的作者赚得钱还多啊!
大鹏被无情的秒杀了,您让大鹏情何以堪啊。。。
@dapeng
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
感觉会很热闹,先占个座Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
啊,还有这个问题?我真没想到这点
那要不我改学Python吧,学R系列暂停更新了
向 @dapeng 致歉
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
分点钱给@dapeng呗,哈哈哈
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
向o哥致谢!请继续!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
理论上无论谁发帖发啥帖都比我从写书里挣得多——出版社还没回本儿,我一分钱都没拿到……所以,你们都尽情来秒杀我吧……
期待o神坚持下去,每多坚持一天,就为我的书多做一天广告!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
决定再发一个总结贴就停掉了
请原谅我继续赚一个总结贴的钱 😂
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
停几天再继续,正好让大家从学R的氛围中休息一下。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
为了避免群众继续帮 @dapeng 打抱不平,决定无限期停止了
回头写学 Python,貌似比学R容易 😀
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
完了,我坏了大鹏哥的好事了,大鹏哥@dapeng不要砍我。。。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
有些quantmod的数据不准,本来打算做back test的
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
是抓来的数据不准还是对数据分析的结果不准呢?
如果是源头上的,quantmod就没法背锅了
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
一直坚持的O哥哥,很棒
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
好看!!!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
buen post
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit