Update app.py
Browse files572 unmodified lines573574575576577578579580581582583584585586587168 unmodified lines756757758759760761762763572 unmodified lines""")fig = go.Figure()fig.add_trace(go.Scatter(x=data.index, y=data['Close'], mode='lines', name='Close'))fig.update_layout(title=f"{company_name} Stock Price History",xaxis_title="Date",yaxis_title="Price",hovermode="x unified",template="plotly_dark")st.plotly_chart(fig, use_container_width=True)with tab2:st.markdown("""### OHLC (Open-High-Low-Close) Chart168 unmodified linesst.metric("Avg Daily Return", f"{returns.mean():.2f}%")st.metric("Return Volatility", f"{returns.std():.2f}%")else:st.error("Failed to fetch data. Please try again.")except Exception as e:st.error(f"An error occurred: {str(e)}. Please try a different time period or check your internet connection.")572 unmodified lines573574575576577578579580581582583584585586587588589590591592593594595168 unmodified lines764765766767768769770771772773774775776777572 unmodified lines""")fig = go.Figure()fig.add_trace(go.Scatter(x=data.index, y=data['Open'], mode='lines', name='Open'))fig.add_trace(go.Scatter(x=data.index, y=data['High'], mode='lines', name='High'))fig.add_trace(go.Scatter(x=data.index, y=data['Low'], mode='lines', name='Low'))fig.add_trace(go.Scatter(x=data.index, y=data['Close'], mode='lines', name='Close'))# Add rolling mean and standard deviationdata['Rolling_Mean'] = data['Close'].rolling(window=20).mean()data['Rolling_Std'] = data['Close'].rolling(window=20).std()fig.add_trace(go.Scatter(x=data.index, y=data['Rolling_Mean'], mode='lines', name='20-day Rolling Mean', line=dict(dash='dash')))fig.add_trace(go.Scatter(x=data.index, y=data['Rolling_Std'], mode='lines', name='20-day Rolling Std', line=dict(dash='dot')))fig.update_layout(title=f"{company_name} Stock Price History",xaxis_title="Date",yaxis_title="Price",hovermode="x unified",template="plotly_dark")st.plotly_chart(fig, use_container_width=True)with tab2:st.markdown("""### OHLC (Open-High-Low-Close) Chart168 unmodified linesst.metric("Avg Daily Return", f"{returns.mean():.2f}%")st.metric("Return Volatility", f"{returns.std():.2f}%")# Display newsst.subheader("Latest News")news = fetch_news(company_name)for item in news:st.markdown(f"[{item['title']}]({item['link']}) ({item['pubDate']})")else:st.error("Failed to fetch data. Please try again.")except Exception as e:st.error(f"An error occurred: {str(e)}. Please try a different time period or check your internet connection.")
app.py+25-11