You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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:

  1. First, make sure you have the curl package installed (it's a dependency for the fix):
install.packages("curl")
  1. If you don't have devtools installed 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 httr or jsonlite to directly query Yahoo's public forex endpoints. Just keep in mind that these unofficial APIs can change without warning.

内容的提问来源于stack exchange,提问作者sen_saven

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:19:11