Learn R Programming

PortfolioTesteR (version 0.1.4)

yahoo_adapter: Download Price Data from Yahoo Finance

Description

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.

Usage

yahoo_adapter(symbols, start_date, end_date, frequency = "daily")

Value

Data.table with Date column and one column per symbol

Arguments

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")

Examples

Run this code
# 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)

if (FALSE) { # interactive()
# 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)
}
}

Run the code above in your browser using DataLab