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

[FR] Allow user to set parallelization level for optimize.portfolio.rebalancing #43

Open
SteveBronder opened this issue Jan 2, 2025 · 2 comments

Comments

@SteveBronder
Copy link

For optimize.portfolio.rebalancing it would be nice to have an argument that would allow the user to set the parallelization level. For instance, CVXR::psolve has a [parallel] argument. Would it be possible to switch to psolve over solve calls? Because adding a parallelization argument and using psolve would then users with large problems to decide where it would be best to have parallelization for their problem. Another example would be generating random portfolios.

@braverock
Copy link
Owner

We can send extra arguments to the solvers (e.g. c("DEoptim", "random", "ROI", "CVXR")) using the "dots" ... argument.

So it may already be possible to pass the parallel argument to CVXR::psolve via dots. This is how we pass parallel and other extra arguments to DEoptim already. Could you try to work up a minimal example of whether this works or not passing the parallel argument via dots?

For random portfolios, the most efficient method is likely the simplex method, which is unlikely to benefit much or at all from parallelization. The 'grid' method is also pretty efficient, as I recall. The sample method is the least efficient, but also supports arbitrary constraints. Without refreshing my memory on the code, which is several (many!) years old at this point, I think allowing parallelization in the sample method would be possible, but would definitely take some refactoring to break up the problem into multiple parallel streams.

@SteveBronder
Copy link
Author

So it may already be possible to pass the parallel argument to CVXR::psolve via dots. This is how we pass parallel and other extra arguments to DEoptim already. Could you try to work up a minimal example of whether this works or not passing the parallel argument via dots?

Yes with ... I think passing parallel is already possible. I'll make a mre switching out solve with psolve to see if that works.

The main thing for this issue is that when we call optimize.portfolio.rebalancing we set the number of threads outside of the function. Then inside of optimize.portfolio.rebalancing there is a foreachloop that, based on the number of threads available, does parallelization at the day level. Since their are only two levels of parallelization for this function (rebalancing periods and parallelization from within the optimizers) how would you feel about adding an argument like parallelize or parallelize_days that can be set to true or false? Or we could just have a string of days or model which would leave things open if we want to do something like parallelize over multiple portfolios

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

No branches or pull requests

2 participants