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

Do you plan to add portfolio-level functions? #20

Open
sstoeckl opened this issue Jun 18, 2024 · 8 comments
Open

Do you plan to add portfolio-level functions? #20

sstoeckl opened this issue Jun 18, 2024 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@sstoeckl
Copy link

sstoeckl commented Jun 18, 2024

Hey guys, I love your book (the R version) and am heavily using it in my teaching. It would help me a lot if your functions os single- and double-sorting portfolios as well as the rolling beta regressions etc. would be part of the package!

Do you plan on implementing them soon?

@sstoeckl sstoeckl changed the title Do youm plan to add portfolio-level functions? Do you plan to add portfolio-level functions? Jun 18, 2024
@christophscheuch
Copy link
Member

christophscheuch commented Jun 19, 2024

Thank you for your kind words @sstoeckl 🙏

We need to clarify the scope of such functions first.

For the portfolio sorts: I can think of a function that is called calculate_portfolio_returns() with parameters data, sorting_variables, n_portfolios, sorting_method (univarite, bivariate-depedent, bivariate-independent), lag_method (fama-frech, 6-months, mixed) and which returns a tibble with month, portfolio, ret_excess_vw, ret_excess_ew.

For the beta estimation: I think we need to add roll_capm_estimation() from the book and add a new function estimate_beta() with parameters data, factors (with default mkt_excess but support for multiple factors), months_lookback, min_obs n_cores (with default availableCores() - 1). This function would return a tibble with permno, month, beta (or beta_mkt_excess, beta_hml, beta_smb etc.).

Would this be sufficient?

@christophscheuch christophscheuch added the enhancement New feature or request label Jun 19, 2024
@christophscheuch christophscheuch self-assigned this Jun 19, 2024
@sstoeckl
Copy link
Author

Hi @christophscheuch thanks for your prompt reply and the suggestions!

If I could come up with a wish, then I would also add fama-macbeth regressions (price_of_risk - I understand that this is not straightforward, as it requires nesting data appropriately, etc).

@voigtstefan
Copy link
Member

Thank you for your kind words @sstoeckl 🙏

We need to clarify the scope of such functions first.

For the portfolio sorts: I can think of a function that is called calculate_portfolio_returns() with parameters data, sorting_variables, n_portfolios, sorting_method (univarite, bivariate-depedent, bivariate-independent), lag_method (fama-frech, 6-months, mixed) and which returns a tibble with month, portfolio, ret_excess_vw, ret_excess_ew.

For the beta estimation: I think we need to add roll_capm_estimation() from the book and add a new function estimate_beta() with parameters data, factors (with default mkt_excess but support for multiple factors), months_lookback, min_obs n_cores (with default availableCores() - 1). This function would return a tibble with permno, month, beta (or beta_mkt_excess, beta_hml, beta_smb etc.).

Would this be sufficient?

Presumably there should also be a distinction between the data and used to build portfolios and the data used to build breakpoints - but I am a bit unsure how to map this to general use cases that go beyond listing exchanges.

@christophscheuch
Copy link
Member

@voigtstefan can you give me specific examples where the data for portfolios and breakpoints are different?

I started drafting the calculate_portfolio_returns() function today and also think it makes more sense to make it narrower. For instance, the lag method should probably not be in the scope of the function because the lags might depend on the corresponding variable.

@voigtstefan
Copy link
Member

Example: breakpoints based on NYSE listed stocks and sorting based on all CRSP stocks. For that reason we split the chain in tidy-finance.org and first computed breakpoints, then applied those.

Not sure if there are other use cases but the one above is definitely relevant. We may have an optional additional argument which takes a 2nd dataset (e.g. filter by listing_exchange==NYSE) to compute breakpoints based on that one. If the argument is empty, just use the default dataset. That way, users can provide their own fancy distinction between breakpoints computation and portfolio construction.

@voigtstefan
Copy link
Member

To clarify: the argument could be "breakpoint_data = data", defaulting to data.

@christophscheuch
Copy link
Member

Maybe another scenario is creating breakpoints based on US stocks and using these to sort European stocks (not sure how much sense that makes though). Just to keep it here as another potential case to consider when designing the functions.

@patrick-weiss
Copy link
Member

I made a first draft of some functions as the basis for further discussions. The idea is to allow for single, dependent double, and independent double sorts both with monthly and annual rebalancing (portfolios assigned in June).

Supplying external breakpoints seems possible by changing the assign_portfolio() function accordingly. Would we want to do this for all flavors of the portfolio sort? I think this puts some strain on the definition of such breakpoints, particularly for dependent sorts.

Additionally, I want to supply a function to lag variables and merge them back. Probably, this is useful beyond portfolio sorts.

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

When branches are created from issues, their pull requests are automatically linked.

4 participants