Skip to content
Prev 13778 / 15274 Next

PortfolioAnalytics question re: showing results

Hi Matt,

You are very close in your script. Note that create.EfficientFrontier with
type="mean-StdDev" is a special case for an efficient frontier that can be
formulated and solved with a QP solver.

Also note that your second call to add.objective should add to the SD.portf
portfolio and not init.portf
# Add measure 2, annualized standard deviation
# note that you want to add this to the SD.portf portfolio, not init.portf
SD.portf <- add.objective(portfolio=SD.portf,
                            type="risk", # the kind of objective this is
                            name="pasd1", # to minimize from the sample
                            enabled=TRUE, # enable or disable the objective
                            multiplier=0 # calculate it but don't use it in
the objective
)

I recommend actually running an optimization using random portfolios so you
get the entire feasible space given the constraints and objectives in your
portfolio.

rp <- random_portfolios(SD.portf, 5000)
# make sure to run with trace=TRUE for the extract stats output
opt <- optimize.portfolio(R, SD.portf, optimize_method="random", trace=TRUE)
chart.RiskReward(opt, risk.col="pasd1.pasd1", return.col="pamean1.pamean1")

# use the output of extractStats to find portfolio with max return at a
given
# risk level and portfolio with min risk at a given return level
ex <- extractStats(opt)
head(ex)

# This should get you started
# order by max pamean1
head(ex[order(ex[,"pamean1.pamean1"], decreasing=TRUE),])

# order by min pasd1
head(ex[order(ex[,"pasd1.pasd1"], decreasing=FALSE),])

Hope this helps, let me know if you need any other pointers.

Regards,
Ross
On Fri, Mar 18, 2016 at 8:13 AM, <matt at considine.net> wrote: