Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## loop thru list and use quantmod to calculate performance from 1/2/14 to 12/31/14
- for(i in 1:4881){
- ticker <- tickernames[i]
- getSymbols(ticker)
- Open <- ticker["2014-01-02",1]
- Close <- ticker["2014-12-31",4]
- performance2014[i] = (Open - Close)/Open
- }
- require(quantmod)
- #Vector of symbols to fetch prices for
- symbols <- c('MSFT','SBUX','GOOGL')
- #Initialize a list to store the fetched prices
- myList <- list()
- #Loop through symbols, fetch prices, and store in myList
- myList <-lapply(symbols, function(x) {getSymbols(x,auto.assign=FALSE)} )
- #Housekeeping
- names(myList) <- symbols
- #Access MSFT prices
- myList[['MSFT']]
- #Access SBUX prices
- myList[['SBUX']]
- #Access GOOGL prices
- myList[['GOOGL']]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement