Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(PerformanceAnalytics)
- library(PortfolioAnalytics)
- # Use the first 4 columns in edhec for a returns object
- data(edhec)
- returns <- edhec[, 1:4]
- colnames(returns) <- c("CA", "CTAG", "DS", "EM")
- funds <- colnames(returns)
- # Create portfolio object
- portf_maxret <- portfolio.spec(assets=funds)
- # Add constraints to the portfolio object
- portf_maxret <- add.constraint(portfolio=portf_maxret, type="full_investment")
- portf_maxret <- add.constraint(portfolio=portf_maxret, type="box",
- min=c(0.02, 0.05, 0.03, 0.02),
- max=c(0.55, 0.6, 0.65, 0.5))
- # Add objective to the portfolio object
- portf_maxret <- add.objective(portfolio=portf_maxret, type="return", name="mean")
- require(DEoptim) # for simplicity's sake let's forget about ROI
- opt_maxret <- optimize.portfolio(R = returns, portfolio = portf_maxret, trace = TRUE)
Add Comment
Please, Sign In to add comment