| switch_weights | R Documentation |
Dynamically switches between two weighting schemes based on a signal. Enables tactical allocation changes.
switch_weights(weights_a, weights_b, use_b_condition, partial_blend = 1)
weights_a |
Primary weight matrix |
weights_b |
Alternative weight matrix |
use_b_condition |
Logical vector (TRUE = use weights_b) |
partial_blend |
Blend factor 0-1 (default: 1 = full switch) |
Combined weight matrix
data("sample_prices_weekly")
momentum <- calc_momentum(sample_prices_weekly, lookback = 12)
selected <- filter_top_n(momentum, n = 10)
weights_equal <- weight_equally(selected)
weights_signal <- weight_by_signal(selected, momentum)
# Create switching signal (example: use SPY momentum as regime indicator)
spy_momentum <- momentum$SPY
switch_signal <- as.numeric(spy_momentum > median(spy_momentum, na.rm = TRUE))
switch_signal[is.na(switch_signal)] <- 0
# Switch between strategies
final_weights <- switch_weights(weights_equal, weights_signal, switch_signal)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.