robertmartin8 / PyPortfolioOpt

Financial portfolio optimisation in python, including classical efficient frontier, Black-Litterman, Hierarchical Risk Parity
https://pyportfolioopt.readthedocs.io/
MIT License
4.38k stars 940 forks source link

Feature request: Logging #364

Closed skullgoblet1089 closed 2 years ago

skullgoblet1089 commented 3 years ago

Awesome library! One feature that would be extremely useful is more logging / transparency into status of optimizations. Is this already planned in future releases?

Is your feature request related to a problem? Many optimization methods are long running and opaque wrt status.

Describe the feature you'd like Rather than the "verbose" switch on a subset of methods, use python's logging module to implement "debug" level messages which a user may enable via the built-in logging api.

Additional context N/A

robertmartin8 commented 3 years ago

Hi @skullgoblet1089,

Thanks for the suggestion!

PyPortfolioOpt is essentially a wrapper around CVXPY – so is only able to provide as much logging as CVXPY provides. That's why the verbose pattern is used, even though it's a bit clunky.

Do you have any specific comments on the "opaque" aspect of the optimiser? I'll try to have a think about what can be done on the PyPortfolioOpt side of things.

I'm not too familiar with the logging module from the perspective of a package designer (I'm in the bad habit of using print to debug 😭), but it's something I should read more about!

skullgoblet1089 commented 3 years ago

Thanks, @robertmartin8!

Good to know, let me try debugging cvxpy to see if that is good enough. Re "opaque": For a test I tried running several optimizations for a large portfolio with 100's of assets. The optimizations did eventually succeed after running for ~15 minutes, but someone else may have closed their console assuming something went wrong. All good, if you don't hear from me again cvxpy debugging worked well. Otherwise I'll send a PR your way.

robertmartin8 commented 3 years ago

@skullgoblet1089

someone else may have closed their console assuming something went wrong

Did verbose=True not print a log with the status of the solver?

skullgoblet1089 commented 3 years ago

The class / methods that are longest running and I can't find a verbose option for are: pypfopt.CLA [.min_volatility, .max_sharpe]. I'm new to your package's api maybe I missed something?

import pypfopt
mu = ...
S = ...
cla = pypfopt.CLA(mu, S, weight_bounds=(-0.99999, 0.99999))
w_minvol = cla.min_volatility()
robertmartin8 commented 3 years ago

@skullgoblet1089

Ah so the CLA implementation is not based on CVXPY, it is essentially Marcos Lopez de Prado's implementation verbatim.

I'm actually considering removing it or at least rewriting it, because the code is quite hard to maintain. Is there a particular reason why you aren't using EfficientFrontier instead?

robertmartin8 commented 2 years ago

Closing because stale – feel free to reopen if needed