Skip to content

Commit 9343e99

Browse files
committed
feat: add streamlit dashboard for paper trading and analytics
1 parent 88b2ceb commit 9343e99

File tree

7 files changed

+107
-16
lines changed

7 files changed

+107
-16
lines changed

frontend/app.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import streamlit as st
2+
import requests
3+
from datetime import datetime
24

3-
st.set_page_config(
4-
page_title="AI Stock Predictor - Home",
5-
page_icon="🏠",
6-
layout="wide"
7-
)
5+
API_BASE = st.secrets.get("API_BASE", "http://localhost:8000")
6+
7+
st.set_page_config(page_title="ArthaQuant", layout="wide")
88

9-
st.title("🏠 Welcome to the AI Stock Predictor")
9+
st.title("📈 ArthaQuant — Paper Trading Dashboard")
1010

11-
st.markdown("""
12-
This application is an end-to-end MLOps project for stock price prediction.
13-
It uses a containerized architecture with Docker, a FastAPI backend, and this Streamlit frontend.
11+
user_id = st.sidebar.number_input("User ID", min_value=1, value=1)
12+
13+
page = st.sidebar.selectbox(
14+
"Navigate",
15+
["Predict", "Paper Trade", "Portfolio", "Analytics", "Drift"],
16+
)
1417

15-
**Features:**
16-
- **Predictions**: Get next-day price predictions for individual stocks using a Transformer model.
17-
- **Screener**: Run the model on multiple stocks to find potential opportunities.
18-
- **Drift Analysis**: Monitor for data drift between training and recent data.
19-
- **Backtesting**: (Coming Soon) Simulate trading strategies based on model predictions.
18+
def api_get(path):
19+
return requests.get(f"{API_BASE}{path}").json()
2020

21-
**Navigate to a feature using the sidebar on the left.**
22-
""")
21+
def api_post(path, payload):
22+
return requests.post(f"{API_BASE}{path}", json=payload).json()

frontend/pages/__init__.py

Whitespace-only changes.

frontend/pages/analytics.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import streamlit as st
2+
from frontend.app import api_get
3+
4+
st.header("📈 Analytics")
5+
6+
data = api_get("/analytics")
7+
8+
st.metric("Sharpe Ratio", data["sharpe_ratio"])
9+
st.metric("Max Drawdown", data["max_drawdown"])
10+
st.metric("Total Return", data["total_return"])
11+
12+
st.line_chart(data["equity_curve"])

frontend/pages/drift.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import streamlit as st
2+
import random
3+
from frontend.app import api_post
4+
5+
st.header("🚨 Drift Detection")
6+
7+
if st.button("Check Drift"):
8+
reference = [random.random() for _ in range(100)]
9+
current = [random.random() for _ in range(100)]
10+
11+
out = api_post("/drift", {
12+
"reference": reference,
13+
"current": current,
14+
})
15+
16+
st.json(out)

frontend/pages/paper_trade.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import streamlit as st
2+
from datetime import datetime
3+
from frontend.app import api_post
4+
5+
st.header("💼 Paper Trade")
6+
7+
symbol = st.text_input("Symbol", "AAPL")
8+
price = st.number_input("Current Price", value=100.0)
9+
10+
p_up = st.slider("P(Up)", 0.0, 1.0, 0.75)
11+
expected_return = st.number_input("Expected Return", value=0.02)
12+
uncertainty = st.number_input("Uncertainty", value=0.1)
13+
14+
if st.button("Execute Paper Trade"):
15+
payload = {
16+
"symbol": symbol,
17+
"p_up": p_up,
18+
"expected_return": expected_return,
19+
"uncertainty": uncertainty,
20+
"price": price,
21+
"timestamp": datetime.utcnow().isoformat(),
22+
}
23+
24+
out = api_post("/paper/trade", payload)
25+
st.json(out)

frontend/pages/portfolio.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import streamlit as st
2+
from frontend.app import api_get
3+
4+
st.header("📊 Portfolio")
5+
6+
data = api_get("/portfolio")
7+
8+
st.subheader("Cash")
9+
st.write(data["cash"])
10+
11+
st.subheader("Positions")
12+
st.json(data["positions"])
13+
14+
st.subheader("Trades")
15+
st.json(data["trades"])

frontend/pages/predict.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import streamlit as st
2+
import numpy as np
3+
from frontend.app import api_post
4+
5+
st.header("🔮 Predict")
6+
7+
symbol = st.text_input("Symbol", "AAPL")
8+
9+
if st.button("Run Prediction"):
10+
market_seq = np.random.randn(60, 10).tolist()
11+
12+
payload = {
13+
"symbol": symbol,
14+
"market_sequence": market_seq,
15+
"input_ids": [101] * 128,
16+
"attention_mask": [1] * 128,
17+
}
18+
19+
out = api_post("/predict", payload)
20+
21+
st.metric("P(Up)", f"{out['p_up']:.2f}")
22+
st.metric("Expected Return", f"{out['expected_return']:.4f}")
23+
st.metric("Uncertainty", f"{out['uncertainty']:.4f}")

0 commit comments

Comments
 (0)