<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>Dear Pankaj,</div>

<div> </div>

<div>thank you very much for the suggestion, unfortunately that did not fix it, it results in the same error message(s). I just posted the question to QuantExchange, maybe someone on there has a suggestion.</div>

<div> </div>

<div>Kind regards!</div>

<div> 
<div> 
<div style="margin: 10.0px 5.0px 5.0px 10.0px;padding: 10.0px 0 10.0px 10.0px;border-left: 2.0px solid rgb(195,217,229);">
<div style="margin: 0 0 10.0px 0;"><b>Gesendet:</b> Dienstag, 15. November 2022 um 12:14 Uhr<br/>
<b>Von:</b> "Pankaj K Agarwal" <pankajsbi@yahoo.com><br/>
<b>An:</b> "r-sig-finance@r-project.org" <r-sig-finance@r-project.org>, "Jarno Bergmeier" <jarno.bergmeier@web.de><br/>
<b>Betreff:</b> Re: [R-SIG-Finance] PortfolioAnalytics: Out-of-sample optimization with transaction cost constraint</div>

<div>
<div class="ydp27567897yahoo-style-wrap" style="font-family: times new roman , new york , times , serif;font-size: 16.0px;">
<div>
<div>Dear Jarno</div>

<div>Perhaps you could try adding Trace = TRUE argument in your optimize.portfolio.rebalancing call.</div>

<div> </div>

<div class="ydp27567897signature">
<div>
<div class="ydp27567897MsoNormal">
<div class="ydp27567897MsoNormal">
<div class="ydp27567897MsoNormal">
<div class="ydp27567897MsoNormal"><span style="font-family: "bookman old style" , "new york" , times , serif;font-size: medium;">Regards,</span></div>

<div class="ydp27567897MsoNormal">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;"><span style="font-size: medium;font-family: "bookman old style" , "new york" , times , serif;"><span style="line-height: 1.22;"><span style="line-height: 1.22;"><span style="line-height: 1.22;">Pankaj K Agarwal</span></span></span></span></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<div class="ydp27567897MsoNormal">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;"><span style="line-height: 1.22;"><span style="line-height: 1.22;"><span style="line-height: 1.22;"><span style="font-size: medium;font-family: "bookman old style" , "new york" , times , serif;">+91-98397-11444</span></span></span></span></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<div>
<div class="ydp27567897MsoNormal">
<div class="ydp27567897MsoNormal">
<div class="ydp27567897MsoNormal">
<div class="ydp27567897MsoNormal">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;">
<div class="ydp27567897MsoNormal" style="display: inline;"><span style="line-height: 1.22;"><span style="font-size: medium;font-family: "bookman old style" , "new york" , times , serif;"><a href="http://in.linkedin.com/in/pankajkagarwal/" target="_blank">http://in.linkedin.com/in/pankajkagarwal/</a></span></span></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<div> </div>

<div> </div>
</div>

<div class="yahoo_quoted" id="yahoo_quoted_8623029029">
<div style="font-family: "Helvetica Neue" , Helvetica , Arial , sans-serif;font-size: 13.0px;color: rgb(38,40,42);">
<div>On Tuesday, 15 November, 2022 at 04:37:21 pm IST, Jarno Bergmeier <jarno.bergmeier@web.de> wrote:</div>

<div> </div>

<div> </div>

<div>
<div id="yiv3022806259">
<div>
<div style="font-family: Verdana;font-size: 12.0px;">
<div>Hello everyone,</div>

<div> </div>

<div>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:</div>

<div> </div>

<div>
<div>library(xts)<br/>
library(PortfolioAnalytics)<br/>
library(ROI)<br/>
library(quadprog)<br/>
options(scipen = 999)</div>

<div> </div>

<div>data("edhec")<br/>
returns = edhec[, 1:3]<br/>
colnames(returns) = c("CA", "CTAG", "DS")</div>

<div> </div>

<div>port <- portfolio.spec(assets = colnames(returns))<br/>
port <- add.constraint(port, "long_only")<br/>
port <- add.constraint(port, "weight_sum", min_weight = 1, max_weight = 1)<br/>
port <- add.constraint(port, "transaction_cost", ptc = 0.004)<br/>
port <- add.objective(port, type = "risk", name = "var", risk_aversion = 10)<br/>
port <- add.objective(port, type = "return", name = "mean")</div>

<div> </div>

<div>opt_TC = optimize.portfolio.rebalancing(R = returns, portfolio = port, optimize_method = "ROI", rebalance_on = "months", training_period = 100, rolling_window = NULL)</div>

<div> </div>

<div>rr_TC = Return.portfolio(returns, weights = extractWeights(opt_TC))<br/>
charts.PerformanceSummary(rr_TC)<br/>
chart.Weights(opt_TC)</div>

<div> </div>

<div> </div>

<div>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:</div>

<div>> charts.PerformanceSummary(rr_TC)<br/>
Error in `[.xts`(x, start.row, 1) : subscript out of bounds<br/>
> chart.Weights(opt_TC)<br/>
Error in plot.window(xlim, ylim, log = log, ...) : <br/>
  need finite 'ylim' values</div>

<div> </div>

<div>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?</div>

<div> </div>

<div>Kind regards, <br/>
Jarno</div>

<div> </div>
</div>
</div>
</div>
</div>
_______________________________________________<br/>
<a href="mailto:R-SIG-Finance@r-project.org" onclick="parent.window.location.href='mailto:R-SIG-Finance@r-project.org'; return false;" target="_blank">R-SIG-Finance@r-project.org</a> mailing list<br/>
<a href="https://stat.ethz.ch/mailman/listinfo/r-sig-finance" target="_blank">https://stat.ethz.ch/mailman/listinfo/r-sig-finance</a><br/>
-- Subscriber-posting only. If you want to post, subscribe first.<br/>
-- Also note that this is not the r-help list where general R questions should go.</div>
</div>
</div>
</div>
</div>
</div>
</div></div></body></html>