I have a dataset of 2500 rows which are all bank loans. Each bank loan has an outstanding amount and collateral type. (Real estate, Machine tools.. etc)
I need to draw a random selection out of this dataset where for example the sum of outstanding amount = 2.5Million +-5% and maximum 25% loans with the same asset class.
I found the function optim, but this asks for a function and looks to be constructed for optimization a portfolio of stocks, which is much more complex. I would say that there is an easy way of achieving this?
I created a sample data set which could illustrate my question better:
dataset <- data.frame(balance=c(25000,50000,35000,40000,65000,10000,5000,2000,2500,5000)
,Collateral=c("Real estate","Aeroplanes","Machine tools","Auto Vehicles","Real estate",
"Machine tools","Office equipment","Machine tools","Real estate","Auto Vehicles"))
If I want for example 5 loans out of this dataset which sum of outstanding balance = 200.000 (with 10% margin) and not more than 40% is allowed to be the same collateral type. (so maximum 2 out of 5 in this example)
Please let me know if additional information is necessary. Many thanks, Tim