Skip to content

arnavgogia20/Tekron-hackathon

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

108 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ»πŸ“ˆ BuriBuri Trading

An Explainable, Risk-Aware Portfolio Decision Engine

Continuous decision-making for risk-aware portfolio management.
(Hackathon Prototype β€” Do not use with real assets.)


🏁 Getting Started

Who This MVP Is For

This prototype is designed for hackathon judges, reviewers, and developers who want to explore an explainable, rule-based portfolio decision engine. It demonstrates risk-aware capital allocation logic without requiring real trading credentials.The Market is open from 9:30 AM to 4:00 PM ET.

Prerequisites

  • Python 3.8+ (tested on 3.10+)
  • pip for installing dependencies
  • A terminal/command line interface

Quick Start (Demo Mode)

No API keys required. Run the full system with mock data:

# 1. Clone the repository
git clone https://github.com/mrhapile/BuriBuri_Trading.git
cd BuriBuri_Trading

# 2. Install dependencies
pip3 install -r requirements.txt

# 3. Run the full system demo
python3 full_system_demo.py

This runs the complete decision pipeline using cached historical data and demo profiles.

Optional: Live Data Mode

To use live market data during market hours, set your Alpaca paper trading credentials:

export ALPACA_API_KEY=your_paper_api_key
export ALPACA_SECRET_KEY=your_paper_secret
export ALPACA_BASE_URL=https://paper-api.alpaca.markets

Safe fallback: If credentials are missing or the API is unavailable, the system automatically uses historical data mode. No crashes, no errors.

What You Will See

When you run the demo, the console will display:

  1. System Mode β€” LIVE or HISTORICAL data source
  2. Market Posture β€” Current risk assessment (RISK_OFF β†’ AGGRESSIVE)
  3. Position Analysis β€” Health scores for each holding (0-100)
  4. Decisions β€” Recommended actions with clear explanations
  5. Blocked Actions β€” Any decisions rejected by safety guardrails

Example output:

πŸ“Š Posture: NEUTRAL | Risk: MEDIUM
πŸ’Š Analyzing position vitals...
πŸ›‘οΈ Evaluating concentration limits...
βœ… Final decisions ready: 3 approved

[Primary Decision]
REDUCE SLOW_UTIL (Score: 42)
Reason: Vitals critically low. Reduce exposure.

Important Notes

⚠️ This is an advisory-only system. No trades are executed.
All recommendations are for demonstration and educational purposes only.
Do not use with real assets or production trading accounts.


🧠 Problem Statement

Traditional trading systems treat positions as isolated events. Once opened, they stop reasoning until a fixed exit is hit.

In reality:

  • Capital gets stuck in stagnant trades
  • Risk accumulates silently (volatility, concentration)
  • Better opportunities appear while capital is locked

BuriBuri Trading addresses this by treating capital as a resource that must continuously justify its allocation.


πŸ‘₯ Team

Name Role
Nishtha Vadhwani Team Lead
Akash Anand Tech Lead
Mohit Ray UI/UX
Dev Jaiswal Reviewer / Tester

🎯 System Philosophy

Principle Meaning
Portfolio-first Optimizes entire portfolios, not single trades
Safety > Aggressiveness Capital preservation is more important than growth
Explainability Every decision has human-readable reasons
No Forced Action "Doing nothing" is often the best decision
Transparency Data source is always clearly labeled

This system is an advisor. It generates high-fidelity recommendations but intentionally disables execution.


πŸ—οΈ High-Level Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    PORTFOLIO INTELLIGENCE SYSTEM                β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
β”‚   β”‚  PHASE 1   │───▢│  PHASE 2   │───▢│  PHASE 3   β”‚            β”‚
β”‚   β”‚  INGEST    β”‚    β”‚  SIGNALS   β”‚    β”‚  DECISIONS β”‚            β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
β”‚         β”‚                 β”‚                 β”‚                   β”‚
β”‚         β–Ό                 β–Ό                 β–Ό                   β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
β”‚   β”‚ Portfolio  β”‚    β”‚ Volatility β”‚    β”‚  Actions   β”‚            β”‚
β”‚   β”‚ Positions  β”‚    β”‚ News Score β”‚    β”‚ + Reasons  β”‚            β”‚
β”‚   β”‚ Candidates β”‚    β”‚ Confidence β”‚    β”‚            β”‚            β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
β”‚                                              β”‚                  β”‚
β”‚                                              β–Ό                  β”‚
β”‚                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚                         β”‚   PHASE 4: RISK GUARDRAILS  β”‚         β”‚
β”‚                         β”‚   (Concentration, Cash,     β”‚         β”‚
β”‚                         β”‚    Volatility Guards)       β”‚         β”‚
β”‚                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚                                              β”‚                  β”‚
β”‚                                              β–Ό                  β”‚
β”‚                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚                         β”‚  PHASE 5: EXECUTION PLAN    β”‚         β”‚
β”‚                         β”‚  (Advisory Only - No Exec)  β”‚         β”‚
β”‚                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Phase Breakdown

Phase Module(s) Input Output
Phase 1 data_router.py, broker/*.py, historical_data_service.py Market status, credentials Portfolio, positions, candidates
Phase 2 volatility_metrics.py, news_scorer.py, sector_confidence.py Candles, headlines ATR, volatility state, news score, confidence
Phase 3 decision_engine.py, position_vitals.py, concentration_guard.py Signals + positions Proposed actions with reasons
Phase 4 risk_guardrails.py Proposed actions + context Allowed vs blocked actions
Phase 5 execution_planner.py, execution_summary.py Safe actions Sequential plan (advisory)

πŸ“Š Data Sources & Operating Modes

The system automatically selects the appropriate data source based on market status:

Market Status Data Mode Data Source Symbol Selection Time Range
OPEN LIVE Alpaca + Polygon API From live portfolio Disabled
CLOSED HISTORICAL Alpaca Historical Cache User selectable User selectable

Strict Routing Rules

  • Market OPEN β†’ LIVE DATA ONLY: No fallbacks, no mixing
  • Market CLOSED β†’ HISTORICAL DATA ONLY: Uses cached Alpaca data
  • Session Immutability: Data mode is locked at session start

Available Historical Data

Cached symbols for historical validation:

  • SPY β€” S&P 500 ETF
  • QQQ β€” NASDAQ-100 ETF
  • IWM β€” Russell 2000 ETF

Time ranges: 1 Month, 4 Months, 6 Months, 1 Year

Security Note

  • Alpaca Integration is READ-ONLY
  • Only paper trading URL allowed (https://paper-api.alpaca.markets)
  • Credentials from environment variables only
  • No write operations, no order submission

🎭 Demo Scenarios

Behavioral Demonstrations

The system includes 5 behavioral scenarios that demonstrate specific agent intelligence:

Scenario Trigger What It Demonstrates
🚨 Crash Reflex Volatility spike Capital preservation overrides profit-seeking
πŸ›‘οΈ Concentration Guard 75%+ sector exposure Refuses perfect trades due to structural limits
πŸ‘€ Disciplined Observer Noisy market signals Chooses inaction over forced action
♻️ Dead Capital Rotator Stagnant positions Identifies and redeploys underperforming capital
πŸͺ€ Greedy Trap High hype + high volatility Anti-FOMO skepticism in conflicting signals

Legacy Demo Profiles

For testing specific portfolio states:

Profile Capital Scenario Expected Response
BALANCED_TECH $500k Healthy, diversified MAINTAIN structure
OVERCONCENTRATED_TECH $1M 82% in TECH TRIM_RISK, block new TECH
LOSING_PORTFOLIO $750k Multiple losers RISK_OFF posture
ROTATION_SCENARIO $800k TECH cooling, ENERGY rising FREE_CAPITAL β†’ reallocate
CASH_HEAVY $500k 40% idle cash WAIT (reject weak trades)

πŸ“ Decision Explainability

Every decision includes human-readable reasoning:

{
  "action": "TRIM_RISK",
  "target": "AMD",
  "score": 31.0,
  "reasons": [
    "Position vitals critically low (Score: 31/100)",
    "Sector TECH is over-concentrated (>60%)",
    "High-confidence upgrade opportunity available in ENERGY"
  ]
}

This ensures a human operator can always understand why a recommendation was made.


πŸ›‘οΈ Risk & Safety Guardrails

Safety rules applied after decisions, before execution:

Guard Trigger Effect
Sector Concentration Any sector > 60% Block new allocations to that sector
Cash Reserve Cash < minimum threshold Block outflows, encourage inflows
Volatility Γ— Aggression High volatility + aggressive action Scale down or block

Rule: Safety always overrides aggressiveness. A profitable trade will be blocked if it violates safety rules.


🧠 Agent Intelligence Features

Agent Memory (Cross-Run Learning)

The system maintains memory between runs:

  • Tracks previous market posture
  • Computes risk trend (INCREASING / DECREASING / STABLE)
  • Provides context for decision continuity

Reasoning Stream

Real-time visibility into the agent's thought process:

  • Step-by-step signal interpretation
  • Decision rationale at each phase
  • Visible in the frontend "Brain Log" panel

Crash Simulation

Toggle to test defensive behavior:

  • Forces RISK_OFF posture
  • Demonstrates capital preservation logic
  • Validates guardrail effectiveness

βœ… Feature Status

Feature Status Details
Position vitals (0–100) βœ… Efficiency score per position
Sector concentration guard βœ… Warning at 60%, breach at 70%
Capital lock-in detection βœ… Flags dead capital in cold sectors
Volatility regime βœ… EXPANDING / STABLE / CONTRACTING
News sentiment βœ… Keyword-based scoring (no LLM)
Market posture βœ… RISK_OFF β†’ AGGRESSIVE spectrum
Decision synthesis βœ… Multi-factor, explainable output
Risk guardrails βœ… Concentration, cash, volatility gates
Demo profiles βœ… 5 hardcoded scenarios
Behavioral scenarios βœ… 5 intelligence demonstrations
Alpaca integration βœ… READ-ONLY paper trading
Market-aware routing βœ… Auto-switches LIVE ↔ HISTORICAL
Historical validation βœ… SPY, QQQ, IWM cached data
Agent memory βœ… Cross-run risk tracking
Reasoning stream βœ… Real-time thought log
Crash simulation βœ… Toggle for defensive testing
Backend API βœ… Flask REST endpoint
Frontend dashboard βœ… Full UI with market-aware controls
Unit tests βœ… Comprehensive test suite
Cloud deployment βœ… Render.yaml configuration
Broker execution ❌ Intentionally disabled

πŸš€ Quick Start

1. Install Dependencies

git clone https://github.com/mrhapile/BuriBuri_Trading.git
cd BuriBuri_Trading
pip3 install -r requirements.txt

2. Run Backend API (Recommended)

python3 backend/app.py

API available at http://localhost:10000

3. Open Frontend

Open index.html in a browser, or serve locally:

python3 -m http.server 8080
# Open http://localhost:8080 in browser

4. Run CLI Demo

python3 full_system_demo.py

The system automatically detects market status and uses appropriate data source.

5. Run Test Suite

python3 tests/test_system.py

πŸ”‘ Environment Variables

Create a .env file (see .env.example):

# Alpaca Paper Trading (Optional - for live mode)
ALPACA_API_KEY=your_paper_api_key
ALPACA_SECRET_KEY=your_paper_secret
ALPACA_BASE_URL=https://paper-api.alpaca.markets

Note: Alpaca credentials are optional. Without them, the system operates in HISTORICAL mode only.


πŸ“¦ Core Modules

Module Purpose
data_router.py Market-aware data source routing
market_mode.py Market status detection (OPEN/CLOSED)
market_aware_runner.py Unified analysis runner
historical_data_service.py Historical data access (cached Alpaca data)
position_vitals.py Health and efficiency scoring (0-100)
volatility_metrics.py ATR computation + regime classification
capital_lock_in.py Dead capital detection
concentration_guard.py Sector exposure monitoring
news_scorer.py Keyword-based sentiment scoring
sector_confidence.py Volatility + news β†’ confidence
opportunity_logic.py Weak vs. strong position comparison
decision_engine.py Core orchestrator
decision_explainer.py Human-readable explanations
risk_guardrails.py Safety filtering
execution_planner.py Action sequencing
broker/alpaca_adapter.py READ-ONLY Alpaca client
broker/mock_adapter.py Mock data generator
demo/demo_profiles.py Hardcoded demo scenarios
demo/trend_overlays.py Signal modifiers
backend/app.py Flask REST API
backend/api_routes.py REST endpoint definitions
backend/scenarios.py Behavioral demo scenarios
tests/test_system.py Comprehensive test suite

πŸ“ File Structure

.
β”œβ”€β”€ full_system_demo.py        # CLI entry point
β”œβ”€β”€ decision_engine.py         # Phase 3: Decision synthesis
β”œβ”€β”€ risk_guardrails.py         # Phase 4: Safety gates
β”œβ”€β”€ execution_planner.py       # Phase 5: Advisory planning
β”‚
β”œβ”€β”€ data_router.py             # Market-aware data routing
β”œβ”€β”€ market_mode.py             # Market status detection
β”œβ”€β”€ market_aware_runner.py     # Unified analysis runner
β”œβ”€β”€ historical_data_service.py # Historical data access
β”‚
β”œβ”€β”€ volatility_metrics.py      # Phase 2: Volatility signals
β”œβ”€β”€ news_scorer.py             # Phase 2: News sentiment
β”œβ”€β”€ sector_confidence.py       # Phase 2: Confidence scoring
β”‚
β”œβ”€β”€ position_vitals.py         # Position health scoring
β”œβ”€β”€ concentration_guard.py     # Concentration detection
β”œβ”€β”€ capital_lock_in.py         # Capital efficiency
β”œβ”€β”€ opportunity_logic.py       # Candidate evaluation
β”‚
β”œβ”€β”€ broker/
β”‚   β”œβ”€β”€ alpaca_adapter.py      # READ-ONLY Alpaca client
β”‚   └── mock_adapter.py        # Mock data generator
β”‚
β”œβ”€β”€ demo/
β”‚   β”œβ”€β”€ demo_profiles.py       # Hardcoded portfolio profiles
β”‚   └── trend_overlays.py      # Signal modifiers for demos
β”‚
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app.py                 # Flask server
β”‚   β”œβ”€β”€ api_routes.py          # REST endpoints
β”‚   β”œβ”€β”€ scenarios.py           # Behavioral demo scenarios
β”‚   └── market_status.py       # Market status helper
β”‚
β”œβ”€β”€ historical_cache/          # Cached Alpaca historical data
β”‚   β”œβ”€β”€ SPY_*.json
β”‚   β”œβ”€β”€ QQQ_*.json
β”‚   └── IWM_*.json
β”‚
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ test_system.py         # Comprehensive test suite
β”‚   β”œβ”€β”€ test_historical_mode.py
β”‚   └── test_live_mode.py
β”‚
β”œβ”€β”€ validation/                # Validation utilities
β”‚   β”œβ”€β”€ data_manager.py
β”‚   β”œβ”€β”€ metrics.py
β”‚   β”œβ”€β”€ replay.py
β”‚   └── runner.py
β”‚
β”œβ”€β”€ index.html                 # Frontend dashboard
β”œβ”€β”€ script.js                  # Frontend logic
β”œβ”€β”€ styles.css                 # Frontend styling
β”‚
β”œβ”€β”€ render.yaml                # Cloud deployment config
β”œβ”€β”€ Procfile                   # Heroku/Render process file
β”‚
└── archive/                   # Deprecated files (reference only)

🚫 What This System Does NOT Do

  • ❌ No Order Execution β€” Intentionally disabled
  • ❌ No Price Prediction β€” Manages risk, not forecasts
  • ❌ No Black Box ML β€” All logic is rule-based and explainable
  • ❌ No High-Frequency Trading β€” Portfolio management, not scalping
  • ❌ No Live Trading β€” Paper trading only
  • ❌ No LLM/AI Models β€” Uses keyword-based sentiment, not neural networks

πŸ› οΈ Development Process

This system was built with engineering maturity:

  1. Mock First β€” Validated logic with synthetic data before API integration
  2. Phased Intelligence β€” Built independent signal layers
  3. Safety Integrated β€” Added guardrails as first-class citizens
  4. Explainability β€” Retrofitted all logic to explain itself
  5. Market-Aware Routing β€” Added automatic LIVE/HISTORICAL switching
  6. Hardening β€” Added demo profiles, scenarios, and regression tests

πŸ‘€ For Judges

What to look for:

  1. Run the backend + open frontend β€” See market-aware controls
  2. Select different symbols and time ranges β€” Observe data source transparency
  3. Try behavioral scenarios β€” See specific agent intelligence demonstrated
  4. Toggle Crash Simulation β€” Watch defensive posture activate
  5. Check the Brain Log β€” Real-time reasoning visibility
  6. Review decision reasons β€” Each action is explained

What this proves:

  • The system can reason about portfolio risk
  • Safety is a first-class concern
  • Decisions are explainable and auditable
  • Market-awareness provides flexibility for demos
  • The architecture is clean and maintainable

πŸ“š Additional Documentation

  • ARCHITECTURE.md β€” Data contracts & module dependencies
  • Inline docstrings in all modules
  • Runnable tests: python3 tests/test_system.py

🧭 Design Principles

  • Capital is finite β€” idle capital is hidden risk
  • Portfolio management > price prediction
  • Explainability > black-box models
  • Safety > aggressiveness
  • Deterministic logic over ML heuristics

This system manages the present β€” it does not predict the future.


⚠️ Known Limitations

Limitation Reason
Historical data limited to SPY, QQQ, IWM Cached subset for demo purposes
No real-time news API Uses keyword-based scoring on mock headlines
Sector inference is simplified Basic symbol-to-sector mapping
No portfolio persistence Each session starts fresh


Last updated: 2026-02-01

Β© 2026 BuriBuri Trading Team

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 75.7%
  • JavaScript 10.7%
  • CSS 10.6%
  • HTML 3.0%