View source: R/data_adapters.R
| yahoo_adapter | R Documentation |
Downloads stock price data directly from Yahoo Finance using quantmod. No database required - perfect for quick analysis and experimentation. Get started with real data in under 5 minutes.
yahoo_adapter(symbols, start_date, end_date, frequency = "daily")
symbols |
Character vector of stock symbols |
start_date |
Start date in "YYYY-MM-DD" format |
end_date |
End date in "YYYY-MM-DD" format |
frequency |
"daily" or "weekly" (default: "daily") |
Data.table with Date column and one column per symbol
# Use included sample data
data(sample_prices_weekly)
# Build a quick momentum strategy with offline data
momentum <- calc_momentum(sample_prices_weekly, lookback = 12)
selected <- filter_top_n(momentum, n = 2)
weights <- weight_equally(selected)
result <- run_backtest(sample_prices_weekly, weights, initial_capital = 100000)
# Download tech stocks (requires internet, skipped on CRAN)
if (requireNamespace("quantmod", quietly = TRUE)) {
prices <- yahoo_adapter(
symbols = c("AAPL", "MSFT", "GOOGL"),
start_date = "2023-01-01",
end_date = "2023-12-31",
frequency = "weekly"
)
momentum <- calc_momentum(prices, lookback = 12)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.