alvarobartt/trendet

Trying to apply example on my own data

thebadguyfromstarwars opened this issue · 2 comments

As you can see above - the bold code is of my own making. I'm taking a column, predicted_stock_data[:,0], from a dataframe to use a the closing price. I then add the 'Date'. I can't grasp the problem with 'Date'.

res = predicted_stock_data[:,0]
des = pd.DataFrame(res, columns = ['Close'])
start = datetime(2018, 9, 29)
dates = pd.date_range(start, periods=100).to_pydatetime().tolist()
des['Dates'] = dates
res = trendet.identify_df_trends(df=des, column='Close')

with plt.style.context('classic'):
plt.figure(figsize=(20, 10))
ax = sns.lineplot(x=res['Date'], y=res['Close'])

labels = res['Up Trend'].dropna().unique().tolist()

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

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

labels = res['Down Trend'].dropna().unique().tolist()

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

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

plt.show()

err

err2

Having this peculiar issue now.. hmm..

use this DataFrame format
image

Date is the index, and its type shoud be date not str