使用Quantmod下载FRED数据:是否可以指定日期? [英] Downloading FRED data with quantmod: can dates be specified?

查看:153
本文介绍了使用Quantmod下载FRED数据:是否可以指定日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用quantmod库(作者Jeffrey A. Ryan)从FRED下载数据.使用 Yahoo Google 数据,我可以设置开始和结束日期.是否可以对 FRED 数据执行相同的操作?

I am downloading data from FRED with the quantmod library (author Jeffrey A. Ryan). With Yahoo and Google data, I am able to set start and end dates. Can the same be done for FRED data?

帮助页面没有将"from"和"to"列出为quantmod的getSymbols函数的选项,据我推断,当前不可能.

The help page does not list "from" and "to" as options of quantmod's getSymbols function, from which I'm inferring that it is not currently possible.

是否可以为要下载的数据设置范围,还是需要下载整个数据集并丢弃不需要的数据?

Is there a way to set a range for the data to be downloaded or do I need to download the entire dataset and discard the data I don't need?

感谢您的帮助.在说明上下文的代码下面:

Thanks for your help. Below the code that illustrates the context:

从FRED下载时,日期将被忽略:

The dates are ignored when downloading from FRED:

# environment in which to store data 
data <- new.env()

# set dates
date.start <- "2000-01-01"
date.end <- "2012-12-31"

# set tickers
tickers <- c("FEDFUNDS", "GDPPOT", "DGS10")

# import data from FRED database
library("quantmod")
getSymbols( tickers
  , src = "FRED"  # needed!
  , from = date.start  # ignored
  , to = date.end  # ignored
  , env = data
  , adjust = TRUE
)

head(data$FEDFUNDS)

head(data$FEDFUNDS)
           FEDFUNDS
1954-07-01     0.80
1954-08-01     1.22
1954-09-01     1.06
1954-10-01     0.85
1954-11-01     0.83
1954-12-01     1.28

解决方案

由于下面的 GSee 的建议,我正在使用以下代码将数据子集到上述指定的日期范围内:

Thanks to GSee's suggestion below, I am using the following code to subset the data to within the range of dates specified above:

# subset data to within time range
  dtx <- data$FEDFUNDS
  dtx[paste(date.start,date.end,sep="/")]

在这里,我先从环境中提取xts数据,然后再对其进行操作.我的后续问题探讨了替代方案.

Here I extracted the xts data from the environment before acting upon it. My follow-up question explores alternatives.

后续问题

我在那里问了一些后续问题:从内部获取xts对象环境

I have asked some follow-up questions there: get xts objects from within an environment

推荐答案

您必须稍后下载所有数据和子集. getSymbols.FRED不像getSymbols.yahoo那样支持from参数.

You have to download all the data and subset later. getSymbols.FRED does not support the from argument like getSymbols.yahoo does.

这篇关于使用Quantmod下载FRED数据:是否可以指定日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆