trendet icon indicating copy to clipboard operation
trendet copied to clipboard

The algorithm does not find trends in the final intervals

Open jackure opened this issue 4 years ago • 17 comments

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

jackure avatar May 23 '20 16:05 jackure

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 avatar Jun 28 '20 17:06 alvarobartt

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()

mattstone avatar Jul 26 '20 00:07 mattstone

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

sunilhariharan avatar Jul 15 '21 16:07 sunilhariharan

@sunilhariharan Can you please share your code?

yuvalfoox avatar Jul 24 '21 15:07 yuvalfoox

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

AliAlhajji avatar Aug 10 '21 13:08 AliAlhajji

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

sunilhariharan avatar Aug 10 '21 17:08 sunilhariharan

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.

AliAlhajji avatar Aug 10 '21 18:08 AliAlhajji

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

sunilhariharan avatar Aug 10 '21 18:08 sunilhariharan

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)

sunilhariharan avatar Aug 10 '21 18:08 sunilhariharan

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 avatar Aug 10 '21 19:08 AliAlhajji

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

@sunilhariharan

AliAlhajji avatar Aug 11 '21 18:08 AliAlhajji

@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!

yuvalfoox avatar Sep 08 '21 19:09 yuvalfoox

@sunilhariharan could you share the code in text please?

jokaorgua avatar Jan 17 '22 13:01 jokaorgua

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

jokaorgua avatar Jan 17 '22 15:01 jokaorgua

@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.

AliAlhajji avatar Jan 27 '22 17:01 AliAlhajji

@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 ?

jokaorgua avatar Jan 27 '22 18:01 jokaorgua

@AliAlhajji did you try my code?

sunilhariharan avatar Apr 29 '22 17:04 sunilhariharan