[R-SIG-Finance] Portfolio Optimization with tawny package

Ross Bennett rossbennett34 at gmail.com
Tue Oct 15 16:15:35 CEST 2013


Hi Eric,

I'm not familiar with doing portfolio optimization with the Tawny
package, but the PortfolioAnalytics is designed to do just what you
are asking and a lot more.

The PortfolioAnalytics package is on R-forge and can be built and
installed following directions in this Stack Overflow post.
http://stackoverflow.com/questions/11105131/cannot-install-r-forge-package-using-install-packages?rq=1

I would encourage you to read the demos and vignettes which contain
more detailed and several additional examples.

library(PortfolioAnalytics)
library(ROI) # from CRAN
library(ROI.plugin.glpk) # from CRAN
library(ROI.plugin.quadprog) # from r-forge

data(edhec)
R <- edhec[, 1:5]
funds <- colnames(R)

# Create initial portfolio with basic constraints
init.portf <- portfolio.spec(assets=funds)
init.portf <- add.constraint(portfolio=init.portf, type="full_investment")
init.portf <- add.constraint(portfolio=init.portf, type="long_only")

# Create new portfolio from init.portf and add objective to minimize
standard deviation
minSD.portf <- add.objective(portfolio=init.portf, type="risk", name="StdDev")

# Set up portfolio to maximize mean per ES
meanES.portf <- add.objective(portfolio=init.portf, type="return", name="mean")
meanES.portf <- add.objective(portfolio=meanES.portf, type="risk", name="ES")

# View the constraints and objectives of each portfolio
print(minSD.portf)
print(meanES.portf)

# Run the optimization for the minimum standard deviation portfolio
minSD.opt <- optimize.portfolio(R=R, portfolio=minSD.portf,
optimize_method="ROI", trace=TRUE)
print(minSD.opt)

# Run the optimization for the maximize mean per ES portfolio
meanES.opt <- optimize.portfolio(R=R, portfolio=meanES.portf,
optimize_method="ROI", trace=TRUE)
print(meanES.opt)

Hope that helps, let me know if you have any more questions.
Ross

On Tue, Oct 15, 2013 at 3:00 AM, <r-sig-finance-request at r-project.org> wrote:
>
> Message: 1
> Date: Mon, 14 Oct 2013 22:31:44 -0400
> From: Eric Thungstom <eric.thungstrom at gmail.com>
> To: R-SIG-Finance at r-project.org
> Subject: [R-SIG-Finance] Portfolio Optimization with tawny package
> Message-ID:
>         <CACv3XEAjhcjm05i2Qt6pirfwO96WK9VVhJTHz34ATuexJaA9cg at mail.gmail.com>
> Content-Type: text/plain
>
> I'm just starting to use the tawny to do portfolio optimization. I;m
> wondering if there is a way to force the optimization to not allow short
> selling. If I use the package example:
>
> require(tawny)
> data(sp500.subset)
> h <- sp500.subset
> ws.1 <-optimizePortfolio(h, 150, RandomMatrixDenoiser())
>
>
> head(ws.1[,1:5])
>                  [,1]      [,2]          [,3]        [,4]         [,5]
> 2008-12-15 0.09248187 0.2088942 -0.0028581226 -0.05568185 -0.011270020
> 2008-12-16 0.09312921 0.2184338 -0.0041928798 -0.05388050 -0.007905639
> 2008-12-17 0.09697907 0.2152621  0.0004219331 -0.05719625 -0.007520671
> 2008-12-18 0.10532884 0.2226241 -0.0004360120 -0.05933589 -0.008948998
> 2008-12-19 0.10566713 0.2241632 -0.0001421756 -0.05808452 -0.008664915
> 2008-12-22 0.10716821 0.2256598  0.0020645245 -0.05588680 -0.005201937
>
> Npte some of the portfolio weights are negative implying short selling.
>
> The package works great but not sure how I could determine the optimum
> portfolio given a "no short selling" criteria.
>
> Thanks in advance for your comments
>
>         [[alternative HTML version deleted]]
>
>
>
> ------------------------------
>



More information about the R-SIG-Finance mailing list