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

Add Return.portfolio.withdrops() #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cortinah
Copy link
Contributor

Hello, hoping to contribute this new function which wraps Return.portfolio().
Return.portfolio.withdrops() handles cases when the assets have variable-length histories. For example, a security in the portfolio could have a shorter history than others due to M&A or delisting. Currently, Return.portfolio warns and assigns a zero return to such securities with missing returns. This may not always be ideal. This function forces a rebalance when security returns become unavailable, excluding such securities. It splices together spans with all available assets in each period, using Return.portfolio() to calculate returns in each span of complete assets. It returns a complete portfolio return, with all available assets at any time. Welcome any suggestions to improve it.

Improved verbose and documented


Edit docs
@braverock
Copy link
Owner

why wouldn't you pass a time series of weights ?

I'm trying to understand what you're getting at here.

It seems to me a more common case would be series that start later than the longest series, e.g. ETF's that weren't listed yet, or symbols that are created by a spin-off of a subsidiary or division, or new series of a futures contract.

@cortinah
Copy link
Contributor Author

Thank you very much for your comments. The use case here is as follows: You have a portfolio of a few hundred stocks and you wish to calculate the daily portfolio return for a year or two. You can easily lose 10-20% of the securities to corp actions over this period, on random days. The portfolio is either equal weighted, or rebalanced to a vector of fixed weights on a monthly basis. Therefore you don't have an xts weights object. Creating one for each of the days when assets stop trading is tedious. This proposed function will take care of all the work for you. You just run it and the entire portfolio returns series is created for you, and you don't have to handle the asset drops. I hope this makes sense.

I completely agree regarding your second comment about adding securities as they become available for trading at later dates. I've also written a prototype of a function that does that and hope to share soon. Thank you.

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

Successfully merging this pull request may close these issues.

2 participants