Skip to content

The-FOOL-00/Trade-Copilot

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Regime-Aware AI Trading Command Center

GDG HackFest 2026 Β· Hybrid Quant + Gemini Multi-Agent System

A production-style agentic AI trading system built with Google ADK and Gemini on Vertex AI.

The system demonstrates how AI agents can safely automate financial workflows by combining deterministic quantitative models, multi-agent adversarial reasoning, a risk engine that can override AI decisions, paper trading, and a real-time React dashboard.

This is a workflow automation system, not a chatbot.


Live Dashboard

Page What It Shows
Dashboard (/) Chat interface, market regime card, portfolio summary, backtest results, dividend scanner, Nifty 50 signal board
Market (/market) Interactive candlestick / line chart with SMA overlays, volume bars, RSI, period & interval selectors
Analyze (/analyze) Full 7-step AI pipeline: Regime β†’ Scan β†’ Dividend Health β†’ Debate β†’ Trade/Risk β†’ Portfolio β†’ Autonomous Flow

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    React + Tailwind Frontend                     β”‚
β”‚    Dashboard  Β·  Market Chart  Β·  Analyze Pipeline  Β·  Chat     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚  REST API
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   FastAPI Server (server/app.py)                 β”‚
β”‚                                                                  β”‚
β”‚  /api/chat ──► ADK root_agent (LLM-driven delegation)           β”‚
β”‚  /api/analyze ──► Server-orchestrated 7-step pipeline            β”‚
β”‚  /api/market, /api/regime, /api/portfolio, /api/signals, ...     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Google ADK Agent Layer                           β”‚
β”‚                                                                  β”‚
β”‚  root_agent (trading_assistant)                                  β”‚
β”‚    β”œβ”€β”€ regime_analyst         β†’ analyze_regime()                 β”‚
β”‚    β”œβ”€β”€ stock_scanner          β†’ scan_watchlist / get_analysis    β”‚
β”‚    β”œβ”€β”€ dividend_scanner       β†’ assess_dividend_health()         β”‚
β”‚    β”œβ”€β”€ trade_debate_judge     β†’ Bull vs Bear adversarial debate  β”‚
β”‚    β”‚     β”œβ”€β”€ bull_advocate                                       β”‚
β”‚    β”‚     └── bear_advocate                                       β”‚
β”‚    β”œβ”€β”€ trade_executor         β†’ check_risk() + paper trading     β”‚
β”‚    └── portfolio_manager      β†’ portfolio CRUD                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Deterministic Python Layer                       β”‚
β”‚                                                                  β”‚
β”‚  Risk Engine Β· Technical Indicators Β· Regime Classifier          β”‚
β”‚  Position Sizing Β· ATR Stop-Loss Β· Portfolio Persistence         β”‚
β”‚  yfinance (live NSE data) Β· News Fetcher                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key design principle: The LLM reasons and orchestrates; Python computes and enforces. The AI cannot override mathematical risk rules.


Seven-Step Analysis Pipeline

When you click Run Analysis on the Analyze page, the server orchestrates these steps programmatically (no LLM delegation failures):

Step Agent What It Does
1 Regime Analyst Classifies market as BULL / SIDEWAYS / BEAR using 50-DMA, 200-DMA, slope, momentum
2 Stock Scanner Fetches live OHLCV, computes RSI, ATR, 50-DMA, breakout detection, volume ratio
3 Dividend Scanner Assesses dividend health (HEALTHY / CAUTION / DESPERATE) via earnings growth, payout ratio, PE, ROE
4 Debate (Bull vs Bear) LLM produces BULL_THESIS + BEAR_THESIS + CIO_DECISION in one pass with embedded market data
5 Trade Executor Deterministic risk engine: entry/stop/target calc, position sizing, kill rules. Or HOLD with no trade.
6 Portfolio Manager Reports cash, open positions, portfolio value
7 Autonomous Flow Synthesis summary of all completed steps

Bull vs Bear Debate

The debate is the core innovation. Instead of a single LLM opinion, the system generates adversarial arguments:

  • Bull Advocate β€” strongest possible case FOR the trade (quant strengths, sentiment strengths, catalysts, risk rebuttal)
  • Bear Advocate β€” strongest possible case AGAINST (quant weaknesses, sentiment risks, downside catalysts, bull case flaws)
  • CIO Decision β€” final verdict (BUY / SELL / HOLD) with entry, stop-loss, target, risk-reward ratio, conviction score

Both sides cite real data (RSI, 50-DMA, volume, news headlines). The CIO weighs both and delivers a data-backed verdict.


Risk Engine

All risk calculations are deterministic Python β€” the LLM cannot override them.

Rule Implementation
Stop-Loss Entry βˆ’ (1.5 Γ— ATR) for BUY; Entry + (1.5 Γ— ATR) for SELL
Position Size floor((Portfolio Γ— 0.01) / RiskPerShare) β€” 1% risk per trade
Minimum R:R β‰₯ 1.5:1 reward-to-risk ratio
Conviction Gate Trades below 0.4 conviction are killed
Regime Filter BEAR regime trades face stricter scrutiny
Volatility Cap Excessive ATR-to-price ratio triggers rejection
Max Exposure Portfolio-level position limits

The risk engine can REJECT trades that pass the debate β€” risk rules act as a hard safety layer.


Tech Stack

Layer Technology
AI Google ADK, Gemini (via Vertex AI or API key)
Backend Python 3.11, FastAPI, uvicorn
Frontend React 19, TypeScript, Vite, Tailwind CSS 4, Recharts, shadcn/ui
Data yfinance (live NSE OHLCV + news), Yahoo Finance
Storage JSON file-based portfolio (server/memory/portfolio.json)

Model Fallback

At startup, _pick_available_model() probes models in order and uses the first that responds:

  1. gemini-3-flash-preview
  2. gemini-2.5-flash
  3. gemini-2.0-flash
  4. gemini-2.5-pro

API Endpoints

Endpoint Method Description
/api/health GET Health check
/api/chat POST Send message to ADK root agent
/api/analyze POST Server-orchestrated 7-step analysis pipeline
/api/regime GET Current market regime
/api/market GET OHLCV + indicators for chart (ticker, period, interval)
/api/portfolio GET Portfolio summary
/api/portfolio/performance GET Portfolio performance metrics
/api/portfolio/refresh POST Refresh position prices
/api/portfolio/reset POST Reset to initial INR 10,00,000
/api/backtest/oversold-summary GET Oversold bounce backtest results
/api/backtest/oversold-best GET Best oversold trades
/api/dividend/top GET Top dividend stocks
/api/signals/nifty50 GET Nifty 50 signal board

Project Structure

GDG_HACKFEST/
β”œβ”€β”€ server/
β”‚   └── app.py                          # FastAPI backend (~970 lines)
β”‚
β”œβ”€β”€ trading_agents/                     # Google ADK agent package
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ agent.py                        # root_agent β€” coordinator
β”‚   β”œβ”€β”€ config.py                       # model fallback, risk rules, watchlist
β”‚   β”œβ”€β”€ models.py                       # Pydantic data models
β”‚   β”œβ”€β”€ utils.py                        # shared helpers (IST, ticker normalization)
β”‚   β”œβ”€β”€ risk_engine.py                  # deterministic risk engine (290 lines)
β”‚   β”œβ”€β”€ regime_agent.py                 # market regime classifier
β”‚   β”œβ”€β”€ scanner_agent.py                # breakout + stock scanner
β”‚   β”œβ”€β”€ debate_agent.py                 # bull/bear/CIO debate system
β”‚   β”œβ”€β”€ trade_agent.py                  # trade execution + risk check
β”‚   β”œβ”€β”€ portfolio_agent.py              # portfolio queries
β”‚   β”œβ”€β”€ dividend_agent.py               # dividend scanning
β”‚   └── tools/
β”‚       β”œβ”€β”€ market_data.py              # live NSE data (yfinance)
β”‚       β”œβ”€β”€ news_data.py                # stock news fetcher
β”‚       β”œβ”€β”€ technical.py                # indicators (DMA, ATR, RSI, breakout)
β”‚       β”œβ”€β”€ fundamental_data.py         # fundamentals + dividend health
β”‚       β”œβ”€β”€ dividend_data.py            # MoneyControl dividend scraper
β”‚       β”œβ”€β”€ paper_trading.py            # paper trade execution
β”‚       β”œβ”€β”€ portfolio.py                # portfolio persistence (JSON)
β”‚       β”œβ”€β”€ risk_tool.py                # ADK-compatible check_risk wrapper
β”‚       β”œβ”€β”€ backtest_oversold.py        # oversold bounce backtest
β”‚       β”œβ”€β”€ backtest_dividend.py        # dividend momentum backtest
β”‚       β”œβ”€β”€ autonomous_trading.py       # autonomous trading flow
β”‚       β”œβ”€β”€ market_status.py            # market open/close check
β”‚       └── demo_tools.py              # demo helpers
β”‚
β”œβ”€β”€ frontend/                           # React + Vite + Tailwind
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.tsx                     # Router setup
β”‚   β”‚   β”œβ”€β”€ api.ts                      # API client
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   β”œβ”€β”€ Home.tsx                # Dashboard (chat + widgets)
β”‚   β”‚   β”‚   β”œβ”€β”€ Market.tsx              # Interactive chart page
β”‚   β”‚   β”‚   └── Analyze.tsx             # 7-step AI pipeline page
β”‚   β”‚   └── components/
β”‚   β”‚       β”œβ”€β”€ Layout.tsx              # App shell + nav
β”‚   β”‚       β”œβ”€β”€ Chat.tsx                # Chat interface
β”‚   β”‚       β”œβ”€β”€ MarketChart.tsx         # Candlestick/line chart (SVG + Recharts)
β”‚   β”‚       β”œβ”€β”€ MarketRegime.tsx        # Regime status card
β”‚   β”‚       β”œβ”€β”€ Portfolio.tsx           # Portfolio summary
β”‚   β”‚       β”œβ”€β”€ DecisionCard.tsx        # Trade decision display
β”‚   β”‚       β”œβ”€β”€ DebatePanel.tsx         # Bull vs Bear debate UI
β”‚   β”‚       β”œβ”€β”€ PipelineSteps.tsx       # 7-step pipeline visualizer
β”‚   β”‚       β”œβ”€β”€ SignalBoard.tsx         # Nifty 50 signals
β”‚   β”‚       β”œβ”€β”€ BacktestSummary.tsx     # Backtest results
β”‚   β”‚       └── DividendTop.tsx         # Top dividend stocks
β”‚   β”œβ”€β”€ package.json
β”‚   └── vite.config.ts
β”‚
β”œβ”€β”€ tests/                              # Test suite
β”œβ”€β”€ _archive/                           # Archived legacy code
β”œβ”€β”€ docs/                               # Architecture docs
β”œβ”€β”€ memory/                             # Portfolio JSON persistence
β”œβ”€β”€ requirements.txt                    # Python dependencies
└── README.md

NSE Watchlist (Nifty 50 Stocks)

# Symbol Company
1 RELIANCE.NS Reliance Industries
2 TCS.NS Tata Consultancy Services
3 HDFCBANK.NS HDFC Bank
4 INFY.NS Infosys
5 ICICIBANK.NS ICICI Bank
6 HINDUNILVR.NS Hindustan Unilever
7 ITC.NS ITC Limited
8 SBIN.NS State Bank of India
9 BHARTIARTL.NS Bharti Airtel
10 KOTAKBANK.NS Kotak Mahindra Bank
11 LT.NS Larsen & Toubro
12 AXISBANK.NS Axis Bank
13 ASIANPAINT.NS Asian Paints
14 MARUTI.NS Maruti Suzuki
15 TITAN.NS Titan Company
16 SUNPHARMA.NS Sun Pharma
17 BAJFINANCE.NS Bajaj Finance
18 WIPRO.NS Wipro
19 HCLTECH.NS HCL Technologies
20 TATAMOTORS.NS Tata Motors

Setup

1. Clone and install

git clone <repo-url>
cd GDG_HACKFEST

python -m venv .venv
.venv\Scripts\activate          # Windows
# source .venv/bin/activate     # macOS/Linux

pip install -r requirements.txt

2. Configure credentials

Create trading_agents/.env:

# Option A: Vertex AI (recommended)
GOOGLE_GENAI_USE_VERTEXAI=TRUE
GOOGLE_CLOUD_PROJECT=your-project-id
GOOGLE_CLOUD_LOCATION=us-central1

# Option B: API Key
# GOOGLE_API_KEY=your-api-key

3. Build the frontend

cd frontend
npm install
npm run build
cd ..

4. Run the server

python -m uvicorn server.app:app --host 0.0.0.0 --port 8000

Open http://localhost:8000 in your browser.

5. Alternative: ADK Web UI

cd trading_agents
adk web

Chat Commands

Prompt What Happens
"What is the current market regime?" Fetches live Nifty 50 data, classifies BULL/SIDEWAYS/BEAR
"Scan for breakout stocks" Scans watchlist for 20-day breakout candidates
"Analyze RELIANCE" Full 7-step pipeline: regime β†’ scan β†’ dividend β†’ debate β†’ risk β†’ portfolio
"Should I buy TCS?" Bull vs Bear debate with BUY/SELL/HOLD verdict
"Show my portfolio" Cash, positions, P&L, trade history
"Reset portfolio" Resets to INR 10,00,000

What Makes This Agentic

Property Implementation
Autonomous reasoning LLM decides which sub-agent to delegate to and how to interpret results
Tool use 15+ deterministic tool functions registered with ADK
Multi-agent orchestration Root agent coordinates 6 sub-agents (8 total including debate advocates)
Adversarial reasoning Bull and Bear agents debate from opposing perspectives; CIO delivers verdict
Deterministic safety Risk engine is pure Python β€” LLM cannot override math
Memory Portfolio state persists to disk across sessions
Explainability Every decision includes data, reasoning, source, and timestamp
Observability React dashboard shows pipeline steps, debate points, chart, and trade details in real time

License

See LICENSE.


Built for GDG Chennai HackFest 2026 β€” Autonomous AI Agents solving real workflows.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 73.4%
  • TypeScript 18.6%
  • HTML 3.5%
  • JavaScript 2.7%
  • CSS 1.8%