[R-SIG-Finance] [R-SIG-FINANCE] Low Priority - market component list and general coding help
gsee000 at gmail.com
Fri Oct 26 21:32:07 CEST 2012
On Fri, Oct 26, 2012 at 2:01 PM, Martin Jenkins <mjenko at yahoo.com> wrote:
> I've searched around and not found anything to help on this, even though it's not the first time it's been asked, so was wondering if anyone had any new ideas.
> I really like the device output of the chartSeries function and so have used it to output a bitmap of the stock chart. What I'm using it for is to get an entire market index component list, however to get that I've had to create my own flat file called masterlist.csv in the below code. Ideally I'd like to have a function do the same job so I don't have to create the file manually. This way I can quickly and easily get graphs for an entire stock market.
> Rather frustratingly Yahoo! have stopped allowing the component list for an index to be downloaded.
If you just want a list of most stocks, use TTR::stockSymbols()
Fetching AMEX symbols...
Fetching NASDAQ symbols...
Fetching NYSE symbols...
 "AA-P" "AAU" "ACU" "ACY" "ADGE" "ADK"
If the holdings of ETFs will suffice, you can use getHoldings from my
qmao package on R-Forge
R> #install.packages("qmao", repos='http://r-forge.r-project.org')
R> rownames(getHoldings("SPY", auto.assign=FALSE))
If you want components of specific indexes, you might look through the
code from systematic investor
I haven't used any of that code, but the file I linked to above
appears to get the Symbols of stocks for different indexes.
> Also as you can see my coding skills are restricted by my procedural background, so whilst the below works fine, I'm sure it can be written more efficiently.
> One last thing, I'm using the auto.assign = FALSE so that I can use a variable in chartseries, this leaves me with the name of my variable, in this case 'x', on the bitmap, which isn't ideal, meaning I have to refer to the filename for the epic.
You can simply provide a "name" argument to chartSeries()
R> s <- "AAPL"
R> chartSeries(getSymbols(s, src='google', auto.assign=FALSE), name=s)
Just curious, why use src='google' ? I've found yahoo's data to be
slightly more reliable.
> Many thanks,
> masterfile <- "C:/Users/Admin/Documents/Programming/R/current/FTSE100/masterlist.csv"
> path <- "C:/Users/Admin/Documents/Programming/R/ftse100bmps/"
> epicstable <- read.table(masterfile, header=FALSE, sep=",")
> i <- 1
> while(is.na(epicstable$V1[i]) == "FALSE")
> epic_char <- as.character(epicstable$V1[i])
> x <- try(getSymbols(epic_char, auto.assign=FALSE))
> if (length(x)==1)
> x <- try(getSymbols(epic_char, src = "google", auto.assign=FALSE))
> if (length(x) > 1)
> outputfile <- paste(path, epicstable$V1[i], '.bmp')
> bmp(file=outputfile, bg = "transparent", width = 1024, height = 768)
> i = i + 1
> [[alternative HTML version deleted]]
> R-SIG-Finance at r-project.org mailing list
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
More information about the R-SIG-Finance