Hi
I want to download stock prices in a loop. But i have problem with the syntax on how to convert string into command etc.
I have this code:
library(quantmod)
getSymbols("GME", from = '2010-11-01', to = "2020-11-01")
Stockprices <- GME$GME.Adjusted
And this line of code above works fine.
however, if want the code to download more than stockprices i thought of using a loop to do that.
So i have a variable called "Dataset" with the different tricker-code for the stocks:
GME
AAPL
etc...
So i have tried to create a loop that looks like this:
x = 1
for (x in 1:nrow(Dataset)) {
getSymbols(sprintf("%s", Dataset[x,]), from = '2010-11-01', to = "2020-11-01")
Stockprice = sprintf("%s", Dataset[x,])$sprintf("%s", Dataset[x,]).Adjusted
}
The first coding line with the "getSymbols..." works fine.
But the last line of code where i want to save the adjusted stock price would not give the stock prices
I have also tried the code below, but that would just return a string of "GME$GME.Adjusted" but would not execute the command to actully give me the stock prices.
paste(q[1],"$",q[1],".Adjusted",sep="")
So how do i use data.frames or whatever its called to execute the command and not just returning a string.