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

Quantmod包chartSeries函数对部分标的失效问题咨询

Hey there! Let's break down what's going on with your quantmod charting issues and fix them one by one:

1. Why those errors are popping up
  • The first error Error in inherits(x, "xts") : object 'BTC' not found happens because you tried to call chartSeries(BTC) without first fetching the BTC data and creating that BTC object in your environment.
  • The second error chartSeries requires an xtsible object is because you passed a string ("BTC-EUR") directly to chartSeries—this function needs an xts/zoo object (time-series data), not just a symbol name.
  • The CAC index issue is likely the same root cause: wrong symbol or missing data fetch step.
2. Step-by-step fixes for each asset

Bitcoin (BTC-EUR)

You need to first pull the BTC-EUR data from Yahoo Finance, then pass the resulting xts object to chartSeries:

  1. Fetch the data with getSymbols (this is how quantmod pulls financial data by default from Yahoo):
    # This will create an object named BTC.EUR (hyphens get converted to dots) in your environment
    getSymbols("BTC-EUR", src = "yahoo")
    
  2. Now you can plot it with chartSeries:
    chartSeries(BTC.EUR)
    
    Alternatively, if you want to use BTC as your object name explicitly, use auto.assign = FALSE to assign the data to your own variable:
    BTC <- getSymbols("BTC-EUR", src = "yahoo", auto.assign = FALSE)
    chartSeries(BTC)
    

French CAC Index

The correct Yahoo Finance symbol for the CAC 40 is FCHI. Follow the same pattern:

  1. Fetch the data:
    getSymbols("FCHI", src = "yahoo")
    
  2. Plot it:
    chartSeries(FCHI)
    
3. Quick pro tips to avoid this in the future
  • Always verify the correct Yahoo Finance symbol for non-US assets/exponents—you can look these up directly on Yahoo Finance's website if you're unsure.
  • Use class() to check if your data is in the right format:
    class(BTC.EUR) # Should return "xts" "zoo" if everything worked
    
  • If getSymbols fails to fetch data, double-check the symbol and consider specifying the src parameter (though Yahoo is the default, some assets might require other sources, note that Google Finance support is limited now).

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 08:52:30