{"id":198596,"date":"2023-11-03T10:30:00","date_gmt":"2023-11-03T14:30:00","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=198596"},"modified":"2023-11-06T17:11:05","modified_gmt":"2023-11-06T22:11:05","slug":"r-code-snippet-read-historical-prices-of-stock-index","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-snippet-read-historical-prices-of-stock-index\/","title":{"rendered":"R Code Snippet: Read Historical Prices of Stock Index"},"content":{"rendered":"\n<p>This post shows how to read prices of stock indices given symbols as a string.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-read-historical-prices-of-stock-indices\">Read historical prices of stock indices<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"732\" height=\"473\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/graph_stock_index-shlee-ai-financial.png\" alt=\"\" class=\"wp-image-198597 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/graph_stock_index-shlee-ai-financial.png 732w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/graph_stock_index-shlee-ai-financial-700x452.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/graph_stock_index-shlee-ai-financial-300x194.png 300w\" data-sizes=\"(max-width: 732px) 100vw, 732px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 732px; aspect-ratio: 732\/473;\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-center\"><em>Source: I collected the symbols of major stock indices at https:\/\/finance.yahoo.com\/world-indices<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">R code<\/h3>\n\n\n\n<p>The following R code retrieves historical daily prices of selected stock indices given their symbols as of 2022-08-14.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#========================================================#\n# Quantitative ALM, Financial Econometrics &amp; Derivatives \n# ML\/DL using R, Python, Tensorflow by Sang-Heon Lee \n#\n# https:\/\/shleeai.blogspot.com\n#--------------------------------------------------------#\n# read historical prices of stock indices\n#========================================================#\n \ngraphics.off(); rm(list = ls())\n \nlibrary(quantmod)\nlibrary(stringr) # trim\n \n#-------------------------------------------------\n# Symbols of stock indices, as of 2022-08-14\n#-------------------------------------------------\nvstr_symbol &lt;- \"\n    Symbol    ,    Name\n    ^GSPC     ,    S&amp;P 500   \n    ^DJI      ,    Dow 30\n    ^IXIC     ,    Nasdaq\n    ^NYA      ,    NYSE COMPOSITE (DJ)\n    ^XAX      ,    NYSE AMEX COMPOSITE INDEX   \n    ^BUK100P  ,    Cboe UK 100\n    ^RUT      ,    Russell 2000\n    ^VIX      ,    CBOE Volatility Index\n    ^FTSE     ,    FTSE 100\n    ^GDAXI    ,    DAX PERFORMANCE-INDEX\n    ^FCHI     ,    CAC 40\n    ^STOXX50E ,    ESTX 50 PR.EUR\n    ^N100     ,    Euronext 100 Index\n    ^BFX      ,    BEL 20\n    ^N225     ,    Nikkei 225\n    ^HSI      ,    HANG SENG INDEX\n    000001.SS ,    SSE Composite Index\n    399001.SZ ,    Shenzhen Index\n    ^STI      ,    STI Index\n    ^AXJO     ,    S&amp;P\/ASX 200\n    ^AORD     ,    ALL ORDINARIES\n    ^BSESN    ,    S&amp;P BSE SENSEX\n    ^JKSE     ,    Jakarta Composite Index\n    ^KLSE     ,    FTSE Bursa Malaysia KLCI\n    ^NZ50     ,    S&amp;P\/NZX 50 INDEX GROSS\n    ^KS11     ,    KOSPI Composite Index\n    ^TWII     ,    TSEC weighted index\n    ^GSPTSE   ,    S&amp;P\/TSX Composite index\n    ^BVSP     ,    IBOVESPA\n    ^MXX      ,    IPC MEXICO   \n    ^TA125.TA ,    TA-125   \n    ^JN0U.JO  ,    Top 40 USD Net TRI Index\n    \"\n \n#-------------------------------------------\n# split symbols and make vector\n#-------------------------------------------\ndf &lt;- read.table(text = str_trim(vstr_symbol), \n                 sep = \",\", header = TRUE)\ndf &lt;- as.data.frame(df); df\n \ndf$Symbol &lt;- str_trim(gsub(\"[\\t\\r\\n,]\", \"\", df$Symbol))\ndf$Name   &lt;- str_trim(gsub(\"[\\t\\r\\n,]\", \"\", df$Name))\ndf\nnc &lt;- nrow(df) # number of index\n \n#-------------------------------------------\n# read price information\n#-------------------------------------------\nsdate &lt;- as.Date(\"2001-01-01\")\nedate &lt;- as.Date(\"2022-08-12\")\ngetSymbols(df$Symbol, from=sdate, to=edate)\n \n#-------------------------------------------\n# collect only adjusted prices\n#-------------------------------------------\nprice &lt;- NULL\nfor(i in 1:nc) {\n    eval(parse(text=paste0(\n        \"price &lt;- cbind(price,`\",\n        gsub(\"\\\\^\",\"\",df$Symbol[i]),\"`[,6])\")))\n}\n \n# modify column Name as only symbol\ncolnames(price) &lt;- gsub(\".Adjusted\", \"\", \n                        colnames(price))\n \n# convert to data.frame with the first column as Date\ndf.price &lt;- cbind(time=time(price), as.data.frame(price))\nrownames(df.price) &lt;- NULL\n \n# partial selection of complete cases \n# by S&amp;P 500, Nikkei 225, HANG SENG INDEX\ndf.price &lt;- df.price[complete.cases(\n                     df.price[,c(\"GSPC\",\"N225\",\"HSI\")]),]\n \n#-------------------------------------------\n# print time series of daily prices\n#-------------------------------------------\nhead(df.price,3)\ntail(df.price,3)<\/pre>\n\n\n\n<p>Running the above R code displays the status of data reading process as follows.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"682\" height=\"724\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/getSymbols_stock_index-shlee-ai-financial.png\" alt=\"\" class=\"wp-image-198600 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/getSymbols_stock_index-shlee-ai-financial.png 682w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/getSymbols_stock_index-shlee-ai-financial-300x318.png 300w\" data-sizes=\"(max-width: 682px) 100vw, 682px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 682px; aspect-ratio: 682\/724;\" \/><\/figure>\n\n\n\n<p>Finally, we can get the collection of individual stock indices.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"735\" height=\"772\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/price_head_tail_stock_index-shlee-ai-financial.png\" alt=\"\" class=\"wp-image-198601 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/price_head_tail_stock_index-shlee-ai-financial.png 735w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/price_head_tail_stock_index-shlee-ai-financial-700x735.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/11\/price_head_tail_stock_index-shlee-ai-financial-300x315.png 300w\" data-sizes=\"(max-width: 735px) 100vw, 735px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 735px; aspect-ratio: 735\/772;\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><em>Originally posted on <a href=\"https:\/\/shleeai.blogspot.com\/2022\/08\/r-code-snippet-read-historical-prices.html\">SHLee AI Financial Model<\/a> blog.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post shows how to read prices of stock indices given symbols as a string.<\/p>\n","protected":false},"author":662,"featured_media":163630,"comment_status":"open","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,343,338,341,342],"tags":[806,4922,487,6591],"contributors-categories":[13728],"class_list":{"0":"post-198596","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"category-programing-languages","9":"category-ibkr-quant-news","10":"category-quant-development","11":"category-r-development","12":"tag-data-science","13":"tag-econometrics","14":"tag-r","15":"tag-rstats","16":"contributors-categories-sh-fintech-modeling"},"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.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>R Code Snippet: Read Historical Prices of Stock Index<\/title>\n<meta name=\"description\" content=\"This post shows how to read prices of stock indices given symbols as a string.\" \/>\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\/198596\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"R Code Snippet: Read Historical Prices of Stock Index | IBKR Campus US\" \/>\n<meta property=\"og:description\" content=\"This post shows how to read prices of stock indices given symbols as a string.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-snippet-read-historical-prices-of-stock-index\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-03T14:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-06T22:11:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/10\/purple-blue-shiny-quant-matrix.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"563\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sang-Heon Lee\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sang-Heon Lee\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\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\\\/r-code-snippet-read-historical-prices-of-stock-index\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-snippet-read-historical-prices-of-stock-index\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Sang-Heon Lee\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/0a959ff9de7f0465a07baa1fe1ae0200\"\n\t            },\n\t            \"headline\": \"R Code Snippet: Read Historical Prices of Stock Index\",\n\t            \"datePublished\": \"2023-11-03T14:30:00+00:00\",\n\t            \"dateModified\": \"2023-11-06T22:11:05+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-snippet-read-historical-prices-of-stock-index\\\/\"\n\t            },\n\t            \"wordCount\": 98,\n\t            \"commentCount\": 0,\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\\\/r-code-snippet-read-historical-prices-of-stock-index\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/10\\\/purple-blue-shiny-quant-matrix.jpg\",\n\t            \"keywords\": [\n\t                \"Data Science\",\n\t                \"Econometrics\",\n\t                \"R\",\n\t                \"rstats\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Quant\",\n\t                \"Quant Development\",\n\t                \"R Development\"\n\t            ],\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"CommentAction\",\n\t                    \"name\": \"Comment\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-snippet-read-historical-prices-of-stock-index\\\/#respond\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-snippet-read-historical-prices-of-stock-index\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-snippet-read-historical-prices-of-stock-index\\\/\",\n\t            \"name\": \"R Code Snippet: Read Historical Prices of Stock Index | IBKR Campus US\",\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\\\/r-code-snippet-read-historical-prices-of-stock-index\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-snippet-read-historical-prices-of-stock-index\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/10\\\/purple-blue-shiny-quant-matrix.jpg\",\n\t            \"datePublished\": \"2023-11-03T14:30:00+00:00\",\n\t            \"dateModified\": \"2023-11-06T22:11:05+00:00\",\n\t            \"description\": \"This post shows how to read prices of stock indices given symbols as a string.\",\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\\\/r-code-snippet-read-historical-prices-of-stock-index\\\/\"\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\\\/r-code-snippet-read-historical-prices-of-stock-index\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/10\\\/purple-blue-shiny-quant-matrix.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/10\\\/purple-blue-shiny-quant-matrix.jpg\",\n\t            \"width\": 1000,\n\t            \"height\": 563,\n\t            \"caption\": \"Quant\"\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\\\/0a959ff9de7f0465a07baa1fe1ae0200\",\n\t            \"name\": \"Sang-Heon Lee\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/sang-heonlee\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"R Code Snippet: Read Historical Prices of Stock Index","description":"This post shows how to read prices of stock indices given symbols as a string.","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\/198596\/","og_locale":"en_US","og_type":"article","og_title":"R Code Snippet: Read Historical Prices of Stock Index | IBKR Campus US","og_description":"This post shows how to read prices of stock indices given symbols as a string.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-snippet-read-historical-prices-of-stock-index\/","og_site_name":"IBKR Campus US","article_published_time":"2023-11-03T14:30:00+00:00","article_modified_time":"2023-11-06T22:11:05+00:00","og_image":[{"width":1000,"height":563,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/10\/purple-blue-shiny-quant-matrix.jpg","type":"image\/jpeg"}],"author":"Sang-Heon Lee","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Sang-Heon Lee","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-snippet-read-historical-prices-of-stock-index\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-snippet-read-historical-prices-of-stock-index\/"},"author":{"name":"Sang-Heon Lee","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/0a959ff9de7f0465a07baa1fe1ae0200"},"headline":"R Code Snippet: Read Historical Prices of Stock Index","datePublished":"2023-11-03T14:30:00+00:00","dateModified":"2023-11-06T22:11:05+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-snippet-read-historical-prices-of-stock-index\/"},"wordCount":98,"commentCount":0,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-snippet-read-historical-prices-of-stock-index\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/10\/purple-blue-shiny-quant-matrix.jpg","keywords":["Data Science","Econometrics","R","rstats"],"articleSection":["Data Science","Programming Languages","Quant","Quant Development","R Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-snippet-read-historical-prices-of-stock-index\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-snippet-read-historical-prices-of-stock-index\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-snippet-read-historical-prices-of-stock-index\/","name":"R Code Snippet: Read Historical Prices of Stock Index | IBKR Campus US","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-snippet-read-historical-prices-of-stock-index\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-snippet-read-historical-prices-of-stock-index\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/10\/purple-blue-shiny-quant-matrix.jpg","datePublished":"2023-11-03T14:30:00+00:00","dateModified":"2023-11-06T22:11:05+00:00","description":"This post shows how to read prices of stock indices given symbols as a string.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-snippet-read-historical-prices-of-stock-index\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-snippet-read-historical-prices-of-stock-index\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/10\/purple-blue-shiny-quant-matrix.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/10\/purple-blue-shiny-quant-matrix.jpg","width":1000,"height":563,"caption":"Quant"},{"@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\/0a959ff9de7f0465a07baa1fe1ae0200","name":"Sang-Heon Lee","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/sang-heonlee\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/10\/purple-blue-shiny-quant-matrix.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/198596","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\/662"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=198596"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/198596\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/163630"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=198596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=198596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=198596"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=198596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}