Spaces:
Runtime error
Runtime error
Upload main.py
Browse files
main.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from stocks import *
|
2 |
+
from functions import *
|
3 |
+
from datetime import datetime
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
st.set_page_config(layout="wide")
|
7 |
+
|
8 |
+
st.title("Tech Stocks Trading Assistant")
|
9 |
+
|
10 |
+
left_column, right_column = st.columns(2)
|
11 |
+
|
12 |
+
with left_column:
|
13 |
+
|
14 |
+
all_tickers = {
|
15 |
+
"Apple":"AAPL",
|
16 |
+
"Microsoft":"MSFT",
|
17 |
+
"Nvidia":"NVDA",
|
18 |
+
"Paypal":"PYPL",
|
19 |
+
"Amazon":"AMZN",
|
20 |
+
"Spotify":"SPOT",
|
21 |
+
"Twitter":"TWTR",
|
22 |
+
"AirBnB":"ABNB",
|
23 |
+
"Uber":"UBER",
|
24 |
+
"Google":"GOOG"
|
25 |
+
}
|
26 |
+
|
27 |
+
st.subheader("Technical Analysis Methods")
|
28 |
+
option_name = st.selectbox('Choose a stock:', all_tickers.keys())
|
29 |
+
option_ticker = all_tickers[option_name]
|
30 |
+
execution_timestamp = datetime.now()
|
31 |
+
'You selected: ', option_name, "(",option_ticker,")"
|
32 |
+
'Last execution:', execution_timestamp
|
33 |
+
|
34 |
+
s = Stock_Data()
|
35 |
+
t = s.Ticker(tick=option_ticker)
|
36 |
+
|
37 |
+
m = Models()
|
38 |
+
|
39 |
+
with st.spinner('Loading stock data...'):
|
40 |
+
|
41 |
+
technical_analysis_methods_outputs = {
|
42 |
+
'Technical Analysis Method': [
|
43 |
+
'Bollinger Bands (20 days & 2 stand. deviations)',
|
44 |
+
'Bollinger Bands (10 days & 1.5 stand. deviations)',
|
45 |
+
'Bollinger Bands (50 days & 3 stand. deviations)',
|
46 |
+
'Moving Average Convergence Divergence (MACD)'
|
47 |
+
],
|
48 |
+
'Outlook': [
|
49 |
+
m.bollinger_bands_20d_2std(t),
|
50 |
+
m.bollinger_bands_10d_1point5std(t),
|
51 |
+
m.bollinger_bands_50d_3std(t),
|
52 |
+
m.MACD(t)
|
53 |
+
],
|
54 |
+
'Timeframe of Method': [
|
55 |
+
"Medium-term",
|
56 |
+
"Short-term",
|
57 |
+
"Long-term",
|
58 |
+
"Short-term"
|
59 |
+
]
|
60 |
+
}
|
61 |
+
|
62 |
+
df = pd.DataFrame(technical_analysis_methods_outputs)
|
63 |
+
|
64 |
+
|
65 |
+
def color_survived(val):
|
66 |
+
color = ""
|
67 |
+
if (val=="Sell" or val=="Downtrend and sell signal" or val=="Downtrend and no signal"):
|
68 |
+
color="#EE3B3B"
|
69 |
+
elif (val=="Buy" or val=="Uptrend and buy signal" or val=="Uptrend and no signal"):
|
70 |
+
color="#3D9140"
|
71 |
+
else:
|
72 |
+
color="#CD950C"
|
73 |
+
return f'background-color: {color}'
|
74 |
+
|
75 |
+
|
76 |
+
st.table(df.sort_values(['Timeframe of Method'], ascending=False).
|
77 |
+
reset_index(drop=True).style.applymap(color_survived, subset=['Outlook']))
|
78 |
+
|
79 |
+
with right_column:
|
80 |
+
|
81 |
+
st.subheader("FinBERT-based Sentiment Analysis")
|
82 |
+
|
83 |
+
with st.spinner("Connecting with www.marketwatch.com..."):
|
84 |
+
st.plotly_chart(m.finbert_headlines_sentiment(t)["fig"])
|
85 |
+
"Current sentiment:", m.finbert_headlines_sentiment(t)["current_sentiment"], "%"
|
86 |
+
|
87 |
+
st.subheader("LSTM-based 7-day stock price prediction model")
|
88 |
+
|
89 |
+
with st.spinner("Compiling LSTM model.."):
|
90 |
+
st.plotly_chart(m.LSTM_7_days_price_predictor(t))
|
91 |
+
|