Learn R Programming

PortfolioTesteR (version 0.1.4)

calc_sector_breadth: Calculate Market Breadth by Sector

Description

Measures participation within each sector separately, revealing which sectors have broad strength vs concentrated leadership. Optimized using pre-splitting for speed.

Usage

calc_sector_breadth(
  condition_df,
  sector_mapping,
  min_stocks_per_sector = 3,
  na_sector_action = c("exclude", "separate", "market")
)

Value

A data.table with Date and Breadth_[Sector] columns (0-100 scale)

Arguments

condition_df

Data frame with Date column and TRUE/FALSE values

sector_mapping

Data frame with Symbol and Sector columns.

min_stocks_per_sector

Minimum stocks for valid sector breadth (default: 3)

na_sector_action

How to handle unmapped stocks: "exclude", "separate", or "market"

Examples

Run this code
data("sample_prices_weekly")
data("sample_sp500_sectors")
ma200 <- calc_moving_average(sample_prices_weekly, 200)
above_ma <- filter_above(calc_distance(sample_prices_weekly, ma200), 0)
sector_breadth <- calc_sector_breadth(above_ma, sample_sp500_sectors)

Run the code above in your browser using DataLab