Downloads historical stock data from Yahoo Finance for given symbols and date range.
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.
See also
Other download functions:
download_data(),
download_data_constituents(),
download_data_factors_ff(),
download_data_factors_q(),
download_data_fred(),
download_data_fred_md(),
download_data_huggingface(),
download_data_jkp(),
download_data_macro_predictors(),
download_data_osap(),
download_data_pastor_stambaugh(),
download_data_risk_free(),
download_data_stambaugh_yuan(),
download_factor_library_grid(),
download_factor_library_ids()
Examples
# \donttest{
download_data_stock_prices(c("AAPL", "MSFT"))
#> No `start_date` or `end_date` provided. Using the range 2024-10-05 to
#> 2025-10-05 to avoid downloading large amounts of data.
#> # A tibble: 498 × 8
#> symbol date volume open low high close adjusted_close
#> <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 AAPL 2024-10-07 39505400 224. 221. 226. 222. 220.
#> 2 AAPL 2024-10-08 31855700 224. 223. 226. 226. 224.
#> 3 AAPL 2024-10-09 33591100 225. 225. 230. 230. 228.
#> 4 AAPL 2024-10-10 28183500 228. 227. 230. 229. 227.
#> 5 AAPL 2024-10-11 31759200 229. 227. 229. 228. 226.
#> 6 AAPL 2024-10-14 39882100 229. 229. 232. 231. 229.
#> 7 AAPL 2024-10-15 64751400 234. 232. 237. 234. 232.
#> 8 AAPL 2024-10-16 34082200 232. 230. 232. 232. 230.
#> 9 AAPL 2024-10-17 32993800 233. 231. 234. 232. 230.
#> 10 AAPL 2024-10-18 46431500 236. 234. 236. 235 233.
#> # ℹ 488 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
# }