Friday, April 9, 2010

Maximum Probability of Profit

To continue with the LSPM examples, this post shows how to optimize a Leverage Space Portfolio for the maximum probability of profit. The data and example are again taken from The Leverage Space Trading Model by Ralph Vince.

These optimizaitons take a very long time. 100 iterations on a 10-core Amazon EC2 cluster took 21 hours. Again, the results will not necessarily match the book because of differences between DEoptim and Ralph's genetic algorithm and because there are multiple possible paths one can take through leverage space that will achieve similar results.

The results from the EC2 run were:
iteration: 100 best member: 0.0275 0 0.0315 -0.928 -1 best value: -0.9999
The book results (on p. 173) were:
iteration: 100 best member: 0.085 0.015 0.129 -0.76 -0.992 best value: -0.9999

Specifying an initial population can give DEoptim an initial set of parameters that are within the constraint. This guarantees a starting point but it can slow optimization if the f (and/or z) values are too low. Therefore, experiment with the initial population to find a set of f (and/or z) values that produce a result within, but not far from, the constraint.


# Load the LSPM and snow packages
library(LSPM)
library(snow)

# Multiple strategy example (data found on pp. 84-87, 169)
trades <- cbind(
  c(-150,-45.333,-45.333,13,13,13,13,13,79.667,79.667,79.667,136),
  c(253,-1000,-64.429,-64.429,-64.429,253,253,448,-64.429,-64.429,-64.429,253),
  c(533,220.143,220.143,-500,533,220.143,799,220.143,-325,220.143,533,220.143))

probs <- c(0.076923076923,0.076923076923,0.153846153846,0.076923076923,
  0.076923076923,0.076923076923,0.076923076923,0.076923076923,
  0.076923076923,0.076923076923,0.076923076923,0.076923076923)

# Create a Leverage Space Portfolio object
port <- lsp(trades,probs)

# Number of population members
np <- 30

# Initial population
initpop <- cbind(runif(np,0,0.01),runif(np,0,0.01),runif(np,0,0.01),
  runif(np,-1,-0.8),runif(np,-1,-0.8))

# DEoptim parameters (see ?deoptim)
DEctrl <- list(NP=np, itermax=11, refresh=1, digits=6, initial=initpop)

# Create a socket cluster with snow to use both cores
# on a dual-core processor
cl <- makeSOCKcluster(2)

# Drawdown-constrained maximum probability of profit (results on p. 173)
res <- maxProbProfit(port, 1e-6, 12, probDrawdown, 0.1,
  DD=0.2, calc.max=4, snow=cl, control=DEctrl)

7 comments:

Ricky P.C. White said...

Josh, Thanks for another great explanation. I might point out to that it is not just the optimization algorithms used, but in the case of mazimizing for greatest probability of profit, there are many posssible optimal sets (f1,..,fn,z+,z-). There are multiple sets which will result in an equivalent (and highest) probability of profit.
-Ralph Vince

Matthew said...

If I understand the optimization problem correctly, I think it may be possible to achieve similar results in just minutes of computation with a different optimization approach. How long does it take to evaluate the fitness of one LSPM allocation?

Here is an example optimizer that is designed to find pretty globally optimal allocations while you wait: http://www.riskcog.com/portfolio-theme2.jsp#5e80e8d

Joshua Ulrich said...

Matthew,

The link you posted finds optimal allocations, but I don't see how to apply any constraints. An unconstrained LSPM geometric growth optimization only takes a few seconds.

Also, the example in this post doesn't find the growth-optimal allocation. Instead, it finds one--of potentially many--allocations that maximizes the probability of profitability, which is very different than a growth-optimal allocation.

Blase said...
This comment has been removed by the author.
TradingPro said...

Hello Josh,

Not yet up to speed with R myself could I ask if you are quickly able to pin point why the following error message is currently being produced:

> # Drawdown-constrained maximum probability of profit (results on p. 173)
> res <- maxProbProfit(port, 1e-6, 12, probDrawdown, 0.1,
+ DD=0.2, calc.max=4, snow=cl, control=DEctrl)
Error in function (VTR = -Inf, strategy = 2, bs = FALSE, NP = NA, itermax = 200, :
unused argument(s) (refresh = 1, digits = 6)

With thanks, Grant

Joshua Ulrich said...

Hi Grant,

The refresh parameter was renamed to trace, and the digits parameters was removed in recent versions of DEoptim.

Create the DEctrl object using this line of code instead:
DEctrl <- list(NP=np, itermax=11, trace=1, initial=initpop)

TradingPro said...

Spot on! My thanks Josh.