R has powerful tools for downloading stock prices

Any person who invests in stocks is going to want to make sure they have the latest data for the programs they use. One of the most popular sites to do this downloading of historical data is Yahoo Finance, as it is one of the more important collections. People need this information, and the R programming language has ways of doing this. This will be able to be added into programs that help people decide when to buy, sell, or hold. This is why people who have their own programs need to understand how to cull the information for use.

Packages Used

There are multiple packages that can be used to pull the information that is required. The most popular is the quantmod package, but the tidyquant one adds in the ability of the tidy formats. The main reason to use either of the quant variants is because the GetSymbols function is powerful, but people might like the BatchGetSymbols package. That package has a better way to have the financial data organized for better reading. People have made sure to improve on the already powerful tools in quantmod. People who want to learn the basic may want to start there.

Information Gathered

When a person uses the GetSymbols function, they will be able to get the historical data, moving average, and closing price. A person will need the stock symbol if they are going for specific stocks, and this will download the relevant information to the program. Tidy and Batch packages will help organize these better. Yahoo Finance and Google Finance are usually where people will go, and this is all set up in the arguments section. The ticker information will allow someone to see how their analysis is holding up to what is actually happening in the real world.

Understanding Arguments

As with all functions in R, a person will need to understand the argument portion of it to get the most out of it. The src argument is limited to eight places to download stock market data, but it does have many strengths once understanding them all. If a person does not get them right, there will be missing values. If a person used these before 2009, they will need to reacquaint themselves with changes since then. NULL is an important state to know when bringing in the commands to pull the information from the various finance sites.

Batch Improvements

If a person is wanting to get lots of information in a better viewing situation, this is when someone will use BatchGetSymbols instead of GetSymbols. Batch has a cache ability in the more recent versions and puts it in a format that missing values can be found easier. This is much better when someone is getting stock market data on many stock symbols. It also allows many other functions that can sort and verify all the data gathered with the commands. This also has a large selection of arguments to further refine what is gathered by the coding.

Tidy Addition

People have the choice of TidyQuant as another way to handle organizing the data that is coming from the downloads. The Tidy package adds in the tibble function in with the getsymbols function of QuantMod. They may be separate commands, but they combine to another way to sort through all the data that gets pulled down. People who have not used tibble will find that this is used by many as a good way to set up tables to make sense of what they have and helps from a data science standpoint. This is another organizing, useful package.

Organizing Everything

There are many ways, as shown, to organize everything in a way that shows a time series for the stock market data. This can be turned into a personal stock ticker that can have the information in a manner anyone into stocks will be used to. Anyone using R will have some understanding of data science and how to use it in sorting anything about stocks. TidyQuant, BatchGetSymbols, and QuantMod are concerned with this in different ways. Any person who normally works with this type of programming may enjoy the flexibility that other packages can add for them.

Coding Snippets

Here are snippets of coding for each of the different functions that are talked about here. These may not fully work without other information, but they will give a good idea of use.

getSymbols(“F”, from = date, to = date)

This uses getsymbols for Ford from the dates needed. Adding tibble commands will allow for tables.

BatchGetSymbols(tickers = ticker used, first.date = date, last.date = date)

This is a basic search through a ticker for batch data with the BatchGetSymbols package.

These commands will be of use when a person is wanting to download all they can for their own stock price portfolio software. This may take time to find what the programmer is comfortable with, but if it is a team collaboration, then the ability to sort everything into a more table type presentation and then into a ticker will help everyone. This is the power that R will give to those who are setting up a trading company or just for an individual trader. Information then becomes the power to make informed decisions, especially with moving averages.

Scroll to top