Learn R Programming

PortfolioTesteR (version 0.1.4)

sql_adapter: Load Price Data from SQL Database

Description

Loads stock price data from SQLite database with automatic frequency conversion.

Usage

sql_adapter(
  db_path,
  symbols,
  start_date = NULL,
  end_date = NULL,
  auto_update = TRUE,
  frequency = "daily"
)

Value

data.table with Date column and one column per symbol

Arguments

db_path

Path to SQLite database file

symbols

Character vector of stock symbols to load

start_date

Start date (YYYY-MM-DD) or NULL

end_date

End date (YYYY-MM-DD) or NULL

auto_update

Auto-update database before loading (default: TRUE)

frequency

"daily", "weekly", or "monthly" (default: "daily")

Examples

Run this code
if (FALSE) { # requireNamespace("RSQLite", quietly = TRUE) && file.exists("sp500.db")
# \donttest{
prices <- sql_adapter(
  db_path   = "sp500.db",
  symbols   = c("AAPL", "MSFT"),
  start_date = "2020-01-01",
  end_date   = "2020-12-31",
  frequency  = "weekly"
)
head(prices)
# }
}

Run the code above in your browser using DataLab