Path: blob/master/sandbox/test2_rp_transform2.R
1433 views
1min_sum <- 0.992max_sum <- 1.013min_box <- rep(-0.15, length(weights))4max_box <- rep(0.6, length(weights))56# violate min_sum and box constraint7weights <- c(0.2, -0.2, 0.4, 0.5)8sum(weights)910rp_transform(w=weights,11min_sum=min_sum,12max_sum=max_sum,13min_box=min_box,14max_box=max_box)151617# violate max_sum and box constraints18weights <- c(0.35, 0.05, 0.7, 0.1)19sum(weights)2021rp_transform(w=weights,22min_sum=min_sum,23max_sum=max_sum,24min_box=min_box,25max_box=max_box)262728# violate box constraints and leverage29weights <- c(-0.45, 0.45, 0.55, 0.45)30sum(weights)31sum(abs(weights))32leverage <- 1.63334rp_transform(w=weights,35min_sum=min_sum,36max_sum=max_sum,37min_box=min_box,38max_box=max_box,39leverage=leverage)404142# violate max position limit constraint43weights <- c(0.15, 0.25, 0.4, 0.2)44sum(weights)45max_pos <- 34647rp_transform(w=weights,48min_sum=min_sum,49max_sum=max_sum,50min_box=min_box,51max_box=max_box,52max_pos=max_pos)5354# violate position limit constraint55weights <- c(-0.05, -0.05, 0.4, 0.7)56sum(weights)5758max_pos_short <- 15960rp_transform(w=weights,61min_sum=min_sum,62max_sum=max_sum,63min_box=min_box,64max_box=max_box,65max_pos_short=max_pos_short)6667# violate position limit constraint68weights <- c(-0.05, -0.05, 0.4, 0.7)69sum(weights)7071max_pos_long <- 372max_pos_short <- 17374rp_transform(w=weights,75min_sum=min_sum,76max_sum=max_sum,77min_box=min_box,78max_box=max_box,79max_pos_long=max_pos_long,80max_pos_short=max_pos_short)818283# violate position limit constraint84weights <- c(-0.05, -0.05, 0.4, 0.7)85sum(weights)8687max_pos_long <- 388max_pos_short <- 189max_pos <- 39091rp_transform(w=weights,92min_sum=min_sum,93max_sum=max_sum,94min_box=min_box,95max_box=max_box,96max_pos=max_pos,97max_pos_long=max_pos_long,98max_pos_short=max_pos_short)99100# violate position limit and leverage constraint101weights <- c(-0.25, -0.15, 0.4, 0.7)102sum(weights)103sum(abs(weights))104105max_pos_long <- 3106max_pos_short <- 1107max_pos <- 3108leverage <- 1.3109110rp_transform(w=weights,111min_sum=min_sum,112max_sum=max_sum,113min_box=min_box,114max_box=max_box,115max_pos=max_pos,116max_pos_long=max_pos_long,117max_pos_short=max_pos_short,118leverage=leverage)119120# The second group is above cUP and the fourth group is below cLO121weights <- c(0.06, 0.1, 0.07, 0.2, 0.22, 0.10, 0.05, 0.08, 0.05, 0.04, 0.03)122sum(weights[1:2])123sum(weights[3:6])124sum(weights[7:10])125sum(weights[10:11])126sum(weights)127128groups <- list(1:2,1293:6,1307:10,13110:11)132# group_pos <- c(2, 3, 2, 2)133group_pos <- NULL134cLO <- c(0.05, 0.10, 0.05, 0.08)135cUP <- c(0.4, 0.55, 0.65, 0.45)136min_sum <- 0.99137max_sum <- 1.01138min_box <- rep(0.05, length(weights))139max_box <- rep(0.65, length(weights))140141group_fail(weights, groups, cLO, cUP, group_pos)142143w <- rp_transform(weights, min_sum, max_sum, min_box, max_box, groups, cLO, cUP)144PortfolioAnalytics:::group_fail(w, groups, cLO, cUP, group_pos)145146147# Note that this was typically not working with max_permutations=200148# Relax constraints or increase max_permutations149150# max_pos <- 3151# max_pos_long <- 4152# max_pos_short <- 4153# leverage <- Inf154# max_permutations <- 200155#156# rp_transform2(weights=weights,157# min_sum=min_sum,158# max_sum=max_sum,159# min_box=min_box,160# max_box=max_box,161# max_pos=max_pos,162# max_pos_long=max_pos_long,163# max_pos_short=max_pos_short,164# leverage=leverage,165# max_permutations=max_permutations)166167168169170