I just started with quantmod package. If I want to select stocks based on their recent performance, then I need to loop through all the stocks in, say, NYSE. So I need:
- get all the stock symbols
- select those symbols that do have data
- loop through them one by one(say, each time, download the stock data as $X$, and do some analysis. Then loop to next one, and set it as $X$)
My question is: how can I do these? Here is part of my thought:
use stockSymbols() function in TTR package:
AllSym <- stockSymbols(). The first column of
AllSymare all the potential symbols.
getSymbols(AllSym[i,1])to loop all the stock
Not all the symbols from TTR have data. Some may have error when using
getSymbols. I actually do not care about this certain stock. So how can I continue with the loop? [How can I use the
getSymbolsfunction will automatically make the stock symbols as the variables. How can I copy(or set) it to $X$(instead of something like $APPL$)?
How can I loop trough the variables with their names saved as strings in a vector? For example, if we do use
getSymbolsfunction to get data with name as the stock symbol. How can I loop through those stocks?[Note that their variable name are stored in first column
Thank you very much!