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

comp_cumulative_returns() weird behaviour #65

Open
opoloko opened this issue Jan 22, 2021 · 3 comments
Open

comp_cumulative_returns() weird behaviour #65

opoloko opened this issue Jan 22, 2021 · 3 comments

Comments

@opoloko
Copy link

opoloko commented Jan 22, 2021

Hi

I do have a portfolio where some of the stocks have data starting at different time (some are more recent). I build my own Dataframe, so it's made to have an index that is date, and then if one stock still has no data when another one has, for that date the value for the stock still not started will be 0.0.

I then use FinQuant, giving it my Dataframe with the stocks and another with the weights, and do all calculations I need.

It works in every aspects I use, and I use pretty much all the functions, but one function, comp_cumulative_returns() fails to deal correctly with the data. If one of the stocks in portfolio starts later than the others, and so in the dataframe the prices for that stock are 0.0 till the 'real' data starts, that function doesn't work and the resulting output has 0.0 for the whole sequence of that specific stock.

Any hint about how to deal with this case?

@opoloko
Copy link
Author

opoloko commented Jan 23, 2021

Ok did more tests. If leaving NaN it works, but it does cut any previous data not available, so it only calculates the date range that is common across all stocks in portfolio. I had a look at function, and it uses dropna() to cut, that's not ideal I think.

Solution is to use bfill() in the input dataframe before passing it to portfolio, that way any NaN value (for stocks starting later than others in portfolio) are filled with the first known price, and volatility and returns are correctly calculated and considered 0.

@vanderheijden86
Copy link

vanderheijden86 commented Jan 25, 2021

Hi @opoloko, I'm currently also using this repo to do some portfolio analysis. I think I will encounter the same issue as you do above. Thanks for your reply to the question. Another issue that you could be facing, and I will be facing, is on re-balancing the portfolio. In real-life I would rebalance my portfolio on a yearly basis, yet there is no function to do this. Is this not necessary given the way it calculates returns? Or do you think we would need to implement this re-balancing as well to get a realistic result? Thanks already.

@opoloko
Copy link
Author

opoloko commented Jan 25, 2021

That's another good point indeed. Although rebalancing makes a difference, I tend to do it as little as possible (in real life and in analysis tools).

I definitely think would be nice to have it, but I also use Finquant mostly for pure quantitative/statistic analytics more than a way to calculate a 'real' returns, if you know what I mean.

In a way leaving rebalancing out and having a simple buy&hold makes things more straightforward. But yes I agree would be a nice feature to have.

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

2 participants