Skip to contents

This function downloads stock data from https://finance.yahoo.com/ and saves it as a .csv-file.

Usage

download_data(
  symbol,
  from = "1902-01-01",
  to = Sys.Date(),
  file = paste0(symbol, ".csv"),
  verbose = TRUE
)

Arguments

symbol

A character, the stock's symbol. It must match the identifier on https://finance.yahoo.com/.

from

A date in format "YYYY-MM-DD", setting the lower data bound. Must not be earlier than "1902-01-01".

to

A date in format "YYYY-MM-DD", setting the upper data bound. Default is the current date Sys.date().

file

The name of the file where the .csv-file is saved. Per default, it is saved in the current working directory with the name "symbol.csv".

verbose

If TRUE returns information about download success.

Value

No return value.

Details

The downloaded data is a .csv-file with the following columns:

  • Date: The date.

  • Open: Opening price.

  • High: Highest price.

  • Low: Lowest price.

  • Close: Close price adjusted for splits.

  • Adj.Close: Close price adjusted for dividends and splits.

  • Volume: Trade volume.

Examples

### download 21st century DAX data
download_data(
  symbol = "^GDAXI", from = "2000-01-03",
  file = paste0(tempfile(), ".csv")
)
#> Download successful.
#> * symbol: ^GDAXI 
#> * from: 2000-01-03 
#> * to: 2022-07-07 
#> * path: /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/RtmpIBhz8b/file6c91426ff67.csv