Learn R Programming

PortfolioTesteR (version 0.1.4)

weight_by_regime: Regime-Based Adaptive Weighting

Description

Applies different weighting methods based on market regime classification. Enables adaptive strategies that change allocation approach in different market conditions.

Usage

weight_by_regime(
  selected_df,
  regime,
  weighting_configs,
  signal_df = NULL,
  vol_timeframe_data = NULL,
  strategy_timeframe_data = NULL
)

Value

Data.table with regime-adaptive weights

Arguments

selected_df

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

regime

Regime classification (integer values per period)

weighting_configs

List with method-specific parameters

signal_df

Signal values (required for signal/rank methods)

vol_timeframe_data

Volatility data (required for volatility method)

strategy_timeframe_data

Strategy timeframe alignment data

Examples

Run this code
data("sample_prices_weekly")
# Create selection and signals
momentum <- calc_momentum(sample_prices_weekly, lookback = 12)
selected <- filter_top_n(momentum, n = 10)

# Create a simple regime (example: based on market trend)
ma20 <- calc_moving_average(sample_prices_weekly, 20)
spy_price <- sample_prices_weekly$SPY
spy_ma <- ma20$SPY
regime <- ifelse(spy_price > spy_ma, 1, 2)

# Different weights for bull/bear markets
weighting_configs <- list(
  "1" = list(method = "equal"),
  "2" = list(method = "signal")
)
weights <- weight_by_regime(selected, regime, weighting_configs,
                            signal_df = momentum)

Run the code above in your browser using DataLab