Multiple simulations of portfolio with varying parameters and sample sizes

25 Views Asked by At

I have a portfolio that I would like to use the Monte Carlo method to do 100,000 simulations to understand the expected payout by first getting the expected number of payout.

The trickier part is that the underlying data is grouped by demographic factors like age and gender, along with the payout amount and number for each group. Example data as per the table:

Age Gender Payout Probability Number
35 M 100 0.1 800
35 F 85 0.05 500
40 M 150 0.2 300
41 F 145 0.09 290
... ... ... ... ...

I am also trying to avoid for loops (due to the time it might take if the number of simulations were to be increased) and to make use of vectorisation instead.

The idea is that for each simulation, it would pick up each record's Number and Probability for the size and prob arguments to generate the simulated number of payouts for each record and hence the whole portfolio (sum of simulated number of payouts for each record). And this should be repeated 100,000 times for as per Monte Carlo "principles" to get the mean. It should be stored in a matrix-like structure as this will then be multiplied by the payout in the data to get expected payout amount.

The results seems reasonable to me, but I do wonder if this makes sense if I am missing anything by using the Map function as I am not very familiar with it. And if there are any best practices in terms of coding that I should be aware of when doing Monte Carlo simulations that might be relevant to what I am doing?

Thank you in advance.

set.seed(1) 
grouped.data <- read.csv("grouped data.csv")     # Read grouped data (example per table above) 
number.simulations <- 100000 
number.payout <- grouped.data$Number
probability <- grouped.data$Probability

simulated.exp.total.number <- matrix(
                           unlist(Map(rbinom, number.simulations, number.payout, probability)), 
                           nrow = number.simulations, 
                           ncol = nrow(grouped.data)
                           )

0

There are 0 best solutions below