# 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