2
I need to create a random investment portfolio with certain benchmarks. I initialized it with all 0.
structure(list(Benchmarks = structure(c(2L, 7L, 6L, 10L, 12L,
11L, 13L, 14L, 15L, 16L, 17L, 1L, 4L, 3L, 9L, 5L, 8L), .Label = c("ALOCACAO",
"DI", "DÓLAR", "IBOV", "IDA - GERAL", "IDKA_IPCA2", "IDKA_PRE2",
"IFIX", "IHFA", "IMA-GERAL", "IMAB", "IMAB - 5", "IMAB - 5 +",
"IRFM", "IRFM - 1", "IRFM - 1 +", "VÉRTICE"), class = "factor"),
percentual = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0)), class = "data.frame", row.names = c(NA, -17L))
But I have the following conditions:
- The obligation, sum of benchmarks = 100%, cannot be left over or missing.
- Not all benchmarks need to be filled, some may be empty
Abaxio follows the generation of one of the benchs that I made
distribuicaoBenchmark[distribuicaoBenchmark$Benchmarks == "DI", 2] <- runif(1, min = 0, max = 100)
I couldn’t think of two limitations. I thought about using one while (totalInvestido < 100)
, but in my tests, there was money left over or he was on an eternal loop because I could never satisfy the condition of while.
Are the two conditions not the same? The sum of the benchmarks == 100%?
– Rui Barradas
Rereading now yes, I will do an Edit!
– Flavio Silva