LSPM Examples
[This article was first published on FOSS Trading, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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.Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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
These examples were run using
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
library(LSPM)
# Multiple strategy example (data found on pp. 84-87)
trades <- cbind(
c(-150,-45.33,-45.33,rep(13,5),rep(79.67,3),136),
c(253,-1000,rep(-64.43,3),253,253,448,rep(-64.43,3),253),
c(533,220.14,220.14,-500,533,220.14,799,220.14,-325,220.14,533,220.14) )
probs <- c(rep(0.076923077,2),0.153846154,rep(0.076923077,9))
# Multiple strategy example (data found on pp. 84-87)
trades <- cbind(
c(-150,-45.33,-45.33,rep(13,5),rep(79.67,3),136),
c(253,-1000,rep(-64.43,3),253,253,448,rep(-64.43,3),253),
c(533,220.14,220.14,-500,533,220.14,799,220.14,-325,220.14,533,220.14) )
probs <- 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
res <– optimalf(port,probDrawdown,0.1,DD=0.2,horizon=12,calc.max=4,control=DEctrl)
# Ruin-constrained Optimal f
res <– 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)
# 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
res <– optimalf(port,probDrawdown,0.1,DD=0.2,horizon=12,calc.max=4,control=DEctrl)
# Ruin-constrained Optimal f
res <– 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.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.