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

Calling cov_pred_finance from cvx_portfolio? #83

Open
enzbus opened this issue Jul 15, 2023 · 3 comments
Open

Calling cov_pred_finance from cvx_portfolio? #83

enzbus opened this issue Jul 15, 2023 · 3 comments

Comments

@enzbus
Copy link

enzbus commented Jul 15, 2023

Hello @tschm and @kasperjo. I've been looking at this repository and your paper and I think it would be easy to write a class that wraps the functionality you provide to integrate in cvxportfolio. In the simplest case it would be something like

class CvxCovariance(BaseForecast):
    def __init__(self, **all_your_hyperparameters):
        # save the hyperparameters
        ...
    def _pre_evaluation(self, universe, *args):
        # initialize your objects knowing the size of the universe
        ...
    def _values_in_time(self, past_returns, **kwargs):
        # do the computation for covariance at time t knowing past returns (up to time t-1)
        ...
        return sqrt_Sigma  # so that Sigma = sqrt_Sigma.T @ sqrt_Sigma

It would be invoked simply by the user and operate completely independently, so the user doesn't have to worry about passing data in the right format, .... (See the examples to see what I mean.) All the cvxpy operations are done from cvxportfolio, and it also takes care of adding and removing assets from the universe as IPOs and bankruptcies happen.

I'm not sure if your method is safe against missing values (past_returns could have nan at the top of some of the columns) but if not you can just throw an error if the user provides such data.

This could even just be in your examples (or cvxportfolio's) and not in any package proper, to not change dependencies.

If you want I can help you to interface with some more of the more advanced facilities, like multi-period forecasting (provide forecast at time t for covariance at time t+tau), on- and off-line caching (which saves on disk expensive computation, safely against parallel execution), ....

@tschm
Copy link
Collaborator

tschm commented Jul 16, 2023

@enzbus Thank you for that.

Dealing with NaNs is an interesting question. I don't want to throw an error if an asset joins later. At the same time I don't want to interpolate its missing history with zero returns (in particular before an asset awakes)

Also, I want to avoid dictating how we treat missing values. It's the responsibility of the user to submit good estimates and make the combination exercise not falling over if a covariance matrix contains a NaN row and a NaN column (enough to check the diagonal). This is simple with pandas.

I doubt it would be a good idea to create a dependency on cvxportfolio within cov_pred_finance (BaseForecast?).
We could add a simple iterator (over time) combining covariance matrices and yielding an estimate for each time t.
It should be easy to use this within cvxportfolio.

@stephenpboyd
Copy link
Collaborator

stephenpboyd commented Jul 16, 2023 via email

@enzbus
Copy link
Author

enzbus commented Nov 22, 2023

Bumping this; in the meantime cvxportfolio's interface has got cleaner, but the code snippet from above is still about right. Do you think it's possible to provide the functionality of cvxcovariance following that API? (See https://github.com/cvxgrp/cvxportfolio/blob/master/examples/user_provided_forecasters.py for a full example.) Thanks @tschm @kasperjo .

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

3 participants