Skip to contents

Downloads historical stock data from Yahoo Finance for given symbols and date range.

Usage

download_data_stock_prices(symbols, start_date = NULL, end_date = NULL)

Arguments

symbols

A character vector of stock symbols to download data for. At least one symbol must be provided.

start_date

Optional. A character string or Date object in "YYYY-MM-DD" format specifying the start date for the data. If not provided, a one-year subset of the dataset is returned (see validate_dates()).

end_date

Optional. A character string or Date object in "YYYY-MM-DD" format specifying the end date for the data. If not provided, a one-year subset of the dataset is returned (see validate_dates()).

Value

A tibble containing the downloaded stock data with columns: symbol, date, volume, open, low, high, close, and adjusted_close.

Details

Dates are the trading days in the exchange's local time zone, as reported by Yahoo Finance, and the range is inclusive of both start_date and end_date.

Examples

# \donttest{
  download_data_stock_prices(c("AAPL", "MSFT"))
#> No `start_date` or `end_date` provided. Using the range 2024-09-24 to
#> 2025-09-24 to avoid downloading large amounts of data.
#> # A tibble: 502 × 8
#>    symbol date         volume  open   low  high close adjusted_close
#>    <chr>  <date>        <dbl> <dbl> <dbl> <dbl> <dbl>          <dbl>
#>  1 AAPL   2024-09-24 43556100  229.  226.  229.  227.           225.
#>  2 AAPL   2024-09-25 42308700  225.  224.  227.  226.           224.
#>  3 AAPL   2024-09-26 36636700  227.  225.  228.  228.           226.
#>  4 AAPL   2024-09-27 34026000  228.  227.  230.  228.           226.
#>  5 AAPL   2024-09-30 54541900  230.  230.  233   233            231.
#>  6 AAPL   2024-10-01 63285000  230.  224.  230.  226.           224.
#>  7 AAPL   2024-10-02 32880600  226.  223.  227.  227.           225.
#>  8 AAPL   2024-10-03 34044200  225.  223.  227.  226.           224.
#>  9 AAPL   2024-10-04 37245100  228.  224.  228   227.           225.
#> 10 AAPL   2024-10-07 39505400  224.  221.  226.  222.           220.
#> # ℹ 492 more rows
  download_data_stock_prices("GOOGL", "2021-01-01", "2022-01-01" )
#> # A tibble: 252 × 8
#>    symbol date         volume  open   low  high close adjusted_close
#>    <chr>  <date>        <dbl> <dbl> <dbl> <dbl> <dbl>          <dbl>
#>  1 GOOGL  2021-01-04 37324000  88    85.4  88.1  86.3           85.5
#>  2 GOOGL  2021-01-05 20360000  86.3  85.8  87.3  87.0           86.2
#>  3 GOOGL  2021-01-06 46588000  85.0  84.8  87.2  86.1           85.3
#>  4 GOOGL  2021-01-07 41936000  86.3  86.3  88.9  88.7           87.9
#>  5 GOOGL  2021-01-08 35484000  88.9  88.1  90.0  89.9           89.0
#>  6 GOOGL  2021-01-11 34796000  88.9  87.6  89.2  87.8           87.0
#>  7 GOOGL  2021-01-12 29528000  87.3  85.8  88.4  86.9           86.1
#>  8 GOOGL  2021-01-13 23432000  86.4  86.4  87.8  87.4           86.5
#>  9 GOOGL  2021-01-14 29212000  87.4  86.3  88.4  86.5           85.7
#> 10 GOOGL  2021-01-15 31444000  86.5  85.6  87.4  86.4           85.6
#> # ℹ 242 more rows
# }