Learn R Programming

PortfolioTesteR (version 0.1.4)

weight_by_rank: Rank-Based Portfolio Weighting

Description

Weights securities based on their rank rather than raw signal values. Useful when signal magnitudes are unreliable but ordering is meaningful.

Usage

weight_by_rank(
  selected_df,
  signal_df,
  method = c("linear", "exponential"),
  ascending = FALSE
)

Value

Data.table with rank-based weights

Arguments

selected_df

Binary selection matrix

signal_df

Signal values for ranking

method

Weighting method: "linear" or "exponential"

ascending

Sort order for ranking (default: FALSE)

Examples

Run this code
data("sample_prices_weekly")
momentum <- calc_momentum(sample_prices_weekly, lookback = 12)
selected <- filter_top_n(momentum, 10)
# Linear rank weighting (best gets most)
weights <- weight_by_rank(selected, momentum, method = "linear")
# Exponential (heavy on top stocks)
weights_exp <- weight_by_rank(selected, momentum, method = "exponential")

Run the code above in your browser using DataLab