【发布时间】:2021-07-06 19:48:55
【问题描述】:
我正在尝试从“Reproducible Finance with R”一书中复制代码。除了以下部分,一切都很好。
asset_returns_tbltime <-
prices %>%
tk_tbl(preserve_index = TRUE,
rename_index = "date") %>%
as_tbl_time(index = date) %>%
as_period(period = "month",
side = "end") %>%
gather(asset, returns, -date) %>%
group_by(asset) %>%
tq_transmute(mutate_fun = periodReturn,
type = "log") %>%
spread(asset, monthly.returns) %>%
select(date, symbols)
这在字符串之后给了我以下错误
tq_transmute(mutate_fun = periodReturn, type = "log"):
Error: Can't subset columns that don't exist. Column "asset" doesn't exist. Run rlang::last_error() to see where the error occurred. In addition: Warning message: "..." must not be empty for ungrouped data frames. Did you want data = everything()?
数据来源于以下代码:
symbols <- c("SPY","EFA", "IJS", "EEM","AGG")
prices <-
getSymbols(symbols,
src = 'yahoo',
from = "2012-12-31",
auto.assign = TRUE,
warnings = FALSE) %>%
map(~Ad(get(.))) %>%
reduce(merge) %>%
`colnames<-`(symbols)
如果有人能将我的注意力指向代码(或其他东西)的问题,那就太好了,因为我认为我已经迷路了。
【问题讨论】:
标签: r tibbletime