Created
March 24, 2023 10:03
-
-
Save sfc-gh-mnowotka/72be478afc1593792280cd94db97597c to your computer and use it in GitHub Desktop.
Demo code used at PyWaw #103
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import date | |
from dateutil.relativedelta import relativedelta | |
import streamlit as st | |
import yfinance as yf | |
st.title("Demo App!") | |
st.header(":snake: pyWaw demo") | |
st.write("---") | |
POPULAR_STOCKS = ["TSLA", "AAPL", "AMZN", "MSFT", "META", "GOOGL", "SNOW", | |
"NVDA", "NFLX", "PLTR", "INTC", "COIN", "ADBE", "ZM"] | |
today = date.today() | |
two_years_ago = today - relativedelta(years=2) | |
if "tickers" not in st.session_state: | |
st.session_state["tickers"] = ["SNOW", "COIN"] | |
if "dates" not in st.session_state: | |
st.session_state["dates"] = [today - relativedelta(years=2), today] | |
if "interval" not in st.session_state: | |
st.session_state["interval"] = "1d" | |
tickers = st.multiselect("Choose ticker", POPULAR_STOCKS, | |
key="tickers") | |
start, end = st.slider("Date range:", key="dates") | |
interval = st.select_slider("Interval", ["1d", "5d", "1wk","1mo", "3mo"], | |
key="interval") | |
data = yf.Tickers(" ".join(tickers)) | |
df = data.history(start=start, end=end, interval=interval) | |
with st.expander("Raw data"): | |
st.write(df) | |
st.line_chart(df.Close) | |
st.line_chart(df.Volume) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment