You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
require(PortfolioAnalytics)
data(edhec)
R<-edhec[, 1:4]
pspec<- portfolio.spec(assets=colnames(R))
pspec<- add.constraint(portfolio=pspec, type="full_investment")
rp1<- random_portfolios(portfolio=pspec, permutations=5000,rp_method='sample')
#> Error in seq.default(from = round(min, rounding), to = round(max, rounding), : 'from' must be a finite number
Created on 2018-09-20 by the reprex package (v0.2.1.9000)
The text was updated successfully, but these errors were encountered:
I just realized that this happens if no weight (box) constraints are specified for the portfolio object. In this case generatesequence() returns an error. A solution could be to assume any weight bound (e.g. min=-n_assets,max=+n_assets) and give a warning. However, when I try to add something like this: if(min(constraints$min)==-Inf){ constraints$min <- rep(-nassets,nassets) warning("random_portfolio needs to sample between bounded weights. As no box constraints were set, we specify minimum weights as -number of assets.") } if(max(constraints$max)==Inf){ constraints$max <- rep(nassets,nassets) warning("random_portfolio needs to sample between bounded weights. As no box constraints were set, we specify maximum weights as number of assets.") }
I get various other problems in rp_transform not finding feasible weights etc...
See the code below. Is that intended?
Created on 2018-09-20 by the reprex package (v0.2.1.9000)
The text was updated successfully, but these errors were encountered: