Learn R Programming

PortfolioTesteR (version 0.1.4)

demo_sector_map: Demo sector (group) map for examples/tests

Description

Demo sector (group) map for examples/tests

Usage

demo_sector_map(symbols, n_groups = 2L)

Value

A data.table with columns Symbol and Group (title-case), for demo use.

Arguments

symbols

character vector of tickers.

n_groups

integer number of groups to assign (cycled).

Examples

Run this code
# Minimal usage
syms <- c("AAPL","MSFT","AMZN","XOM","JPM")
gdf  <- demo_sector_map(syms, n_groups = 3L)  # columns: Symbol, Group
print(gdf)

# Use with cap_exposure(): convert to a named vector (names = symbols)
gmap <- stats::setNames(gdf$Group, gdf$Symbol)

data(sample_prices_weekly)
mom12 <- calc_momentum(sample_prices_weekly, 12)
sel10 <- filter_top_n(mom12, 10)
w_eq  <- weight_equally(sel10)

w_cap <- cap_exposure(
  weights          = w_eq,
  max_per_symbol   = 0.10,
  group_map        = gmap,     # <- named vector, OK for current cap_exposure()
  max_per_group    = 0.45,
  renormalize_down = TRUE
)
head(w_cap)

Run the code above in your browser using DataLab