powered by
Calculates momentum as the percentage change in price over a specified lookback period. Optimized using column-wise operations (25x faster).
calc_momentum(data, lookback = 12)
Data.table with momentum values (0.1 = 10% increase)
A data.frame or data.table with Date column and price columns
Number of periods for momentum calculation (default: 12)
data("sample_prices_weekly") momentum <- calc_momentum(sample_prices_weekly, lookback = 12)
Run the code above in your browser using DataLab