Spaces:
Runtime error
Runtime error
import streamlit as st | |
import yfinance as yf | |
import pandas as pd | |
import cufflinks as cf | |
import datetime | |
import plotly.graph_objects as go | |
# App title | |
st.markdown(''' | |
# Sovrenn Market Sentiment Indicator App | |
Shown are the stock price data for the selected company! | |
**Credits** | |
- App built by SRL | |
''') | |
st.write('---') | |
# Sidebar | |
st.sidebar.subheader('Query parameters') | |
start_date = st.sidebar.date_input("Start date", datetime.date(2023,9, 20)) | |
#start_date = start_date - datetime.timedelta(days=1) | |
end_date = start_date + datetime.timedelta(days=14) | |
# User input for the stock ticker symbol | |
tickerSymbol = st.sidebar.text_input('Enter Stock Ticker Symbol') | |
if tickerSymbol: | |
tickerData = yf.Ticker(tickerSymbol) # Get ticker data | |
tickerDf = tickerData.history(period='1d', start=start_date, end=end_date) # Get the historical prices for this ticker | |
string_name = tickerData.info.get('longName', 'Company Name Not Available') | |
st.header('**%s**' % string_name) | |
# Try to get the business summary, handle KeyError if not available | |
try: | |
string_summary = tickerData.info['longBusinessSummary'] | |
st.info(string_summary) | |
except KeyError: | |
st.warning("Business summary not available for this company.") | |
# Ticker data | |
st.header('**Ticker data**') | |
st.write(tickerDf) | |
# Create a candlestick chart and volume bar chart | |
fig_candlestick = go.Figure(data=[go.Candlestick(x=tickerDf.index, | |
open=tickerDf['Open'], | |
high=tickerDf['High'], | |
low=tickerDf['Low'], | |
close=tickerDf['Close'])]) | |
fig_volume = go.Figure(data=[go.Bar(x=tickerDf.index, y=tickerDf['Volume'])]) | |
st.header('**Candlestick Chart**') | |
st.plotly_chart(fig_candlestick) | |
st.header('**Volume Bar Chart**') | |
st.plotly_chart(fig_volume) | |
st.write(start_date) | |
tickerDf = pd.DataFrame(tickerDf).reset_index() | |
# st.write(tickerDf) | |
#date = datetime.date(start_date) | |
date_str = start_date.strftime("%Y-%m-%d") | |
st.write(date_str) | |
df = tickerDf[tickerDf["Date"]==date_str] | |
st.write(df) | |
if (Df["Close"][0] > Df["Open"][0] ): | |
st.write("NSE has uptrend on " +date_str ) | |
if (Df["Close"][0] < Df["Open"][0] ): | |
st.write(" NSE has downdtrend on " +date_str ) | |
else: | |
st.warning("Please enter a valid Stock Ticker Symbol.") | |