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

linreg returns a wrong value #676

Closed
monkey0619 opened this issue Apr 3, 2023 · 6 comments
Closed

linreg returns a wrong value #676

monkey0619 opened this issue Apr 3, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@monkey0619
Copy link

monkey0619 commented Apr 3, 2023

Which version are you running? The lastest version is on Github. Pip is for major releases.
0.3.14b0

Do you have TA Lib also installed in your environment?
No

Have you tried the development version? Did it resolve the issue?
Not tried

Describe the bug
A wrong return. I checked the linreg help and found the following calculation formula.
return m * (length - 1) + b

The actual return is m * (length - 2) + b with coefficient of 10.0952380952381 and intercept of 11.1666666666667 for the first return 71.738095. In this case, length is 8 and (length - 2) equals 6.

To Reproduce

ta.linreg(pd.Series([10,25,33,38,49,61,72,84,99]), 8)
0          NaN
1          NaN
2          NaN
3          NaN
4          NaN
5          NaN
6          NaN
7    71.738095
8    84.023810

**Expected behavior**
0          NaN
1          NaN
2          NaN
3          NaN
4          NaN
5          NaN
6          NaN
7    81.8
8    94.6

Screenshots
圖片

Additional context
Add any other context about the problem here.

Thanks for using Pandas TA!

@monkey0619 monkey0619 added the bug Something isn't working label Apr 3, 2023
@twopirllc twopirllc removed their assignment Apr 3, 2023
@twopirllc
Copy link
Owner

Hello @monkey0619,

Thanks for sharing a potential solution for v0.3.14b. Furthermore, as mentioned in Issue #659:

The Linear Regression indicator, like many others, is due for an update as well as be rewritten using numpy to speed it up. ... Unfortunately there are too many things outstanding for one person to do. So hopefully someone can help by checking out the development branch and submit a PR to get this resolved sooner. 😎

Kind Regards,
KJ

@twopirllc
Copy link
Owner

@monkey0619,

You did not specify which library or trading platform it is incongruent with. Was it TA-Lib, TradingView, ToS, IBKR, MT4/5, Sierra, ... ?

Note: It is really hard to easily test anything but TA-Lib. TradingView requires a manual approach. Any others are even more cumbersome to compare. 😭

Thanks

@xieliaing
Copy link

xieliaing commented Jun 17, 2023

I compared the result with TA-Lib, his result is consistent with what's expected from TA-lib, see screenshot below:
image

When I get time, I could try to fix it, and do a PR/Contribution.

@xieliaing
Copy link

Looks like it requires tsf=True with all other parameter outputs such as "intercept", "r", etc., set to False to be compatible with TA-Lib. So TA-Lib output: m * length + b, not m * (length - 1) + b

image

@twopirllc
Copy link
Owner

@xieliaing

If TA Lib is installed, by default TA Lib will run. Thus it must be disabled using talib=False in the call.

Basic linreg with ta.linreg(close, length=8, talib=False) with the first Series is Pandas TA, the following is TA Lib.
Screenshot 2023-12-23 at 5 48 35 PM

Kind Regards,
KJ

Does this work as expected for you as well?

@xieliaing
Copy link

Thank you, KJ, it works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants