Quantmod包getFX函数HTTP 404报错求助及外汇数据下载替代方案咨询
解决quantmod包getFX函数HTTP 404错误及外汇数据替代方案
Hey there, lots of R users have run into this exact issue with quantmod's getFX() function lately! The problem comes down to Oanda—one of quantmod's primary data sources for forex rates—adjusting their API endpoints, which left the current CRAN version of quantmod unable to connect properly, hence the HTTP 404 error.
官方修复方案
Good news: the quantmod developers have already pushed a fix in a dedicated branch. Here's how to install it:
- First, make sure you have the
curlpackage installed (it's a dependency for the fix):
install.packages("curl")
- If you don't have
devtoolsinstalled yet, grab that first, then install the patched version of quantmod from GitHub:
install.packages("devtools") library(devtools) devtools::install_github("joshuaulrich/quantmod", ref="225_getsymbols_oanda")
After installing, restart your R session, and getFX("USD/JPY") should work like it did before.
替代外汇数据获取方案
If you'd rather not mess with development versions right now, here are some reliable alternatives to pull forex data in R:
- tidyquant: This package wraps multiple financial data sources (including Oanda and Yahoo Finance) in a tidyverse-friendly way. Getting USD/JPY rates is straightforward:
library(tidyquant) usd_jpy <- tq_get("USD/JPY", get = "exchange.rates")
- forexconnect: Built specifically for forex data, it supports connections to several major brokers' data feeds—great if you need more professional-grade forex data.
- Quandl: Quandl offers a wide range of financial datasets, including forex rates. You'll need a free API key (sign up on their site) to access the data:
library(Quandl) Quandl.api_key("your-api-key-here") usd_jpy <- Quandl("CURRFX/USDJPY")
- Manual Yahoo Finance API calls: You can use packages like
httrorjsonliteto directly query Yahoo's public forex endpoints. Just keep in mind that these unofficial APIs can change without warning.
内容的提问来源于stack exchange,提问作者sen_saven
相关产品推荐
相关产品推荐

