{"id":45021,"date":"2020-05-13T12:31:43","date_gmt":"2020-05-13T16:31:43","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=45021"},"modified":"2022-11-21T09:45:30","modified_gmt":"2022-11-21T14:45:30","slug":"how-to-get-historical-sp-500-constituents-data-for-free","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-historical-sp-500-constituents-data-for-free\/","title":{"rendered":"How To Get Historical S&#038;P 500 Constituents Data For Free"},"content":{"rendered":"\n<p><strong><em>Excerpt<\/em><\/strong><\/p>\n\n\n\n<p><strong>Getting Current S&amp;P 500 Constituents for Free<\/strong><\/p>\n\n\n\n<p>Wikipedia publishes current S&amp;P 500 component stocks&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_S%26P_500_companies\">here.<\/a><\/p>\n\n\n\n<p>If we use the chrome inspector we can see that the S&amp;P 500 stock constituents are in an HTML table with id&nbsp;<code>#constituents<\/code><\/p>\n\n\n\n<p>So let\u2019s use the&nbsp;<code>rvest<\/code>&nbsp;R package to scrape that data into a data frame.<\/p>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\n# Load dependencies<br>\nif (!require(&#8220;pacman&#8221;)) install.packages(&#8220;pacman&#8221;)<br>\npacman::p_load(tidyverse, rvest)<br>\nwikispx <- read_html('https:\/\/en.wikipedia.org\/wiki\/List_of_S%26P_500_companies')<br>\ncurrentconstituents <- wikispx %>%<br>\n  html_node(&#8216;#constituents&#8217;) %>%<br>\n  html_table(header = TRUE)<br>\ncurrentconstituents\n<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1100\" height=\"236\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/current-spx500-constituents-free-1100x236.png\" alt=\"How To Get Historical S&amp;P 500 Constituents Data For Free\" class=\"wp-image-45055 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/current-spx500-constituents-free-1100x236.png 1100w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/current-spx500-constituents-free-700x150.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/current-spx500-constituents-free-300x64.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/current-spx500-constituents-free-768x165.png 768w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/current-spx500-constituents-free.png 1108w\" data-sizes=\"(max-width: 1100px) 100vw, 1100px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1100px; aspect-ratio: 1100\/236;\" \/><\/figure>\n\n\n\n<p><strong>Getting S&amp;P 500 Changes for Free<\/strong><\/p>\n\n\n\n<p>Wikipedia also publishes \u201cSelected Changes to the list of S&amp;P 500 components\u201d on the same page.<\/p>\n\n\n\n<p>This lists stocks that have been added or removed from the index as a result of acquisitions, or as the companies grow and shrink in market capitalisation.<\/p>\n\n\n\n<p>I\u2019ve checked this against our data set and it\u2019s relatively accurate and complete up to about the year 2000. It gets less complete and accurate before then.<\/p>\n\n\n\n<p>But we don\u2019t need&nbsp;<em>perfection<\/em>&nbsp;here\u2026 so let\u2019s scrape these changes.<\/p>\n\n\n\n<p>The Chrome Inspector shows us they live in a table with id&nbsp;<code>#changes<\/code>.<\/p>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\nspxchanges <- wikispx %>%<br>\n  html_node(&#8216;#changes&#8217;) %>%<br>\n  html_table(header = FALSE, fill = TRUE) %>%<br>\n  filter(row_number() > 2) %>% # First two rows are headers<br>\n  `colnames<-`(c('Date','AddTicker','AddName','RemovedTicker','RemovedName','Reason')) %>%<br>\n  mutate(Date = as.Date(Date, format = &#8216;%B %d, %Y&#8217;),<br>\n         year = year(Date),<br>\n         month = month(Date))<br>\nspxchanges\n<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1100\" height=\"244\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/sandp500-changes-free-1100x244.png\" alt=\"\" class=\"wp-image-45061 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/sandp500-changes-free-1100x244.png 1100w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/sandp500-changes-free-700x155.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/sandp500-changes-free-300x66.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/sandp500-changes-free-768x170.png 768w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/sandp500-changes-free.png 1111w\" data-sizes=\"(max-width: 1100px) 100vw, 1100px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1100px; aspect-ratio: 1100\/244;\" \/><\/figure>\n\n\n\n<p><strong>Create Monthly Snapshot of S&amp;P 500 Index Constituents<\/strong><\/p>\n\n\n\n<p>Now we\u2019re going to use this data to create monthly snapshots of what the SPX index used to look like.<\/p>\n\n\n\n<p>To do this we:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>start at the current S&amp;P 500 index constituents<\/li><li>iterate backwards a month at a time and:<ul><li>add back the stocks that were removed<\/li><li>remove the stocks that were added<\/li><\/ul><\/li><\/ul>\n\n\n\n<p><em>If that sounds back to front, it\u2019s because we are working backwards in time through the data!<\/em><\/p>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\n# Start at the current constituents&#8230;<br>\ncurrentmonth <- as.Date(format(Sys.Date(), '%Y-%m-01'))<br>\nmonthseq <- seq.Date(as.Date('1990-01-01'), currentmonth, by = 'month') %>% rev()<br><br>\n\nspxstocks <- currentconstituents %>% mutate(Date = currentmonth) %>% select(Date, Ticker = Symbol, Name = Security)<br>\nlastrunstocks <- spxstocks<br><br>\n\n# Iterate through months, working backwards<br>\nfor (i in 2:length(monthseq)) {<br>\n  d <- monthseq[i]<br>\n  y <- year(d)<br>\n  m <- month(d)<br>\n  changes <- spxchanges %>% <br>\n    filter(year == year(d), month == month(d)) <br><br>\n\n  # Remove added tickers (we&#8217;re working backwards in time, remember)<br>\n  tickerstokeep <- lastrunstocks %>% <br>\n    anti_join(changes, by = c(&#8216;Ticker&#8217; = &#8216;AddTicker&#8217;)) %>%<br>\n    mutate(Date = d)<br><br>\n  \n  # Add back the removed tickers&#8230;<br>\n  tickerstoadd <- changes %>%<br>\n    filter(!RemovedTicker == &#8221;) %>%<br>\n        transmute(Date = d,<br>\n                  Ticker = RemovedTicker,<br>\n                  Name = RemovedName)<br><br>\n  \n  thismonth <- tickerstokeep %>% bind_rows(tickerstoadd)<br>\n  spxstocks <- spxstocks %>% bind_rows(thismonth)  <br><br>\n  \n  lastrunstocks <- thismonth<br>\n}<br>\nspxstocks\n<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1100\" height=\"232\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/spx-constituent-snapshots-1100x232.png\" alt=\"\" class=\"wp-image-45056 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/spx-constituent-snapshots-1100x232.png 1100w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/spx-constituent-snapshots-700x148.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/spx-constituent-snapshots-300x63.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/spx-constituent-snapshots-768x162.png 768w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/spx-constituent-snapshots.png 1112w\" data-sizes=\"(max-width: 1100px) 100vw, 1100px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1100px; aspect-ratio: 1100\/232;\" \/><\/figure>\n\n\n\n<p>Visit RobotWealth to read the full article and download the code:<br><a href=\"https:\/\/robotwealth.com\/how-to-get-historical-spx-constituents-data-for-free\/\">https:\/\/robotwealth.com\/how-to-get-historical-spx-constituents-data-for-free\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Getting Current S&#038;P 500 Constituents for Free. Wikipedia publishes current S&#038;P 500 component stocks here. If we use the chrome inspector we can see that the S&#038;P 500 stock constituents are in an HTML table with id #constituents. So let\u2019s use the rvest R package to scrape that data into a data frame<\/p>\n","protected":false},"author":421,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,343,338,350,341,342],"tags":[851,7560,4922,4941,5110,7559,487,910],"contributors-categories":[13676],"class_list":{"0":"post-45021","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-data-science","7":"category-programing-languages","8":"category-ibkr-quant-news","9":"category-quant-asia-pacific","10":"category-quant-development","11":"category-r-development","12":"tag-algo-trading","13":"tag-data-visualization","14":"tag-econometrics","15":"tag-financial-mathematics","16":"tag-historical-data","17":"tag-portfolio-optmization","18":"tag-r","19":"tag-sp-500","20":"contributors-categories-robot-wealth"},"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.5) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How To Get Historical S&#038;P 500 Constituents Data For Free<\/title>\n<meta name=\"description\" content=\"Robot Wealth codes in R and explains How To Get Historical S&amp;P 500 Constituents Data For Free. So let\u2019s use the rvest R package to scrape that data...\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/45021\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Get Historical S&amp;P 500 Constituents Data For Free | via IBKR Quant Blog\" \/>\n<meta property=\"og:description\" content=\"Robot Wealth codes in R and explains How To Get Historical S&amp;P 500 Constituents Data For Free. So let\u2019s use the rvest R package to scrape that data into a data frame\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-historical-sp-500-constituents-data-for-free\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-13T16:31:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-21T14:45:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.ibkrcampusdev.wpengine.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/current-spx500-constituents-free-1100x236.png\" \/>\n<meta name=\"author\" content=\"Robot James\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Robot James\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-historical-sp-500-constituents-data-for-free\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-historical-sp-500-constituents-data-for-free\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Robot James\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/0fcf297a219d9485e2efa476d632b468\"\n\t            },\n\t            \"headline\": \"How To Get Historical S&#038;P 500 Constituents Data For Free\",\n\t            \"datePublished\": \"2020-05-13T16:31:43+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:45:30+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-historical-sp-500-constituents-data-for-free\\\/\"\n\t            },\n\t            \"wordCount\": 326,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-historical-sp-500-constituents-data-for-free\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.ibkrcampusdev.wpengine.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/05\\\/current-spx500-constituents-free-1100x236.png\",\n\t            \"keywords\": [\n\t                \"Algo Trading\",\n\t                \"Data Visualization\",\n\t                \"Econometrics\",\n\t                \"Financial Mathematics\",\n\t                \"historical data\",\n\t                \"Portfolio Optmization\",\n\t                \"R\",\n\t                \"S&amp;P 500\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Quant\",\n\t                \"Quant Asia Pacific\",\n\t                \"Quant Development\",\n\t                \"R Development\"\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-historical-sp-500-constituents-data-for-free\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-historical-sp-500-constituents-data-for-free\\\/\",\n\t            \"name\": \"How To Get Historical S&P 500 Constituents Data For Free | via IBKR Quant Blog\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-historical-sp-500-constituents-data-for-free\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-historical-sp-500-constituents-data-for-free\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.ibkrcampusdev.wpengine.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/05\\\/current-spx500-constituents-free-1100x236.png\",\n\t            \"datePublished\": \"2020-05-13T16:31:43+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:45:30+00:00\",\n\t            \"description\": \"Robot Wealth codes in R and explains How To Get Historical S&P 500 Constituents Data For Free. So let\u2019s use the rvest R package to scrape that data into a data frame\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-historical-sp-500-constituents-data-for-free\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-get-historical-sp-500-constituents-data-for-free\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.ibkrcampusdev.wpengine.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/05\\\/current-spx500-constituents-free-1100x236.png\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.ibkrcampusdev.wpengine.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/05\\\/current-spx500-constituents-free-1100x236.png\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/0fcf297a219d9485e2efa476d632b468\",\n\t            \"name\": \"Robot James\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/robotjames\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How To Get Historical S&#038;P 500 Constituents Data For Free","description":"Robot Wealth codes in R and explains How To Get Historical S&P 500 Constituents Data For Free. So let\u2019s use the rvest R package to scrape that data...","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/45021\/","og_locale":"en_US","og_type":"article","og_title":"How To Get Historical S&P 500 Constituents Data For Free | via IBKR Quant Blog","og_description":"Robot Wealth codes in R and explains How To Get Historical S&P 500 Constituents Data For Free. So let\u2019s use the rvest R package to scrape that data into a data frame","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-historical-sp-500-constituents-data-for-free\/","og_site_name":"IBKR Campus US","article_published_time":"2020-05-13T16:31:43+00:00","article_modified_time":"2022-11-21T14:45:30+00:00","og_image":[{"url":"https:\/\/www.ibkrcampusdev.wpengine.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/current-spx500-constituents-free-1100x236.png","type":"","width":"","height":""}],"author":"Robot James","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Robot James","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-historical-sp-500-constituents-data-for-free\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-historical-sp-500-constituents-data-for-free\/"},"author":{"name":"Robot James","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/0fcf297a219d9485e2efa476d632b468"},"headline":"How To Get Historical S&#038;P 500 Constituents Data For Free","datePublished":"2020-05-13T16:31:43+00:00","dateModified":"2022-11-21T14:45:30+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-historical-sp-500-constituents-data-for-free\/"},"wordCount":326,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-historical-sp-500-constituents-data-for-free\/#primaryimage"},"thumbnailUrl":"https:\/\/www.ibkrcampusdev.wpengine.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/current-spx500-constituents-free-1100x236.png","keywords":["Algo Trading","Data Visualization","Econometrics","Financial Mathematics","historical data","Portfolio Optmization","R","S&amp;P 500"],"articleSection":["Data Science","Programming Languages","Quant","Quant Asia Pacific","Quant Development","R Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-historical-sp-500-constituents-data-for-free\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-historical-sp-500-constituents-data-for-free\/","name":"How To Get Historical S&P 500 Constituents Data For Free | via IBKR Quant Blog","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-historical-sp-500-constituents-data-for-free\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-historical-sp-500-constituents-data-for-free\/#primaryimage"},"thumbnailUrl":"https:\/\/www.ibkrcampusdev.wpengine.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/current-spx500-constituents-free-1100x236.png","datePublished":"2020-05-13T16:31:43+00:00","dateModified":"2022-11-21T14:45:30+00:00","description":"Robot Wealth codes in R and explains How To Get Historical S&P 500 Constituents Data For Free. So let\u2019s use the rvest R package to scrape that data into a data frame","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-historical-sp-500-constituents-data-for-free\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-get-historical-sp-500-constituents-data-for-free\/#primaryimage","url":"https:\/\/www.ibkrcampusdev.wpengine.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/current-spx500-constituents-free-1100x236.png","contentUrl":"https:\/\/www.ibkrcampusdev.wpengine.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/05\/current-spx500-constituents-free-1100x236.png"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/0fcf297a219d9485e2efa476d632b468","name":"Robot James","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/robotjames\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/45021","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/421"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=45021"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/45021\/revisions"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=45021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=45021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=45021"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=45021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}