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

The algorithm does not find trends in the final intervals #11

Open
jackure opened this issue May 23, 2020 · 17 comments
Open

The algorithm does not find trends in the final intervals #11

jackure opened this issue May 23, 2020 · 17 comments
Assignees
Labels
bug Something isn't working

Comments

@jackure
Copy link

jackure commented May 23, 2020

What makes an algorithm like this attractive is being able to identify the current trend of the market.
However, in all tests I've done, the algorithm ignores the final intervals.
Below I show you the result of the algorithm with smoothed data, to further accentuate the phenomenon that I mentioned.

image

@alvarobartt
Copy link
Owner

alvarobartt commented Jun 28, 2020

Hi @jackure, thank you for reporting this!

I already need to perform some tests over this so as to identify the problem and find the best possible solution! Please, could you send me a CSV file containing the data that produced that concrete error? Or just the trendet function call that you made?

Thank you! Remember to star the repo if you found it useful and follow me at GitHub so as to get notified of all the updates!

@alvarobartt alvarobartt self-assigned this Jun 28, 2020
@alvarobartt alvarobartt added the bug Something isn't working label Jun 28, 2020
@mattstone
Copy link

Just adding to this.. something does look a bit broken with the trend identification algorithm.

This is the test data I've used.

test = investpy.get_stock_historical_data(stock='AAPL',
country='united states',
from_date='01/04/2020',
to_date='20/07/2020')

df = trendet.identify_df_trends(df=test, column='Close')

This is the result.

Screen Shot 2020-07-26 at 10 15 56 am

Also, the demonstration breaks if there is no downtrend (as in the above example). Quick fix highlighted in bold.

with plt.style.context('seaborn-paper'):
plt.figure(figsize=(20, 10))

ax = sns.lineplot(x=df['Date'], y=df['Close'])

**if 'Up Trend' in df.columns:**
  labels = df['Up Trend'].dropna().unique().tolist()

  for label in labels:
      sns.lineplot(x=df[df['Up Trend'] == label]['Date'],
                   y=df[df['Up Trend'] == label]['Close'],
                   color='green')

      ax.axvspan(df[df['Up Trend'] == label]['Date'].iloc[0],
                 df[df['Up Trend'] == label]['Date'].iloc[-1],
                 alpha=0.2,
                 color='green')

**if 'Down Trend' in df.columns:**
  labels = df['Down Trend'].dropna().unique().tolist()

  for label in labels:
      sns.lineplot(x=df[df['Down Trend'] == label]['Date'],
                   y=df[df['Down Trend'] == label]['Close'],
                   color='red')

      ax.axvspan(df[df['Down Trend'] == label]['Date'].iloc[0],
                 df[df['Down Trend'] == label]['Date'].iloc[-1],
                 alpha=0.2,
                 color='red')

plt.show()

@sunilhariharan
Copy link

Hi…i have fixed this….can i post an image of my code /the modified code ?

@yuvalfoox
Copy link

@sunilhariharan Can you please share your code?

@AliAlhajji
Copy link

I noticed the same issue too. When I change the to_date parameter to be in the middle of an area that was predicted as a trend, it does not identify it as a trend anymore.

Example:

image

And when I changed to_date to be in 30/06/2021, the uptrend was not identified:
image

You can try it with this stock:

Stock: 8240
Country: Saudi Arabia
From: "01/02/2021"
To (1): "08/08/2021"
To (2): "30/06/2021"
Window: 5

@sunilhariharan
Copy link

The bug is in the for loop…This algo will never be able to find the last upward and the last downward local trend.
In the for loop,when the limit is being compared to the value, what is happening is for the last updard n downward trend iteration, the algorithm is not able to get a value greater than the limit (in the elif part)…so it is not appending that trend

@AliAlhajji
Copy link

The bug is in the for loop…This algo will never be able to find the last upward and the last downward local trend.
In the for loop,when the limit is being compared to the value, what is happening is for the last updard n downward trend iteration, the algorithm is not able to get a value greater than the limit (in the elif part)…so it is not appending that trend

Were you able to fix it? Can you share the code if you did?

Thanks.

@sunilhariharan
Copy link

WhatsApp Image 2021-08-11 at 12 01 21 AM (6)

@sunilhariharan
Copy link

WhatsApp Image 2021-08-11 at 12 01 21 AM
WhatsApp Image 2021-08-11 at 12 01 21 AM (1)
WhatsApp Image 2021-08-11 at 12 01 21 AM (2)
WhatsApp Image 2021-08-11 at 12 01 21 AM (3)
WhatsApp Image 2021-08-11 at 12 01 21 AM (4)
WhatsApp Image 2021-08-11 at 12 01 21 AM (5)

@AliAlhajji
Copy link

Thansk @sunilhariharan !
If the code is working as expected, would you like to share it as a forked repo or a pull request?
It's hard to follow line by line here :)

@AliAlhajji
Copy link

Or at least copy and paste the code in here so that we can follow your logic easily.

@sunilhariharan

@yuvalfoox
Copy link

@sunilhariharan
Thanks for sharing!
Can you please share it as a repo or copy the full text as comment with example data?
I got a bit lost there :|
Thanks!

@jokaorgua
Copy link

@sunilhariharan could you share the code in text please?

jokaorgua added a commit to jokaorgua/trendet that referenced this issue Jan 17, 2022
…5 seconds timeout in tests to avoid getting 429 error from investing.com
@jokaorgua
Copy link

@alvarobartt I've made a pull request. please check it and if everything is ok - add to master

@AliAlhajji
Copy link

@alvarobartt I've made a pull request. please check it and if everything is ok - add to master

I tried your code. I don't think it's doing better than what we have now. I've back-tested it on several stocks, none of which showed uptrend towards the end even if there was one.

@jokaorgua
Copy link

@alvarobartt I've made a pull request. please check it and if everything is ok - add to master

I tried your code. I don't think it's doing better than what we have now. I've back-tested it on several stocks, none of which showed uptrend towards the end even if there was one.

Could you provide example data so I can backtest it too ?

@sunilhariharan
Copy link

@AliAlhajji did you try my code?

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

7 participants