My last post provided examples of how to use the LSPM package. Those who experimented with the code have probably found that constrained optimizations with horizons > 6 have long run-times (when calc.max >= horizon).
This post will illustrate how the snow package can increase the speed of the probDrawdown and probRuin functions on computers with multiple cores. This yields nearly linear improvements in run-times relative to the number of cores. (Improvements are nearly linear because there is overhead in setting up the cluster and communication between the nodes.)
The first optimization takes 346 seconds on my 2.2Ghz Centrino, while the second optimization (with snow) takes 193 seconds... nearly a 45% improvement.
# Load the libraries
# Create a Leverage Space Portfolio object
trades <- cbind(
probs <- c(rep(0.076923077,2),0.153846154,rep(0.076923077,9))
port <- lsp(trades,probs)
# Optimization using one CPU core
res1 <- optimalf(port,probDrawdown,0.1,DD=0.2,horizon=5,control=list(NP=30,itermax=100))
# Create snow socket cluster for both cores
clust <- makeSOCKcluster(2)
# Optimization using both CPU cores
res2 <- optimalf(port,probDrawdown,0.1,DD=0.2,horizon=5,snow=clust,control=list(NP=30,itermax=100))
# Stop snow cluster
1 day ago