-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.py
52 lines (37 loc) · 1.39 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pytrend
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style='darkgrid')
df = pytrend.identify_all_trends(stock='AAPl',
from_date='06/01/2020',
to_date='04/01/2021',
window_size=5,
identify='both')
df.reset_index(inplace=True)
plt.figure(figsize=(20, 10))
ax = sns.lineplot(x=df.index, y=df['Close'])
ax.set(xlabel='Date')
labels = df['Up Trend'].dropna().unique().tolist()
for label in labels:
sns.lineplot(x=df[df['Up Trend'] == label].index,
y=df[df['Up Trend'] == label]['Close'],
color='green')
ax.axvspan(df[df['Up Trend'] == label].index[0],
df[df['Up Trend'] == label].index[-1],
alpha=0.2,
color='green')
labels = df['Down Trend'].dropna().unique().tolist()
for label in labels:
sns.lineplot(x=df[df['Down Trend'] == label].index,
y=df[df['Down Trend'] == label]['Close'],
color='red')
ax.axvspan(df[df['Down Trend'] == label].index[0],
df[df['Down Trend'] == label].index[-1],
alpha=0.2,
color='red')
locs, _ = plt.xticks()
labels = []
for position in locs[1:-1]:
labels.append(str(df['Date'].loc[position])[:-9])
plt.xticks(locs[1:-1], labels)
plt.show()