In R, the main library for working with time series data is xts. The Quantmod library builds on xts to provide the user with many quantitative finance features, including the ability to download data directly from Yahoo Finance.

To load these two libraries in R, simply run the following:

Next, we specify the start and end dates of the time series we want to download:

To download the stock price data of a certain stock, such as Apple, simply input the required parameters ( ticker, src = data_source, from = start date, to = end date) into the getSymbols function as follows:

In order to plot the adjusted closing prices of Apple, we simply run:

Apple R