| filter_top_n_where | R Documentation |
Selects top N stocks by signal, but only from those meeting a condition. Combines qualification and ranking in one step.
filter_top_n_where(
signal_df,
n,
condition_df,
min_qualified = 1,
ascending = FALSE
)
signal_df |
Signal values for ranking |
n |
Number to select |
condition_df |
Binary matrix of qualified stocks |
min_qualified |
Minimum qualified stocks required (default: 1) |
ascending |
FALSE for highest, TRUE for lowest |
Binary selection matrix
data("sample_prices_weekly")
# Calculate indicators
momentum <- calc_momentum(sample_prices_weekly, 12)
ma20 <- calc_moving_average(sample_prices_weekly, 20)
distance_from_ma <- calc_distance(sample_prices_weekly, ma20)
# Top 10 momentum stocks from those above MA
above_ma <- filter_above(distance_from_ma, 0)
top_qualified <- filter_top_n_where(momentum, 10, above_ma)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.