LSPM Examples

January 2, 2010

(This article was first published on FOSS Trading, and kindly contributed to R-bloggers)

I have received several requests for additional LSPM documentation over the past couple days and a couple months ago I promised an introduction to LSPM.

In this long-overdue post, I will show how to optimize a Leverage Space Portfolio with the LSPM package.  Please use the comments to let me know what you would like to see next.

Some copious notes before we get to the code:

These examples are based on revision 26 31 from r-forge and will not work under earlier revisions (and may not work with later revisions). LSPM is still in very alpha status.  Expect things to change, perhaps significantly.

These examples were run using DEoptim_1.3-3 (and LSPM revision 26 depends on that version) code from DEoptim_1.3-3 that has been bundled inside LSPM.  We are working with the DEoptim authors to address issues with more recent versions of DEoptim.  LSPM will un-bundle and use the most recent version of DEoptim as soon as the issues are resolved.

The first two examples are taken from Vince, Ralph (2009). The Leverage Space Trading Model. New York: John Wiley & Sons, Inc. The results will not match the book because of differences between optimization via DEoptim and Ralph’s genetic algorithm implementation.  Ralph believes his genetic algorithm is getting hung up on a local maximum, whereas DEoptim is closer to the global solution.

    # Load the LSPM package

    # Multiple strategy example (data found on pp. 84-87)
    trades <- cbind(
     c(533,220.14,220.14,-500,533,220.14,799,220.14,-325,220.14,533,220.14) )
    <- c(rep(0.076923077,2),0.153846154,rep(0.076923077,9))

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

    # DEoptim parameters (see ?DEoptim)
    # NP=30        (10 * number of strategies)
    # itermax=100  (maximum number of iterations)
    DEctrl <– list(NP=30,itermax=100)

    # Unconstrainted Optimal f (results on p. 87)
    res <– optimalf(port,control=DEctrl)

    # Drawdown-constrained Optimal f (results on p. 137)
    # Since horizon=12, this optimization will take about an hour
    <– optimalf(port,probDrawdown,0.1,DD=0.2,horizon=12,calc.max=4,control=DEctrl)

    # Ruin-constrained Optimal f
    <– optimalf(port,probRuin,0.1,DD=0.2,horizon=4,control=DEctrl)

    # Drawdown-constrained Optimal f
    res <– optimalf(port,probDrawdown,0.1,DD=0.2,horizon=4,control=DEctrl)

    To leave a comment for the author, please follow the link and comment on their blog: FOSS Trading. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

    If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

    Tags: ,

    Comments are closed.


    Mango solutions

    RStudio homepage

    Zero Inflated Models and Generalized Linear Mixed Models with R

    Dommino data lab

    Quantide: statistical consulting and training



    CRC R books series

    Six Sigma Online Training

    Contact us if you wish to help support R-bloggers, and place your banner here.

    Never miss an update!
    Subscribe to R-bloggers to receive
    e-mails with the latest R posts.
    (You will not see this message again.)

    Click here to close (This popup will not appear again)