Downloading S&P 500 Sector Data and Distinguishing Select Sector ETFs
Summary
The document discusses downloading S&P 500 data and sector series with R’s quantmod package, then asks why a Yahoo Finance symbol for a healthcare subsector index does not work. Responses suggest the issue may be Yahoo’s symbol coverage or historical data availability, and point out that the example sector tickers are exchange-traded funds rather than the S&P 500’s sector indexes.
The distinction matters for research: Select Sector ETFs follow indexes with composition rules that can differ from the corresponding S&P 500 sector indexes. The technology ETF, for example, includes telecommunications alongside information technology, so its holdings may not match either sector index. Another response identifies a separate implementation issue: assigning downloaded data to a named R environment requires creating that environment first, or omitting the environment argument. The thread offers troubleshooting suggestions, not a verified resolution for the specific subsector symbol, and Yahoo’s availability may vary by symbol and date.
Key ideas
- Yahoo Finance may not provide data for every index symbol or historical period.
- Select Sector ETFs are not identical to S&P 500 sector indexes.
- ETF composition rules can produce different constituents from the corresponding sector indexes.
- In quantmod, a named destination environment must exist before it is passed to getSymbols.
Tags
Full text
# Getting data of sub-sector indexes of an S&P 500 index sector using QuantMod in R
# Getting data of sub-sector indexes of an S&P 500 index sector using QuantMod in R
Using the quantmod package in R, one can download the S&P500 index using the following command:
`getSymbols("^GSPC", env = sp500, src = "yahoo",from = as.Date("1960-01-04"), to = as.Date("2009-01-01"))`
The S&P is further broken down in sectors (with their yahoo symbols in brackets): Health care (XLV), industrials (XLI), consumer staples (XLP), consumer discretionary (XLY), materials (XLB), utilities (XLU), financials (XLF or XLFS), energy (XLE), technology (XLK), and Real Estate (XLRE).
These sectors are further broken down in subsectors, but I do not know how to get these indexes. For example, Healtcare is has Managed care, Pharmaceuticals, equipment, as subsectors. For example,
http://finance.yahoo.com/quote/%5ESP500-3510?p=%5ESP500-3510
is a subsector of the Health care index, but using the symbol given there (^SP500-3510) does not seem to work in the above `getSymbol` R command. Any suggestion on how to get this index?
## Answer by Richard at NorgateData (score 2)
https://quant.stackexchange.com/a/30092
This is a Yahoo data issue - you should contact them regarding their symbols and availability of data. It might just be that the index is not covered by them or they are restricted from providing historical data.
Also note that you have referenced ETFs (XLV, XLI, etc.) that trade on NYSE Arca as being sector-based subsets of the S&P 500. These ETFs are based upon the Select Sector indexes. The "Select" indexes are a little different from the actual S&P 500 sector indexes in that they have more rules associated with index composition (to minimize churn) and also include other GICS classifications.
For example, XLK (Technology Select Sector SPDR ETF) is not a GICS sector - it comprises both Information Technology and Telecommunications companies. From time-to-time it has a different set of components comapred to the S&P 500 Information Technology Sector Index and the S&P 500 Telecommunications Sector Index.
Reference: https://us.spindices.com/documents/methodologies/methodology-sp-us-indices.pdf
## Answer by Brian O'Donnell (score 1)
https://quant.stackexchange.com/a/29587
There is something wrong with the web page for that index. I tried viewing historical data and there was none. The link to download historical data is also broken. I suggest testing another index.
## Answer by Harini (score 1)
https://quant.stackexchange.com/a/59564
Alternatively you could check this link:
https://finance.yahoo.com/quote/%5EGSPC/history?period1=1479945600&period2=1606176000&interval=1d&filter=history&frequency=1d&includeAdjustedClose=true
Also this code worked for me. Directly loading data using getSymbols.
```
getSymbols("^GSPC", src = "yahoo", from = as.Date("2019-05-20"),
to = as.Date("2020-05-20"), periodicity = "daily")
```
Let me know if this works.
## Answer by Siamak Farjami (score 1)
https://quant.stackexchange.com/a/59568
```
getSymbols("^GSPC", env = sp500, src = "yahoo",from = as.Date("1960-01-04"), to = as.Date("2009-01-01"))
```
this code not gonna work until you create a new environment which you used, sp500. you need to create this new environment using `sp500 = new.env()`.
or you can not creat it but you need to change your code to
```
getSymbols("^GSPC", src = "yahoo",from = as.Date("1960-01-04"), to = as.Date("2009-01-01"))
```Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.