-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
94 lines (73 loc) · 3.58 KB
/
Copy pathapp.py
File metadata and controls
94 lines (73 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import streamlit as st
import yfinance as yf
import plotly.graph_objs as go
from crew import run_analysis
import json
def main():
st.set_page_config(layout="wide")
st.title("AI-Powered Advanced Stock Analysis")
# User input
stock_symbol = st.text_input("Enter stock symbol (e.g., AAPL):", "AAPL")
if st.button("Analyze Stock"):
# Run CrewAI analysis
with st.spinner("Performing comprehensive stock analysis..."):
result = run_analysis(stock_symbol)
# Parse the result
analysis = json.loads(result)
# Display analysis result
st.header("AI Analysis Report")
col1, col2 = st.columns(2)
with col1:
st.subheader("Technical Analysis")
st.write(analysis.get('technical_analysis', 'No technical analysis available'))
st.subheader("Chart Patterns")
st.write(analysis.get('chart_patterns', 'No chart patterns identified'))
with col2:
st.subheader("Fundamental Analysis")
st.write(analysis.get('fundamental_analysis', 'No fundamental analysis available'))
st.subheader("Sentiment Analysis")
st.write(analysis.get('sentiment_analysis', 'No sentiment analysis available'))
st.subheader("Risk Assessment")
st.write(analysis.get('risk_assessment', 'No risk assessment available'))
st.subheader("Competitor Analysis")
st.write(analysis.get('competitor_analysis', 'No competitor analysis available'))
st.subheader("Investment Strategy")
st.write(analysis.get('investment_strategy', 'No investment strategy available'))
# Fetch stock data for chart
stock = yf.Ticker(stock_symbol)
hist = stock.history(period="1y")
# Create interactive chart
fig = go.Figure()
fig.add_trace(go.Candlestick(x=hist.index,
open=hist['Open'],
high=hist['High'],
low=hist['Low'],
close=hist['Close'],
name='Price'))
# Add volume bars
fig.add_trace(go.Bar(x=hist.index, y=hist['Volume'], name='Volume', yaxis='y2'))
# Add moving averages
fig.add_trace(go.Scatter(x=hist.index, y=hist['Close'].rolling(window=50).mean(), name='50-day MA'))
fig.add_trace(go.Scatter(x=hist.index, y=hist['Close'].rolling(window=200).mean(), name='200-day MA'))
fig.update_layout(
title=f"{stock_symbol} Stock Analysis",
yaxis_title='Price',
yaxis2=dict(title='Volume', overlaying='y', side='right'),
xaxis_rangeslider_visible=False
)
st.plotly_chart(fig, use_container_width=True)
# Display key statistics
st.subheader("Key Statistics")
info = stock.info
col1, col2, col3 = st.columns(3)
with col1:
st.metric("Market Cap", f"${info.get('marketCap', 'N/A'):,}")
st.metric("P/E Ratio", round(info.get('trailingPE', 0), 2))
with col2:
st.metric("52 Week High", f"${info.get('fiftyTwoWeekHigh', 0):,.2f}")
st.metric("52 Week Low", f"${info.get('fiftyTwoWeekLow', 0):,.2f}")
with col3:
st.metric("Dividend Yield", f"{info.get('dividendYield', 0):.2%}")
st.metric("Beta", round(info.get('beta', 0), 2))
if __name__ == "__main__":
main()