filter_top_n: Select Top N Stocks by Signal Value

View source: R/filters.R

filter_top_nR Documentation

Select Top N Stocks by Signal Value

Description

Most commonly used filter function. Selects top N (highest) or bottom N (lowest) stocks by signal value. Optimized for 5-10x faster performance.

Usage

filter_top_n(signal_df, n, ascending = FALSE)

Arguments

signal_df

Data frame with Date column and signal values

n

Number of stocks to select

ascending

FALSE (default) selects highest, TRUE selects lowest

Value

Binary selection matrix (1 = selected, 0 = not selected)

Examples

data("sample_prices_weekly")
momentum <- calc_momentum(sample_prices_weekly, 12)
# Select 10 highest momentum stocks
top_momentum <- filter_top_n(momentum, n = 10)

PortfolioTesteR documentation built on Nov. 5, 2025, 5:23 p.m.