Open jackure opened 4 years ago
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!
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.
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()
Hi…i have fixed this….can i post an image of my code /the modified code ?
@sunilhariharan Can you please share your code?
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:
And when I changed to_date
to be in 30/06/2021, the uptrend was not identified:
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
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
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.
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 :)
Or at least copy and paste the code in here so that we can follow your logic easily.
@sunilhariharan
@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!
@sunilhariharan could you share the code in text please?
@alvarobartt I've made a pull request. please check it and if everything is ok - add to master
@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.
@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 ?
@AliAlhajji did you try my code?
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.