Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

random.portfolio fails without constraints and no weight sequence specified #12

Open
sstoeckl opened this issue Sep 20, 2018 · 2 comments

Comments

@sstoeckl
Copy link

See the code below. Is that intended?

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)

@sstoeckl
Copy link
Author

sstoeckl commented Oct 1, 2018

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...

@priyasaivasan
Copy link

Did you resolve this issue? I am having a similar problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants