Guest User

Untitled

a guest
Dec 14th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. library(PerformanceAnalytics)
  2. library(PortfolioAnalytics)
  3.  
  4. # Use the first 4 columns in edhec for a returns object
  5. data(edhec)
  6. returns <- edhec[, 1:4]
  7. colnames(returns) <- c("CA", "CTAG", "DS", "EM")
  8. funds <- colnames(returns)
  9.  
  10. # Create portfolio object
  11. portf_maxret <- portfolio.spec(assets=funds)
  12. # Add constraints to the portfolio object
  13. portf_maxret <- add.constraint(portfolio=portf_maxret, type="full_investment")
  14. portf_maxret <- add.constraint(portfolio=portf_maxret, type="box",
  15. min=c(0.02, 0.05, 0.03, 0.02),
  16. max=c(0.55, 0.6, 0.65, 0.5))
  17. # Add objective to the portfolio object
  18. portf_maxret <- add.objective(portfolio=portf_maxret, type="return", name="mean")
  19.  
  20. require(DEoptim) # for simplicity's sake let's forget about ROI
  21. opt_maxret <- optimize.portfolio(R = returns, portfolio = portf_maxret, trace = TRUE)
Add Comment
Please, Sign In to add comment