I'm working with an R package called "ruin package", and it is taking too long to compute the ruin probability for the parameter values that I chose. The function works, I already checked for other values that come in here: Cran-r-project-package-ruin-readme. This is my code:
library(ruin)
library(ggplot2)
#set.seed(1991)
#Definicion del modelo CramerLundberg y la simulacion de la trayectoria
model2<- CramerLundberg(
initial_capital = 10,
premium_rate = 100,
claim_poisson_arrival_rate = 100,
claim_size_generator = rexp, # mean=1/rate f(x)=lambda exp(-lambda x)
claim_size_parameters = list(rate = 1.25))
path2 <- simulate_path(model = model2, max_time_horizon = 50)
#Grafica de la trayectoria
plot_path(path2)+ labs(title= "Modelo de riesgo clásico") + xlab("tiempo") +
ylab("Capital ")
head(path2@path)
#Cálculo de probabilidad de ruina real
ruin_probability(model = model2, time_horizon = 10, parallel = FALSE, return_paths = FALSE)
I tried to change parallel = TRUE, thinking that it would help to do the calculations faster but I received a warning message: Warning message. Maybe it does take long, but I'm not sure how long it would normally take to give the calculation.
My question is: how can I reduce the execution time for the ruin_probability function with the values defined in model2.
I hope someone can help me.
Thanks! c:
I don't think there's much you can do within the scope of this particular package to speed things up. However, it can help to benchmark some shorter runs to help you estimate how long the full run will take: e.g. on my system simulating only 100 rather than 1000 paths (the default) takes about 5 seconds:
system.time(
ruin_probability(model = model2, time_horizon = 10,
parallel = FALSE, return_paths = FALSE, simulation_number = 100)
)
This will let me know how much trouble you're in if you want to run the default 1000 simulations (if you're in a hurry and are willing to have lower precision you could settle for an answer based on fewer simulations).
If you run it for multiple values of simulation_number
you can see how the elapsed time scales with the number of simulations (I'd be surprised if it were different from linear, but you never know ...)
Also, your warning messages are actually harmless; they mean that some R session that set up some parallel connections didn't clean them up properly so they're being auto-cleaned. You can go ahead and run your simulations in parallel if you want.