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

Error when rebalancing with only one stock #65

Closed
atobiese opened this issue Feb 1, 2022 · 5 comments
Closed

Error when rebalancing with only one stock #65

atobiese opened this issue Feb 1, 2022 · 5 comments

Comments

@atobiese
Copy link

atobiese commented Feb 1, 2022

Hi,
I have tried to reproduce test results and simulated one single stock over time by forcing the weight distribution as shown below:
tickers = ["stock1", "stock2"]
weights_new_ = [1.0, 0.0]
no optimizer is used, so just using the quantstats calculations of ratios and returns.
In the next example, we do the same but with a yearly rebalancer. The thing here is that the results should be exactly the same.
There seems to be a slight error in the returns calculations over time, which turns out to be bigger with more rebalancing.

I will have some more look at it, and update if I find the bug. Btw great work!

@ssantoshp
Copy link
Owner

Hey,

Sorry, for the late reply?
There is no purpose in rebalancing only one stock. The weight will stay the same.
Hope it helps!

@atobiese
Copy link
Author

Hi, of course, but the point I was trying to make is that there is a math error. The end value is NOT the same here. This means that when using more than one stock), the rebalancing will create large errors.
The test for this is simply rebalancing with two stocks, where the second weight is zero. The result should be exactly the same, since a perfentage of zero is zero. So since this result is different than the single stock, the math is not correct.

@ssantoshp
Copy link
Owner

Sorry!! My fault, I misinterpreted the issue. If you find the bug, pin me! I'll also look at the code to see where is the problem coming from 😟
Thanks for reporting this issue!

@atobiese
Copy link
Author

I haven't looked at the code for a while, but it could be the precision of the calculations in pypfopt, resulting in rounding erros outside after several balancers. Errors grow fast as I remember. May need higher precision. Could be a summation error etc. I'll have a look if I get time. Regards

@ssantoshp
Copy link
Owner

ssantoshp commented May 22, 2022

This #72 pull request solved it
You can install Empyrial 2.0.1 and it should work!

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