# Load packages
library(tidyquant)
library(tidyverse) # for count() function
# Import S&P500 Stock Index
SP500 <- tq_index("SP500")
SP500
## # A tibble: 505 x 8
## symbol company identifier sedol weight sector shares_held local_currency
## <chr> <chr> <chr> <chr> <dbl> <chr> <dbl> <chr>
## 1 AAPL Apple Inc. 03783310 20462… 0.0651 Inform… 162992320 USD
## 2 MSFT Microsoft… 59491810 25881… 0.0557 Inform… 77107060 USD
## 3 AMZN Amazon.co… 02313510 20000… 0.0421 Consum… 4349600 USD
## 4 FB Facebook … 30303M10 B7TL8… 0.0196 Commun… 24517350 USD
## 5 GOOGL Alphabet … 02079K30 BYVY8… 0.0190 Commun… 3066174 USD
## 6 TSLA Tesla Inc 88160R10 B616C… 0.0186 Consum… 7733841 USD
## 7 GOOG Alphabet … 02079K10 BYY88… 0.0184 Commun… 2960512 USD
## 8 BRK.B Berkshire… 08467070 20733… 0.0142 Financ… 19847860 USD
## 9 JNJ Johnson &… 47816010 24758… 0.0132 Health… 26848432 USD
## 10 JPM JPMorgan … 46625H10 21903… 0.0130 Financ… 31087676 USD
## # … with 495 more rows
There are 505 rows in the data set.
There are 8 columns in the data set.
505 companies are listed in S&P500 index.
Hint: Use the weight column of the data.
Apple, Microsoft, and Amazon have the greatest influence on ups and downs in S&P500 index.
Hint: Use the sector column of the data.
Health Care, Financials, Communication Services, and Information Technology are sectors represented in S&P500 index.
Hint: Use the symbol column of the data.
NFLX is the symbol for Netflix.
Hint: Insert a R code chunk below, type the following code: count(SP500, sector, sort = T)
count(SP500, sector, sort = T)
## # A tibble: 11 x 2
## sector n
## <chr> <int>
## 1 Information Technology 76
## 2 Industrials 73
## 3 Financials 65
## 4 Health Care 63
## 5 Consumer Discretionary 61
## 6 Consumer Staples 32
## 7 Real Estate 30
## 8 Materials 28
## 9 Utilities 28
## 10 Communication Services 26
## 11 Energy 23
Information Technology sector has the largest number of companies.
Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.