在 R 中导入与管理金融数据
Joshua Ulrich
Quantitative Analyst & quantmod Co-Author and Maintainer
setSymbolLookup(AAPL = "google")
aapl <- getSymbols("AAPL", auto.assign = FALSE)
str(aapl) # 注意 'src' 属性
一个 'xts' 对象,区间 2007-01-03/2017-02-22:
Data: num [1:2552, 1:5] 12.3 12 12.2 12.3 12.3 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:5] "AAPL.Open" "AAPL.High" "AAPL.Low" "AAPL.Close" ...
索引类型: [Date] 时区: UTC
xts 属性:
List of 2
$ src : chr "google"
$ updated: POSIXct[1:1], format: "2017-02-23 14:16:55"
setSymbolLookup(MSFT = list(src = "google", from = "2016-01-01"))
msft <- getSymbols("MSFT", auto.assign = FALSE)
str(msft) # 注意 'src' 属性和首个日期
一个 'xts' 对象,区间 2016-01-04/2017-02-27:
Data: num [1:290, 1:5] 54.3 54.9 54.3 52.7 52.4 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:5] "MSFT.Open" "MSFT.High" "MSFT.Low" "MSFT.Close" ...
索引类型: [Date] 时区: UTC
xts 属性:
List of 2
$ src : chr "google"
$ updated: POSIXct[1:1], format: "2017-02-23 14:20:21"
# 设置默认
setSymbolLookup(AAPL = "google")
# 验证默认已变更
getSymbolLookup()
$AAPL
$AAPL$src
"google"
# 保存查找表
saveSymbolLookup("symbol_lookup.rda")
# 移除查找表
setSymbolLookup(AAPL = NULL)
# 验证默认已移除
getSymbolLookup()
named list()
# 加载查找表
loadSymbolLookup("symbol_lookup.rda")
# 验证默认已恢复
getSymbolLookup()
$AAPL
$AAPL$src
"google"
在 R 中导入与管理金融数据