Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,52 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
3 |
-
import
|
4 |
-
|
5 |
-
|
6 |
import datetime
|
7 |
-
import streamlit as st
|
8 |
|
9 |
-
#
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
1 |
import streamlit as st
|
2 |
+
import yfinance as yf
|
3 |
+
import pandas as pd
|
4 |
+
import cufflinks as cf
|
|
|
5 |
import datetime
|
|
|
6 |
|
7 |
+
# App title
|
8 |
+
st.markdown('''
|
9 |
+
# Stock Price App
|
10 |
+
Shown are the stock price data for query companies!
|
11 |
+
|
12 |
+
**Credits**
|
13 |
+
- App built by [Chanin Nantasenamat](https://medium.com/@chanin.nantasenamat) (aka [Data Professor](http://youtube.com/dataprofessor))
|
14 |
+
- Built in `Python` using `streamlit`,`yfinance`, `cufflinks`, `pandas` and `datetime`
|
15 |
+
''')
|
16 |
+
st.write('---')
|
17 |
+
|
18 |
+
# Sidebar
|
19 |
+
st.sidebar.subheader('Query parameters')
|
20 |
+
start_date = st.sidebar.date_input("Start date", datetime.date(2019, 1, 1))
|
21 |
+
end_date = st.sidebar.date_input("End date", datetime.date(2021, 1, 31))
|
22 |
+
|
23 |
+
# Retrieving tickers data
|
24 |
+
ticker_list = pd.read_csv('https://raw.githubusercontent.com/dataprofessor/s-and-p-500-companies/master/data/constituents_symbols.txt')
|
25 |
+
tickerSymbol = st.sidebar.selectbox('Stock ticker', ticker_list) # Select ticker symbol
|
26 |
+
tickerData = yf.Ticker(tickerSymbol) # Get ticker data
|
27 |
+
tickerDf = tickerData.history(period='1d', start=start_date, end=end_date) #get the historical prices for this ticker
|
28 |
+
|
29 |
+
# Ticker information
|
30 |
+
string_logo = '<img src=%s>' % tickerData.info['logo_url']
|
31 |
+
st.markdown(string_logo, unsafe_allow_html=True)
|
32 |
+
|
33 |
+
string_name = tickerData.info['longName']
|
34 |
+
st.header('**%s**' % string_name)
|
35 |
|
36 |
+
string_summary = tickerData.info['longBusinessSummary']
|
37 |
+
st.info(string_summary)
|
38 |
|
39 |
+
# Ticker data
|
40 |
+
st.header('**Ticker data**')
|
41 |
+
st.write(tickerDf)
|
42 |
|
43 |
+
# Bollinger bands
|
44 |
+
st.header('**Bollinger Bands**')
|
45 |
+
qf=cf.QuantFig(tickerDf,title='First Quant Figure',legend='top',name='GS')
|
46 |
+
qf.add_bollinger_bands()
|
47 |
+
fig = qf.iplot(asFigure=True)
|
48 |
+
st.plotly_chart(fig)
|
49 |
|
50 |
+
####
|
51 |
+
#st.write('---')
|
52 |
+
#st.write(tickerData.info)
|