This function uses a block of code from randomize_portfolio
to transform the weight vector if either the weight_sum (leverage)
constraints, box constraints, group constraints, position_limit constraints,
or leverage exposure constraints are violated. The logic from
randomize_portfolio
is heavily utilized here with extensions to
handle more complex constraints.
The resulting weights vector might be quite different from the original weights vector.
rp_transform(
w,
min_sum,
max_sum,
min_box,
max_box,
groups = NULL,
cLO = NULL,
cUP = NULL,
max_pos = NULL,
group_pos = NULL,
max_pos_long = NULL,
max_pos_short = NULL,
leverage = NULL,
weight_seq = NULL,
max_permutations = 200
)
named weighting vector
weights vector to be transformed
minimum sum of all asset weights, default 0.99
maximum sum of all asset weights, default 1.01
numeric or named vector specifying minimum weight box constraints
numeric or named vector specifying maximum weight box constraints
vector specifying the groups of the assets
numeric or vector specifying minimum weight group constraints
numeric or vector specifying minimum weight group constraints
maximum assets with non-zero weights
vector specifying maximum number assets with non-zero weights per group
maximum number of assets with long (i.e. buy) positions
maximum number of assets with short (i.e. sell) positions
maximum leverage exposure where leverage is defined as sum(abs(weights))
vector of seed sequence of weights
integer: maximum number of iterations to try for a valid portfolio, default 200
Peter Carl, Brian G. Peterson, Ross Bennett (based on an idea by Pat Burns)