Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ from sklearn.cluster import AgglomerativeClustering
|
|
7 |
import streamlit as st
|
8 |
import requests
|
9 |
from streamlit_lottie import st_lottie
|
|
|
10 |
|
11 |
st.set_page_config(page_title = "Support and resistance levels",
|
12 |
page_icon = ':π:',
|
@@ -14,6 +15,11 @@ st.set_page_config(page_title = "Support and resistance levels",
|
|
14 |
|
15 |
st.title('π Technical analysis π')
|
16 |
st.header('Find support and resistance levels for :blue[price action] analysis!')
|
|
|
|
|
|
|
|
|
|
|
17 |
st.markdown('##')
|
18 |
|
19 |
def load_lottieurl(url: str):
|
@@ -27,33 +33,42 @@ lottie_money = load_lottieurl(lottie_url__money)
|
|
27 |
|
28 |
st.sidebar.header('Please choose parameters: ')
|
29 |
|
30 |
-
ticker = st.text_input('Select stock to analyse:
|
|
|
|
|
31 |
|
32 |
-
interval =
|
|
|
|
|
33 |
|
34 |
-
|
35 |
-
'Select a number of clusters',
|
36 |
-
options=[i for i in range(1,8)])
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
(
|
41 |
-
options=[i for i in range(5, 21)])
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
|
47 |
-
|
48 |
-
df =
|
49 |
-
df.index = pd.to_datetime(df.index).strftime("%d-%m-%Y %H:%M")
|
50 |
df = df.drop(columns = ["Adj Close"])
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
left_column, right_column = st.columns(2)
|
53 |
|
54 |
left_column.markdown('<span style="font-size:20px; font-weight:600; letter-spacing:2px;">Preview data:</span>',
|
55 |
unsafe_allow_html = True)
|
56 |
-
left_column.dataframe(df, height = 400)
|
57 |
|
58 |
with right_column:
|
59 |
st_lottie(lottie_money, key="money")
|
@@ -98,20 +113,6 @@ fig.add_trace(go.Candlestick(x=df.index,
|
|
98 |
low=df['Low'],
|
99 |
close=df['Close'], name = "Market data"), row = 1, col = 1)
|
100 |
|
101 |
-
fig.update_xaxes(
|
102 |
-
rangeslider_visible = False,
|
103 |
-
rangeselector=dict(
|
104 |
-
buttons=list([
|
105 |
-
dict(count=1, label="1d",
|
106 |
-
step="day", stepmode="backward"),
|
107 |
-
dict(count=3, label="3d",
|
108 |
-
step="day", stepmode="backward"),
|
109 |
-
dict(count=7, label="7d",
|
110 |
-
step="day", stepmode="backward"),
|
111 |
-
dict(count=30, label="30d",
|
112 |
-
step="day", stepmode="backward"),
|
113 |
-
dict(step="all")])))
|
114 |
-
|
115 |
i = 0
|
116 |
for level in support_resistance_levels.to_list():
|
117 |
fig.add_hline(y=level, line_width=1,
|
@@ -119,6 +120,9 @@ for level in support_resistance_levels.to_list():
|
|
119 |
line_color="snow")
|
120 |
i += 1
|
121 |
|
|
|
|
|
|
|
122 |
colors = []
|
123 |
|
124 |
for i in range(len(df.Close)):
|
@@ -144,4 +148,37 @@ fig.update_layout(
|
|
144 |
x=0))
|
145 |
|
146 |
#show chart
|
147 |
-
st.plotly_chart(fig, use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
import streamlit as st
|
8 |
import requests
|
9 |
from streamlit_lottie import st_lottie
|
10 |
+
import datetime
|
11 |
|
12 |
st.set_page_config(page_title = "Support and resistance levels",
|
13 |
page_icon = ':π:',
|
|
|
15 |
|
16 |
st.title('π Technical analysis π')
|
17 |
st.header('Find support and resistance levels for :blue[price action] analysis!')
|
18 |
+
st.markdown('''<span style="font-size:18px; font-weight:500;">
|
19 |
+
This demo includes an implemented <em>Agglomerative Clustering</em>
|
20 |
+
algorithm that can assist you in automatically detecting
|
21 |
+
potential support and resistance levels in financial markets.
|
22 |
+
</span>''', unsafe_allow_html = True)
|
23 |
st.markdown('##')
|
24 |
|
25 |
def load_lottieurl(url: str):
|
|
|
33 |
|
34 |
st.sidebar.header('Please choose parameters: ')
|
35 |
|
36 |
+
ticker = st.text_input('''Select stock to analyse:
|
37 |
+
(Make sure the ticker you search for is supported
|
38 |
+
by _Yahoo! Finance_).''', 'BNB-USD')
|
39 |
|
40 |
+
interval = st.sidebar.selectbox(
|
41 |
+
'Select the time interval',
|
42 |
+
('1d', '5d', '1wk', '1mo', '3mo'))
|
43 |
|
44 |
+
timedelta = {'1d': 1, '5d': 5, '1wk' : 7, '1mo' : 30, '3mo' : 90}
|
|
|
|
|
45 |
|
46 |
+
start = st.sidebar.date_input(
|
47 |
+
"Select the beginning date",
|
48 |
+
datetime.date(2022, 1, 1))
|
|
|
49 |
|
50 |
+
end = st.sidebar.date_input(
|
51 |
+
"Select the ending date",
|
52 |
+
datetime.date(2023, 1, 1), min_value = start + datetime.timedelta(timedelta[interval]))
|
53 |
|
54 |
+
df = yf.download(ticker, start = start, end = end, interval = interval)
|
55 |
+
df.index = pd.to_datetime(df.index).strftime("%d-%m-%Y")
|
|
|
56 |
df = df.drop(columns = ["Adj Close"])
|
57 |
|
58 |
+
num_clusters = st.sidebar.slider(
|
59 |
+
'Select the number of clusters (affects number of levels you will get)',
|
60 |
+
1, 7, 3)
|
61 |
+
|
62 |
+
rolling_wave_length = st.sidebar.slider(
|
63 |
+
'''Select the length of rolling wave
|
64 |
+
(select more the more long-term biased you are)''',
|
65 |
+
1, len(df)//5, 1)
|
66 |
+
|
67 |
left_column, right_column = st.columns(2)
|
68 |
|
69 |
left_column.markdown('<span style="font-size:20px; font-weight:600; letter-spacing:2px;">Preview data:</span>',
|
70 |
unsafe_allow_html = True)
|
71 |
+
left_column.dataframe(df, height = 400, use_container_width=True)
|
72 |
|
73 |
with right_column:
|
74 |
st_lottie(lottie_money, key="money")
|
|
|
113 |
low=df['Low'],
|
114 |
close=df['Close'], name = "Market data"), row = 1, col = 1)
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
i = 0
|
117 |
for level in support_resistance_levels.to_list():
|
118 |
fig.add_hline(y=level, line_width=1,
|
|
|
120 |
line_color="snow")
|
121 |
i += 1
|
122 |
|
123 |
+
fig.update_xaxes(
|
124 |
+
rangeslider_visible = False)
|
125 |
+
|
126 |
colors = []
|
127 |
|
128 |
for i in range(len(df.Close)):
|
|
|
148 |
x=0))
|
149 |
|
150 |
#show chart
|
151 |
+
st.plotly_chart(fig, use_container_width=True)
|
152 |
+
|
153 |
+
st.markdown("""<span style="font-size:13px; font-weight:400;">
|
154 |
+
Disclaimer: It's important to note that while this demonstration provides a useful approach to
|
155 |
+
identifying support and resistance levels in financial markets,
|
156 |
+
it is not intended to be taken as financial advice.
|
157 |
+
Trading decisions should be made based on careful analysis of multiple factors,
|
158 |
+
including market conditions,
|
159 |
+
risk tolerance,
|
160 |
+
and individual financial goals.
|
161 |
+
</span>""", unsafe_allow_html=True)
|
162 |
+
|
163 |
+
hide_streamlit_style = """
|
164 |
+
<style>
|
165 |
+
footer {visibility: hidden;}
|
166 |
+
</style>
|
167 |
+
"""
|
168 |
+
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
169 |
+
|
170 |
+
st.markdown('''
|
171 |
+
<div style="position: relative; bottom: -180px; width: 100%;">
|
172 |
+
<span class="e1_33">
|
173 |
+
<p style="text-align:center">
|
174 |
+
Designed with β€οΈ by
|
175 |
+
<a href="https://www.linkedin.com/in/amelia-doli%C5%84ska-55613a270/">
|
176 |
+
<em>
|
177 |
+
Amelia DoliΕska
|
178 |
+
</em>
|
179 |
+
</a>
|
180 |
+
</p>
|
181 |
+
</span>
|
182 |
+
</div>
|
183 |
+
''',
|
184 |
+
unsafe_allow_html=True)
|