4
$\begingroup$

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?

$\endgroup$

4 Answers 4

2
$\begingroup$

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

$\endgroup$
1
$\begingroup$

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.

$\endgroup$
1
$\begingroup$
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"))
$\endgroup$
1
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.