Path: blob/master/sandbox/testing_constrained_group.R
1433 views
12##### EX1 #####3# first group exceeds cUP4groups <- c(2, 1)5cLO <- c(0.2, 0.10)6cUP <- c(0.4, 0.55)78weights <- c(0.15, 0.35, 0.50)9sum(weights)1011(w <- constrained_group_tmp(groups, cLO, cUP, weights, 1, 1, TRUE))12sum(w[1:2])13sum(w)1415(w <- constrained_group_tmp(groups, cLO, cUP, weights, 1, 1, FALSE))16# The group 1 cUP is met exactly, but the sume of weights are not equal to 117sum(w[1:2])18sum(w)192021##### EX2 #####22# The assets are grouped into 3 groups of 223# The sum of the weights for the first group assets must be between 0.05 and 0.3524# The sum of the weights for the second group of assets must be between 0.10 and 0.4525# The sum of the weights for the last group of assets must be between 0.05 and 0.252627# first group exceeds cUP28groups <- c(2, 2, 2)29cLO <- c(0.05, 0.10, 0.05)30cUP <- c(0.4, 0.45, 0.25)3132weights <- c(0.15, 0.30, 0.15, 0.25, 0.05, 0.10)33sum(weights)3435(w <- constrained_group_tmp(groups, cLO, cUP, weights, 1, 1, TRUE))36sum(w)3738##### Ex3 #####39# The second group is below cLO40groups <- c(2, 1, 3)41cLO <- c(0.05, 0.10, 0.05)42cUP <- c(0.4, 0.45, 0.65)4344weights <- c(0.15, 0.25, 0.08, 0.2, 0.22, 0.10)45sum(weights)4647(w <- constrained_group_tmp(groups, cLO, cUP, weights, 1, 1, TRUE))48sum(w)4950##### Ex4 #####51# The second group is above cUP and the fourth group is below cLO52groups <- c(2, 4, 3, 2)53cLO <- c(0.05, 0.10, 0.05, 0.08)54cUP <- c(0.4, 0.5, 0.65, 0.45)5556weights <- c(0.05, 0.1, 0.07, 0.2, 0.22, 0.10, 0.05, 0.08, 0.05, 0.04, 0.04)57sum(weights[1:2])58sum(weights[3:6])59sum(weights[7:10])60sum(weights[10:11])61sum(weights)6263(w <- constrained_group_tmp(groups, cLO, cUP, weights, 1, 1, TRUE))64sum(w[1:2])65sum(w[3:6])66sum(w[7:10])67sum(w[10:11])6869# Group 2 cUP is being violated. Appears that normalizing at the end of the70# function is causing some of the group constraints to be violated717273