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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import plotly.graph_objects as go
|
| 4 |
+
from datetime import datetime, timedelta
|
| 5 |
+
import random
|
| 6 |
+
|
| 7 |
+
# Page configuration
|
| 8 |
+
st.set_page_config(
|
| 9 |
+
page_title="Ahsan's AI Stock Dashboard",
|
| 10 |
+
page_icon="π",
|
| 11 |
+
layout="wide",
|
| 12 |
+
initial_sidebar_state="expanded"
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
# Custom CSS
|
| 16 |
+
st.markdown("""
|
| 17 |
+
<style>
|
| 18 |
+
.main-header {
|
| 19 |
+
font-size: 2.5rem;
|
| 20 |
+
background: linear-gradient(45deg, #3b82f6, #8b5cf6);
|
| 21 |
+
-webkit-background-clip: text;
|
| 22 |
+
-webkit-text-fill-color: transparent;
|
| 23 |
+
font-weight: 800;
|
| 24 |
+
margin-bottom: 1rem;
|
| 25 |
+
}
|
| 26 |
+
.card {
|
| 27 |
+
background-color: #0f172a;
|
| 28 |
+
border-radius: 10px;
|
| 29 |
+
padding: 1.5rem;
|
| 30 |
+
border: 1px solid #334155;
|
| 31 |
+
margin-bottom: 1rem;
|
| 32 |
+
}
|
| 33 |
+
.positive {
|
| 34 |
+
color: #10b981;
|
| 35 |
+
font-weight: bold;
|
| 36 |
+
}
|
| 37 |
+
.negative {
|
| 38 |
+
color: #ef4444;
|
| 39 |
+
font-weight: bold;
|
| 40 |
+
}
|
| 41 |
+
.warning {
|
| 42 |
+
color: #f59e0b;
|
| 43 |
+
font-weight: bold;
|
| 44 |
+
}
|
| 45 |
+
</style>
|
| 46 |
+
""", unsafe_allow_html=True)
|
| 47 |
+
|
| 48 |
+
# Header
|
| 49 |
+
st.markdown('<h1 class="main-header">π Ahsan\'s AI Stock Dashboard</h1>', unsafe_allow_html=True)
|
| 50 |
+
|
| 51 |
+
# Portfolio Data
|
| 52 |
+
portfolio_data = {
|
| 53 |
+
'Symbol': ['OCEA', 'KUST', 'MLGO', 'BNN', 'IRWD', 'HEIO', 'DB', 'ATYR', 'DOW', 'XLY'],
|
| 54 |
+
'Name': ['Ocean Biomedical', 'Kustom Entertainment', 'MicroAlgo Inc', 'Bollinger Innovations',
|
| 55 |
+
'Ironwood Pharmaceuticals', 'Harvard Bioscience', 'Diedbal Cannabis', 'Aryr Pharma',
|
| 56 |
+
'Dow Inc', 'Audy Cannabis'],
|
| 57 |
+
'Return %': [-99.07, -92.32, -87.26, -99.96, 542.70, 48.67, 41.94, -2.49, 3.88, 70.99],
|
| 58 |
+
'AI Recommendation': ['SELL', 'SELL', 'SELL', 'SELL', 'BUY', 'BUY', 'BUY', 'HOLD', 'HOLD', 'HOLD'],
|
| 59 |
+
'Confidence %': [97, 95, 93, 96, 78, 74, 68, 71, 72, 75]
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
df = pd.DataFrame(portfolio_data)
|
| 63 |
+
|
| 64 |
+
# Dashboard Layout
|
| 65 |
+
col1, col2, col3 = st.columns(3)
|
| 66 |
+
|
| 67 |
+
with col1:
|
| 68 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
| 69 |
+
st.metric("Total Portfolio Value", "$9,485.94", "-$222.55")
|
| 70 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 71 |
+
|
| 72 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
| 73 |
+
st.subheader("π΄ Immediate Sell")
|
| 74 |
+
sell_df = df[df['AI Recommendation'] == 'SELL']
|
| 75 |
+
for _, row in sell_df.iterrows():
|
| 76 |
+
st.markdown(f"**{row['Symbol']}**: -{abs(row['Return %']):.2f}% (Confidence: {row['Confidence %']}%)")
|
| 77 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 78 |
+
|
| 79 |
+
with col2:
|
| 80 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
| 81 |
+
st.metric("Total Return", "-$9,328.80", "-49.57%")
|
| 82 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 83 |
+
|
| 84 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
| 85 |
+
st.subheader("π’ Strong Buy")
|
| 86 |
+
buy_df = df[df['AI Recommendation'] == 'BUY']
|
| 87 |
+
for _, row in buy_df.iterrows():
|
| 88 |
+
st.markdown(f"**{row['Symbol']}**: +{row['Return %']:.2f}% (Confidence: {row['Confidence %']}%)")
|
| 89 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 90 |
+
|
| 91 |
+
with col3:
|
| 92 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
| 93 |
+
st.metric("Positions", "39", "7 Winning, 31 Losing")
|
| 94 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 95 |
+
|
| 96 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
| 97 |
+
st.subheader("π‘ Hold Positions")
|
| 98 |
+
hold_df = df[df['AI Recommendation'] == 'HOLD']
|
| 99 |
+
for _, row in hold_df.iterrows():
|
| 100 |
+
color_class = "positive" if row['Return %'] > 0 else "negative" if row['Return %'] < 0 else "warning"
|
| 101 |
+
st.markdown(f"**{row['Symbol']}**: <span class='{color_class}'>{row['Return %']:.2f}%</span> (Confidence: {row['Confidence %']}%)", unsafe_allow_html=True)
|
| 102 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 103 |
+
|
| 104 |
+
# Portfolio Chart
|
| 105 |
+
st.markdown("---")
|
| 106 |
+
st.subheader("π Portfolio Performance")
|
| 107 |
+
|
| 108 |
+
# Generate sample chart data
|
| 109 |
+
dates = pd.date_range(end=datetime.now(), periods=30, freq='D')
|
| 110 |
+
values = [10000 + random.uniform(-200, 200) for _ in range(30)]
|
| 111 |
+
for i in range(1, 30):
|
| 112 |
+
values[i] = values[i-1] + random.uniform(-200, 200)
|
| 113 |
+
|
| 114 |
+
fig = go.Figure(data=go.Scatter(x=dates, y=values, mode='lines', name='Portfolio Value',
|
| 115 |
+
line=dict(color='#3b82f6', width=3)))
|
| 116 |
+
fig.update_layout(
|
| 117 |
+
title="30-Day Portfolio Performance",
|
| 118 |
+
xaxis_title="Date",
|
| 119 |
+
yaxis_title="Portfolio Value ($)",
|
| 120 |
+
template="plotly_dark",
|
| 121 |
+
height=400
|
| 122 |
+
)
|
| 123 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 124 |
+
|
| 125 |
+
# 7-Day Action Plan
|
| 126 |
+
st.markdown("---")
|
| 127 |
+
st.subheader("π 7-Day Action Plan")
|
| 128 |
+
|
| 129 |
+
plan_cols = st.columns(4)
|
| 130 |
+
action_plan = [
|
| 131 |
+
("Days 1-2", "SELL LOSERS", "Sell OCEA, KUST, MLGO, BNN immediately"),
|
| 132 |
+
("Day 3", "REBALANCE", "Reduce biotech from 30% to 15%"),
|
| 133 |
+
("Days 4-5", "ADD WINNERS", "Buy more IRWD, HEIO, DB"),
|
| 134 |
+
("Days 6-7", "MONITOR", "Set stop-loss orders, weekly review")
|
| 135 |
+
]
|
| 136 |
+
|
| 137 |
+
for idx, (title, action, desc) in enumerate(action_plan):
|
| 138 |
+
with plan_cols[idx]:
|
| 139 |
+
st.markdown(f'<div class="card">', unsafe_allow_html=True)
|
| 140 |
+
st.markdown(f"### {title}")
|
| 141 |
+
st.markdown(f"**{action}**")
|
| 142 |
+
st.markdown(f"<small>{desc}</small>", unsafe_allow_html=True)
|
| 143 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 144 |
+
|
| 145 |
+
# Risk Assessment
|
| 146 |
+
st.markdown("---")
|
| 147 |
+
col1, col2 = st.columns([2, 1])
|
| 148 |
+
|
| 149 |
+
with col1:
|
| 150 |
+
st.subheader("β οΈ Risk Assessment")
|
| 151 |
+
risk_score = 85
|
| 152 |
+
st.progress(risk_score/100)
|
| 153 |
+
st.markdown(f"**Risk Level: HIGH ({risk_score}/100)**")
|
| 154 |
+
st.markdown("""
|
| 155 |
+
- 31 of 39 positions losing money
|
| 156 |
+
- Extreme concentration in speculative biotech
|
| 157 |
+
- No diversification in large-cap stocks
|
| 158 |
+
- No stop-loss protection
|
| 159 |
+
""")
|
| 160 |
+
|
| 161 |
+
with col2:
|
| 162 |
+
st.subheader("π― Quick Actions")
|
| 163 |
+
if st.button("π¨ Sell Extreme Losers", use_container_width=True):
|
| 164 |
+
st.success("Sell orders executed for OCEA, KUST, MLGO, BNN")
|
| 165 |
+
|
| 166 |
+
if st.button("π Buy Top Performers", use_container_width=True):
|
| 167 |
+
st.success("Buy orders executed for IRWD, HEIO, DB")
|
| 168 |
+
|
| 169 |
+
if st.button("βοΈ AI Rebalance", use_container_width=True):
|
| 170 |
+
st.success("Portfolio rebalancing initiated")
|
| 171 |
+
|
| 172 |
+
# Footer
|
| 173 |
+
st.markdown("---")
|
| 174 |
+
st.markdown("""
|
| 175 |
+
<div style="text-align: center; color: #64748b; font-size: 0.9rem;">
|
| 176 |
+
<p>π AI Stock Dashboard β’ Last Updated: {}</p>
|
| 177 |
+
<p>π Real-time Analysis β’ 39 Positions Monitored β’ AI Model: GPT-4 Quantum</p>
|
| 178 |
+
</div>
|
| 179 |
+
""".format(datetime.now().strftime("%Y-%m-%d %H:%M")), unsafe_allow_html=True)
|