Search code examples
rquantmod

How to get Indian Stock market Index data in r?


I was trying to get BSE SENSEX data in R and came across this Import Indian stock prices into R which is useful but I am not able to get SENSEX Index data using getSymbols from quantmod.

I have tried many options but none of them worked

quantmod::getSymbols("SENSEX", src="yahoo")

quantmod::getSymbols("SENSEX.BO", src="yahoo")

quantmod::getSymbols("BSE SENSEX", src="yahoo")

quantmod::getSymbols("BSE SENSEX.BO", src="yahoo")

About Sensex:

SENSEX


Solution

  • Packages tidyquant andQuantmod uses Yahoo Finance. Therefore, check what the security is called on their website, hence: ^BSESN

    library(tidyquant)
    
    tq_get("^BSESN") 
    
    # A tibble: 2,643 × 8
       symbol date         open   high    low  close volume adjusted
       <chr>  <date>      <dbl>  <dbl>  <dbl>  <dbl>  <dbl>    <dbl>
     1 ^BSESN 2012-01-03 15641. 15970. 15641. 15939.  16200   15939.
     2 ^BSESN 2012-01-04 15967. 16005. 15822. 15883.  17800   15883.
     3 ^BSESN 2012-01-05 15893. 15980. 15809. 15857.  21200   15857.
     4 ^BSESN 2012-01-06 15789. 16001. 15665. 15868.  17200   15868.
     5 ^BSESN 2012-01-07    NA     NA     NA     NA      NA      NA 
     6 ^BSESN 2012-01-09 15840. 15872. 15678. 15815.  11200   15815.
     7 ^BSESN 2012-01-10 15898. 16181. 15898. 16165.  19600   16165.
     8 ^BSESN 2012-01-11 16222. 16245. 16128. 16176.  18600   16176.
     9 ^BSESN 2012-01-12 16117. 16179. 15963. 16038.  14400   16038.
    10 ^BSESN 2012-01-13 16145. 16257. 16050. 16155.  19600   16155.
    # … with 2,633 more rows
    # ℹ Use `print(n = ...)` to see more rows