R与金融投资分析的框架

上传人:d****y 文档编号:98592930 上传时间:2019-09-12 格式:PPTX 页数:21 大小:358.40KB
返回 下载 相关 举报
R与金融投资分析的框架_第1页
第1页 / 共21页
R与金融投资分析的框架_第2页
第2页 / 共21页
R与金融投资分析的框架_第3页
第3页 / 共21页
R与金融投资分析的框架_第4页
第4页 / 共21页
R与金融投资分析的框架_第5页
第5页 / 共21页
点击查看更多>>
资源描述

《R与金融投资分析的框架》由会员分享,可在线阅读,更多相关《R与金融投资分析的框架(21页珍藏版)》请在金锄头文库上搜索。

1、,R与金融投资分析的框架,数据、模型、策略及报告,第五届中国R语言会议,前言,要学会安抚自己那颗略带恐惧的心! 彼得林奇,2,CAPM模型,理论基础: Alpha来源:基本面财务建模 行业分析 Beta来源: 股票与指数相关性回归分析 Rm来源: 指数波动股指建模 宏观建模,3,一个框架,财务数据 技术分析数据,宏观数据 行业数据,模型,因 子,策略,4,数据篇,数据,数据,没有数据的推理是罪恶! 福尔摩斯,数据的重要性,数据和信息是金融分析的灵魂 模型与策略都是基于数据得出 模型好坏的判断标准便是未来的数据是否 符合模型的预测结果 与策略相比,客户更关心的是数据,6,金融数据处理与R,R是处

2、理金融数据的利器 数据的导入与导出(R Data Import/Export) 可以处理多种类型的数据 数据重整与清洗 数据的可视化(grahphics,lattice,ggplot2,ggobi) 针对数据进行建模 提供了线性回归、机器学习等各种模型的函数,7,模型篇,All models are wrong but some are useful. George E. P. Box,模型的作用,模型是数据的统帅 好的模型往往可以将繁杂的数据提炼成一 条简单的规律。比如一条回归线便可以刻 画一群杂乱的点。 好的模型可以稳定地预测或者指导未来。,9,金融模型与R,几乎所有的统计模型在金融分析都

3、有涉及 线性回归模型与CAPM模型 移动平均与MACD指标 协整与套利 GARCH,SV模型与波动率 极值理论与涨跌预测 突发冲击与传递模型、时间序列聚类 ,10,相关的R包,base/stat/MASS e1071/kernlab/klar/svmpath rugarch/fgarch/gogarch rpart/party quantmod/blotter/quantstrat/TTR,11,相关书籍,12,策略篇,知己知彼,百战不殆! 孙子谋攻,策略的意义,金融建模的目的是为了从数据中找出金融 市场的波动规律,继而开始出可以持续盈 利的策略。 好的策略应当可以在一定时期内战胜市场 先生(

4、Mr. Market)。,14,策略的类型,价值投资型策略 格雷厄姆、费雪、巴菲特、芒格 量化投资型策略 索普、西蒙斯 技术分析型策略 江恩,15,相关R包,Quantstrat Blotter quantmod,16,quantstrat示例,#thanks so much to the developers of quantstrat #99% of this code comes from the demos in the quantstrat package#now lets define our silly countupdown function CUD 0,1,-1),n) co

5、lnames(temp) 0 stratCUD - add.signal(strategy = stratCUD, name=“sigThreshold“,arguments = list(threshold=-0.5, column=“CUD“,relationship=“gt“, cross=TRUE),label=“CUD.gteq.0“) # exit when CUD 0 stratCUD - add.signal(strategy = stratCUD, name=“sigThreshold“,arguments = list(threshold=-0.5, column=“CUD

6、“,relationship=“lt“,cross=TRUE),label=“CUD.lt.0“) stratCUD - add.rule(strategy = stratCUD, name=ruleSignal, arguments = list(sigcol=“CUD.gteq.0“, sigval=TRUE, orderqty=1000, ordertype=market, orderside=long, pricemethod=market, replace=FALSE), type=enter, path.dep=TRUE) stratCUD - add.rule(strategy

7、= stratCUD, name=ruleSignal, arguments = list(sigcol=“CUD.lt.0“, sigval=TRUE, orderqty=all, ordertype=market, orderside=long, pricemethod=market, replace=FALSE), type=exit, path.dep=TRUE) currency(“USD“) symbol = “GSPC“ stock(symbol, currency=“USD“,multiplier=1) #use paste with to get index data get

8、Symbols(paste(“,symbol,sep=“),adjust=T,from=“1900-12-31“) #I use weekly but comment this out if you want to use daily GSPC-to.weekly(GSPC) initDate=1950-12-31 initEq=100000 port.st-CUD #use a string here for easier changing of parameters and re-trying initPortf(port.st, symbols=symbol, initDate=init

9、Date) initAcct(port.st, portfolios=port.st, initDate=initDate) initOrders(portfolio=port.st, initDate=initDate) print(“setup completed“) # Process the indicators and generate trades start_t-Sys.time() out-try(applyStrategy(strategy=stratCUD , portfolios=port.st ) ) end_t-Sys.time() print(“Strategy L

10、oop:“) print(end_t-start_t) start_t-Sys.time() updatePortf(Portfolio=port.st,Dates=paste(:,as.Date(Sys.time(),sep=) end_t-Sys.time() print(“trade blotter portfolio update:“) print(end_t-start_t) # hack for new quantmod graphics, remove later themelist-chart_theme() themelist$col$up.col-lightgreen themelist$col$dn.col-pink chart.Posn(Portfolio=port.st,Symbol=symbol,theme=themelist,log=TRUE),quantstrat示例,来自http:/www.r- 结合Linux和knitr 自动运行模型并生成报告 甚至可以短信或者邮件通知你 ,20,21,Thank you!,

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > IT计算机/网络 > 数据库

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号