[Returnanalytics-commits] r3053 - in pkg/PortfolioAnalytics: R demo

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Sep 11 04:39:37 CEST 2013


Author: rossbennett34
Date: 2013-09-11 04:39:36 +0200 (Wed, 11 Sep 2013)
New Revision: 3053

Modified:
   pkg/PortfolioAnalytics/R/constrained_objective.R
   pkg/PortfolioAnalytics/demo/demo_proportional_cost.R
Log:
Modified penalty and demo script for transaction costs.

Modified: pkg/PortfolioAnalytics/R/constrained_objective.R
===================================================================
--- pkg/PortfolioAnalytics/R/constrained_objective.R	2013-09-11 01:11:06 UTC (rev 3052)
+++ pkg/PortfolioAnalytics/R/constrained_objective.R	2013-09-11 02:39:36 UTC (rev 3053)
@@ -502,7 +502,7 @@
     tc <- sum(abs(w - portfolio$assets) * constraints$ptc)
     # for now use a multiplier of 1, may need to adjust this later
     mult <- 1
-    out <- out + penalty * mult * tc
+    out <- out + mult * tc
   } # End transaction cost penalty
     
   nargs <- list(...)

Modified: pkg/PortfolioAnalytics/demo/demo_proportional_cost.R
===================================================================
--- pkg/PortfolioAnalytics/demo/demo_proportional_cost.R	2013-09-11 01:11:06 UTC (rev 3052)
+++ pkg/PortfolioAnalytics/demo/demo_proportional_cost.R	2013-09-11 02:39:36 UTC (rev 3053)
@@ -37,40 +37,39 @@
 # Now use random portfolios
 # set up portfolio with equally weighted portfolio for initial weights
 pspec <- portfolio.spec(assets=funds)
-pspec <- add.constraint(portfolio=pspec, type="full_investment")
+pspec <- add.constraint(portfolio=pspec, type="leverage", min_sum=0.99, max_sum=1.01)
 pspec <- add.constraint(portfolio=pspec, type="long_only")
 pspec <- add.constraint(portfolio=pspec, type="transaction", ptc=0.01)
 
 # There is no transaction cost, the penalty should be 0.
 # constrained_objective(w=rep(1/4, 4), R=R, portfolio=pspec)
 # wts <- c(0.2, 0.3, 0.25, 0.25)
-# 10000 * sum(abs(wts - pspec$assets)*pspec$constraints[[3]]$ptc)
+# sum(abs(wts - pspec$assets)*pspec$constraints[[3]]$ptc)
 # constrained_objective(w=wts, R=R, portfolio=pspec)
 
 # add objective to minimize standard deviation
 pspec <- add.objective(portfolio=pspec, type="risk", name="StdDev")
 
 # This pushes the optimal portfolio to the initial weights
-opt_rp <- optimize.portfolio(R=R, portfolio=pspec, optimize_method="random", search_size=2000)
+opt_rp <- optimize.portfolio(R=R, portfolio=pspec, optimize_method="random", search_size=2000, trace=TRUE)
 opt_rp
 
-
 # Now use random portfolios
 # set up portfolio with initial weights
 pspec <- portfolio.spec(assets=c(0.15, 0.15, 0.2, 0.5))
-pspec <- add.constraint(portfolio=pspec, type="full_investment")
+pspec <- add.constraint(portfolio=pspec, type="leverage", min_sum=0.99, max_sum=1.01)
 pspec <- add.constraint(portfolio=pspec, type="long_only")
 pspec <- add.constraint(portfolio=pspec, type="transaction", ptc=0.01)
 
 # There is no transaction cost, the penalty should be 0.
 # constrained_objective(w=rep(1/4, 4), R=R, portfolio=pspec)
 # wts <- c(0.2, 0.3, 0.25, 0.25)
-# 10000 * sum(abs(wts - pspec$assets)*pspec$constraints[[3]]$ptc)
+# sum(abs(wts - pspec$assets)*pspec$constraints[[3]]$ptc)
 # constrained_objective(w=wts, R=R, portfolio=pspec)
 
 # add objective to minimize standard deviation
 pspec <- add.objective(portfolio=pspec, type="risk", name="StdDev")
 
 # This pushes the optimal portfolio to the initial weights
-opt_rp <- optimize.portfolio(R=R, portfolio=pspec, optimize_method="random", search_size=2000)
+opt_rp <- optimize.portfolio(R=R, portfolio=pspec, optimize_method="random", search_size=2000, trace=TRUE)
 opt_rp



More information about the Returnanalytics-commits mailing list