0% found this document useful (0 votes)
89 views7 pages

Library

The document shows the use of the quantmod package in R to download stock price data for various companies traded on Indian stock exchanges from Yahoo Finance. Some stock symbols could not be downloaded due to HTTP errors or being invalid, and many of the downloaded stock prices contained missing values. The code retrieves price data and issues warnings for 29 stock symbols.

Uploaded by

sandeep e
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views7 pages

Library

The document shows the use of the quantmod package in R to download stock price data for various companies traded on Indian stock exchanges from Yahoo Finance. Some stock symbols could not be downloaded due to HTTP errors or being invalid, and many of the downloaded stock prices contained missing values. The code retrieves price data and issues warnings for 29 stock symbols.

Uploaded by

sandeep e
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

> library("quantmod")

>
getSymbols("HOCL.NS;IRCON.NS;ONGC.NS;FACT.NS;NFL.NS;RCF.NS;BLML.NS;PWFC.NS
;RECLTD.NS;BHEL.NS;ENGINERSIN.NS;ANDY.NS;BLMR.NS;BAJE.NS;HCPR.NS;HMTL.NS;I
TI.NS;HINDCOPPER.NS;KIOCL.NS;NATIONALUM.NS;NMDC.NS;CHENNPETRO.NS;GAIL.NS;H
INDPETRO.NS;IOC.NS;MRPL.NS;NLCINDIA.NS;NTPC.NS;POWERGRID.NS;SAIL.NS;MTNL.N
S;ITDC.NS;MMTC.NS;STCINDIA.NS;CONCOR.NS;DREDGECORP.NS;SCI.NS;BEML.NS",src=
"yahoo",from=01-01-2000)
Warning: HOCL.NS download failed; trying again.
Warning: Unable to import “HOCL.NS”.
HOCL.NS download failed after two attempts. Error message:
HTTP error 404.
Warning: IRCON.NS download failed; trying again.
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
Warning: BLML.NS download failed; trying again.
Warning: Unable to import “BLML.NS”.
BLML.NS download failed after two attempts. Error message:
HTTP error 404.
Warning: PWFC.NS download failed; trying again.
Warning: Unable to import “PWFC.NS”.
PWFC.NS download failed after two attempts. Error message:
HTTP error 404.
Warning: RECLTD.NS download failed; trying again.
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
Warning: ANDY.NS download failed; trying again.
Warning: Unable to import “ANDY.NS”.
ANDY.NS download failed after two attempts. Error message:
HTTP error 404.
Warning: BLMR.NS download failed; trying again.
Warning: Unable to import “BLMR.NS”.
BLMR.NS download failed after two attempts. Error message:
HTTP error 404.
Warning: BAJE.NS download failed; trying again.
Warning: Unable to import “BAJE.NS”.
BAJE.NS download failed after two attempts. Error message:
HTTP error 404.
Warning: HCPR.NS download failed; trying again.
Warning: Unable to import “HCPR.NS”.
HCPR.NS download failed after two attempts. Error message:
HTTP error 404.
Warning: HMTL.NS download failed; trying again.
Warning: Unable to import “HMTL.NS”.
HMTL.NS download failed after two attempts. Error message:
HTTP error 404.
Warning: ITI.NS download failed; trying again.
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
pausing 1 second between requests for more than 5 symbols
[1] "IRCON.NS" "ONGC.NS" "FACT.NS" "NFL.NS"
"RCF.NS"
[6] "RECLTD.NS" "BHEL.NS" "ENGINERSIN.NS" "ITI.NS"
"HINDCOPPER.NS"
[11] "KIOCL.NS" "NATIONALUM.NS" "NMDC.NS" "CHENNPETRO.NS"
"GAIL.NS"
[16] "HINDPETRO.NS" "IOC.NS" "MRPL.NS" "NLCINDIA.NS"
"NTPC.NS"
[21] "POWERGRID.NS" "SAIL.NS" "MTNL.NS" "ITDC.NS"
"MMTC.NS"
[26] "STCINDIA.NS" "CONCOR.NS" "DREDGECORP.NS" "SCI.NS"
"BEML.NS"
There were 49 warnings (use warnings() to see them)
> getSymbols("HOCL.BO",src="yahoo",from=01-01-2000)
[1] "HOCL.BO"
Warning message:
HOCL.BO contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("ANDY.BO",src="yahoo",from=01-01-2000)
Warning: ANDY.BO download failed; trying again.
Error in getSymbols.yahoo(Symbols = "ANDY.BO", env = <environment>,
verbose = FALSE, :
Unable to import “ANDY.BO”.
ANDY.BO download failed after two attempts. Error message:
HTTP error 404.
> getSymbols("ANDY.NS",src="yahoo",from=01-01-2000)
Warning: ANDY.NS download failed; trying again.
Error in getSymbols.yahoo(Symbols = "ANDY.NS", env = <environment>,
verbose = FALSE, :
Unable to import “ANDY.NS”.
ANDY.NS download failed after two attempts. Error message:
HTTP error 404.
> getSymbols("ANDY.NS",src="google",from=01-01-2000)
Error: ‘getSymbols.google’ is defunct.
Google Finance stopped providing data in March, 2018.
You could try setting src = "yahoo" instead.
See help("Defunct") and help("quantmod-defunct")
> getSymbols("ANDEWYU.BO",src="google",from=01-01-2000)
Error: ‘getSymbols.google’ is defunct.
Google Finance stopped providing data in March, 2018.
You could try setting src = "yahoo" instead.
See help("Defunct") and help("quantmod-defunct")
> getSymbols("ANDEWYU.BO",src="yahoo",from=01-01-2000)
Warning: ANDEWYU.BO download failed; trying again.
Error in getSymbols.yahoo(Symbols = "ANDEWYU.BO", env = <environment>, :
Unable to import “ANDEWYU.BO”.
ANDEWYU.BO download failed after two attempts. Error message:
HTTP error 404.
> getSymbols("ANDREWYU.BO",src="yahoo",from=01-01-2000)
Warning: ANDREWYU.BO download failed; trying again.
[1] "ANDREWYU.BO"
Warning messages:
1: In formals(sys.function(sys.parent())) :
closing unused connection 9
(https://query2.finance.yahoo.com/v7/finance/download/ANDREWYU.BO?
period1=-
172800000&period2=1588723200&interval=1d&events=history&crumb=PvnUojQpOHt)
2: In formals(sys.function(sys.parent())) :
closing unused connection 8
(https://query1.finance.yahoo.com/v7/finance/download/ANDEWYU.BO?period1=-
172800000&period2=1588723200&interval=1d&events=history&crumb=PvnUojQpOHt)
3: In formals(sys.function(sys.parent())) :
closing unused connection 7
(https://query2.finance.yahoo.com/v7/finance/download/ANDEWYU.BO?period1=-
172800000&period2=1588723200&interval=1d&events=history&crumb=rF1rQrzhrq6)
4: In formals(sys.function(sys.parent())) :
closing unused connection 6
(https://query1.finance.yahoo.com/v7/finance/download/ANDY.NS?period1=-
172800000&period2=1588723200&interval=1d&events=history&crumb=rF1rQrzhrq6)
5: In formals(sys.function(sys.parent())) :
closing unused connection 5
(https://query2.finance.yahoo.com/v7/finance/download/ANDY.NS?period1=-
172800000&period2=1588723200&interval=1d&events=history&crumb=qd7SeSzNhM8)
6: In formals(sys.function(sys.parent())) :
closing unused connection 4
(https://query1.finance.yahoo.com/v7/finance/download/ANDY.BO?period1=-
172800000&period2=1588723200&interval=1d&events=history&crumb=qd7SeSzNhM8)
7: In formals(sys.function(sys.parent())) :
closing unused connection 3
(https://query1.finance.yahoo.com/v7/finance/download/ANDY.BO?period1=-
172800000&period2=1588723200&interval=1d&events=history&crumb=WWNne6FhQ5g)
8: ANDREWYU.BO contains missing values. Some functions will not work if
objects contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("NFL.NS",src="yahoo",from=01-01-2000)
[1] "NFL.NS"
Warning message:
NFL.NS contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("BALMLAWRIE.NS",src="yahoo",from=01-01-2000)
[1] "BALMLAWRIE.NS"
Warning message:
BALMLAWRIE.NS contains missing values. Some functions will not work if
objects contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("532485.BO",src="yahoo",from=01-01-2000)
[1] "532485.BO"
Warning message:
532485.BO contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> View(`532485.BO`)
> View(`532485.BO`)
> View(`532485.BO`)
> View(`532485.BO`)
> View(`532485.BO`)
> View(`532485.BO`)
> getSymbols("PFC.BO",src="yahoo",from=01-01-2000)
[1] "PFC.BO"
Warning message:
PFC.BO contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("BEL.BO",src="yahoo",from=01-01-2000)
[1] "BEL.BO"
Warning message:
BEL.BO contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("HINDCOPPER.NS",src="yahoo",from=01-01-2000)
[1] "HINDCOPPER.NS"
Warning message:
HINDCOPPER.NS contains missing values. Some functions will not work if
objects contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("HMT.NS",src="yahoo",from=01-01-2000)
[1] "HMT.NS"
Warning message:
HMT.NS contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("HINDZINC.NS",src="yahoo",from=01-01-2000)
[1] "HINDZINC.NS"
Warning message:
HINDZINC.NS contains missing values. Some functions will not work if
objects contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("Hal.NS",src="yahoo",from=01-01-2000)
[1] "Hal.NS"
Warning message:
Hal.NS contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("COALINDIA.NS",src="yahoo",from=01-01-2000)
[1] "COALINDIA.NS"
Warning message:
COALINDIA.NS contains missing values. Some functions will not work if
objects contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("GICRE.NS",src="yahoo",from=01-01-2000)
[1] "GICRE.NS"
Warning message:
GICRE.NS contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("HUDCO.NS",src="yahoo",from=01-01-2000)
[1] "HUDCO.NS"
Warning message:
HUDCO.NS contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("MOIL.NS",src="yahoo",from=01-01-2000)
[1] "MOIL.NS"
Warning message:
MOIL.NS contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("NBCC.NS",src="yahoo",from=01-01-2000)
[1] "NBCC.NS"
Warning message:
NBCC.NS contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("NIACL.NS",src="yahoo",from=01-01-2000)
[1] "NIACL.NS"
Warning message:
NIACL.NS contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("OIL.NS",src="yahoo",from=01-01-2000)
[1] "OIL.NS"
Warning message:
OIL.NS contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("SJVN.NS",src="yahoo",from=01-01-2000)
[1] "SJVN.NS"
Warning message:
SJVN.NS contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> getSymbols("RECLTD.NS",src="yahoo",from=01-01-2000)
[1] "RECLTD.NS"
Warning message:
RECLTD.NS contains missing values. Some functions will not work if objects
contain missing values in the middle of the series. Consider using
na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> View(`532485.BO`)
> View(`532485.BO`)
> save.image("C:/Users/user/Desktop/QUANTMOD.RData")
> View(ANDREWYU.BO)
> View(`532485.BO`)
> View(`532485.BO`)
> ##Balmer& Lawrie Investments -532485.BO#####
> save.image("C:/Users/user/Desktop/QUANTMOD.RData")
> install.packages("rvest")
Installing package into ‘C:/Users/user/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
also installing the dependency ‘selectr’

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/selectr_0.4-


2.zip'
Content type 'application/zip' length 485407 bytes (474 KB)
downloaded 474 KB

trying URL
'https://cran.rstudio.com/bin/windows/contrib/3.5/rvest_0.3.5.zip'
Content type 'application/zip' length 662934 bytes (647 KB)
downloaded 647 KB

package ‘selectr’ successfully unpacked and MD5 sums checked


package ‘rvest’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in


C:\Users\user\AppData\Local\Temp\Rtmpo7IsSj\downloaded_packages
> install.packages("robotstxt")
Installing package into ‘C:/Users/user/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
also installing the dependencies ‘globals’, ‘listenv’, ‘spiderbar’,
‘future’, ‘future.apply’

trying URL
'https://cran.rstudio.com/bin/windows/contrib/3.5/globals_0.12.5.zip'
Content type 'application/zip' length 75753 bytes (73 KB)
downloaded 73 KB

trying URL
'https://cran.rstudio.com/bin/windows/contrib/3.5/listenv_0.8.0.zip'
Content type 'application/zip' length 105562 bytes (103 KB)
downloaded 103 KB

trying URL
'https://cran.rstudio.com/bin/windows/contrib/3.5/spiderbar_0.2.2.zip'
Content type 'application/zip' length 673339 bytes (657 KB)
downloaded 657 KB

trying URL
'https://cran.rstudio.com/bin/windows/contrib/3.5/future_1.17.0.zip'
Content type 'application/zip' length 685990 bytes (669 KB)
downloaded 669 KB

trying URL
'https://cran.rstudio.com/bin/windows/contrib/3.5/future.apply_1.5.0.zip'
Content type 'application/zip' length 130971 bytes (127 KB)
downloaded 127 KB

trying URL
'https://cran.rstudio.com/bin/windows/contrib/3.5/robotstxt_0.6.2.zip'
Content type 'application/zip' length 133927 bytes (130 KB)
downloaded 130 KB

package ‘globals’ successfully unpacked and MD5 sums checked


package ‘listenv’ successfully unpacked and MD5 sums checked
package ‘spiderbar’ successfully unpacked and MD5 sums checked
package ‘future’ successfully unpacked and MD5 sums checked
package ‘future.apply’ successfully unpacked and MD5 sums checked
package ‘robotstxt’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in


C:\Users\user\AppData\Local\Temp\Rtmpo7IsSj\downloaded_packages
> paths_allowed{
Error: unexpected '{' in "paths_allowed{"
> paths=c("https://economictimes.indiatimes.com")
> }
Error: unexpected '}' in "}"
> paths_allowed{
Error: unexpected '{' in "paths_allowed{"
> paths = c("https://economictimes.indiatimes.com")
> }
Error: unexpected '}' in "}"
> library(robotstxt)
Warning message:
package ‘robotstxt’ was built under R version 3.5.3
> paths_allowed(paths = c("https://economictimes.indiatimes.com""))
+ paths_allowed{
+ paths = c("https://economictimes.indiatimes.com"")
Error: unexpected string constant in:
"paths_allowed{
paths = c(""
> }
Error: unexpected '}' in "}"
> paths_allowed{
Error: unexpected '{' in "paths_allowed{"
> paths = c("https://economictimes.indiatimes.com")
> }
Error: unexpected '}' in "}"
> paths_allowed(paths = c("https://economictimes.indiatimes.com/"))
economictimes.indiatimes.com No encoding supplied:
defaulting to UTF-8.
[1] TRUE

You might also like