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 foundhappens because you tried to callchartSeries(BTC)without first fetching the BTC data and creating thatBTCobject in your environment. - The second error
chartSeries requires an xtsible objectis because you passed a string ("BTC-EUR") directly tochartSeries—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:
- 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") - Now you can plot it with
chartSeries:
Alternatively, if you want to usechartSeries(BTC.EUR)BTCas your object name explicitly, useauto.assign = FALSEto 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:
- Fetch the data:
getSymbols("FCHI", src = "yahoo") - 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
getSymbolsfails to fetch data, double-check the symbol and consider specifying thesrcparameter (though Yahoo is the default, some assets might require other sources, note that Google Finance support is limited now).
内容的提问来源于stack exchange,提问作者responsibleHedger
相关产品推荐
相关产品推荐

