[R-SIG-Finance] PortfolioAnalytics: Out-of-sample optimization with transaction cost constraint

Pankaj K Agarwal p@nk@j@b| @end|ng |rom y@hoo@com
Tue Nov 15 12:14:14 CET 2022


Dear JarnoPerhaps you could try adding Trace = TRUE argument in your optimize.portfolio.rebalancing call.
Regards,Pankaj K Agarwal
+91-98397-11444http://in.linkedin.com/in/pankajkagarwal/ 

    On Tuesday, 15 November, 2022 at 04:37:21 pm IST, Jarno Bergmeier <jarno.bergmeier using web.de> wrote:  
 
 Hello everyone, I am currently trying to run an out-of-sample-optimization with the PortfolioAnalytics package, where the quadratic utility function of the investor also penalizes transaction costs (40bps) through the numeric solver. The vignette states that this can be implemented via a constraint that is supported for quadratic utility maximization using the ROI solver. However, this does not work for me. I have the following exemplary code: library(xts)
library(PortfolioAnalytics)
library(ROI)
library(quadprog)
options(scipen = 999) data("edhec")
returns = edhec[, 1:3]
colnames(returns) = c("CA", "CTAG", "DS") port <- portfolio.spec(assets = colnames(returns))
port <- add.constraint(port, "long_only")
port <- add.constraint(port, "weight_sum", min_weight = 1, max_weight = 1)
port <- add.constraint(port, "transaction_cost", ptc = 0.004)
port <- add.objective(port, type = "risk", name = "var", risk_aversion = 10)
port <- add.objective(port, type = "return", name = "mean") opt_TC = optimize.portfolio.rebalancing(R = returns, portfolio = port, optimize_method = "ROI", rebalance_on = "months", training_period = 100, rolling_window = NULL) rr_TC = Return.portfolio(returns, weights = extractWeights(opt_TC))
charts.PerformanceSummary(rr_TC)
chart.Weights(opt_TC)  When I run this code without the transaction cost constraint it works fully as intended. However, if I run it with the TC constraint, I suddenly receive the following error messages:> charts.PerformanceSummary(rr_TC)
Error in `[.xts`(x, start.row, 1) : subscript out of bounds
> chart.Weights(opt_TC)
Error in plot.window(xlim, ylim, log = log, ...) : 
  need finite 'ylim' values It does work with the "DEoptim" solver (although the solutions somehow look strange to me), but I would want to run it using the ROI solver, which should be possible as I understand it. Has someone had a similar problem and was able to fix it? Kind regards, 
Jarno _______________________________________________
R-SIG-Finance using r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
  
	[[alternative HTML version deleted]]



More information about the R-SIG-Finance mailing list