1
$\begingroup$

I am experimenting with the PortfolioAnalytics package to optimize portfolio with dollar neutral and transaction costs as constraints to the quadratic utility objective function. A sample R snippet is the following:

data(edhec)
R <- edhec[,1:6]
colnames(R) <- c("CA", "TAG", "DS", "EM", "EQMN", "ED")

funds <- colnames(R) 
pspec <- portfolio.spec(assets=funds)
pspec <- add.constraint(portfolio=pspec, type="dollar_neutral")
pspec <- add.constraint(portfolio=pspec, type="transaction_cost", ptc=0.01, enabled=TRUE)
pspec <- add.objective(portfolio=pspec, type="return", name="mean")
pspec <- add.objective(portfolio=pspec, type="risk", name="var", risk_aversion=1.0)
opt_qu <- optimize.portfolio(R=R,portfolio=pspec, optimize_method="ROI", trace=TRUE)

The documentation on PortfolioAnalytics states that " Proportional transaction cost constraints can be implemented for quadratic utility and minimum variance problems using the ROI solver", However, I get the following error:

Error in ROI::L_constraint(L = Amat, dir = dir, rhs = rhs) : 
      all(c(dim_L[1], n_dir) == n_L_constraints) is not TRUE

I have further debugged to identify that constraints.R, line no. 357, in ROI package throws this error when dimensions do not match. The problem is in function gmv_opt_ptc() function, the line no. 87

dir <- dir[!is.infinite(rhs)]

doesn't really resize to the size of rhs vector. Could anyone help with this error, in general?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.