Skip to content

Real-Time Financial Intelligence Powered by Pathway Streaming Engine

Notifications You must be signed in to change notification settings

wildcraft958/AlphaStream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

54 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AlphaStream Live AI

Real-Time Financial Intelligence Powered by Pathway Streaming Engine

AlphaStream is a production-grade AI trading system that solves the "stale knowledge" problem in financial analysis. It combines real-time news ingestion, SEC EDGAR filings, multi-agent reasoning, and live visualization to deliver instant, explainable trading recommendations.

Built for DataQuest 2026 hackathon using the Pathway streaming framework.


🎯 Problem Statement

Traditional AI systems suffer from knowledge cutoffβ€”they can't react to breaking news or regulatory filings. AlphaStream demonstrates Live AI:

  • Ingests news articles in real-time
  • Updates recommendations in <2 seconds when new data arrives
  • Incorporates SEC insider trading data
  • Generates professional PDF reports

πŸš€ Key Features

Real-Time Data Pipeline

  • Pathway Streaming Engine - Incremental processing, no batch jobs
  • NewsAPI Integration - Live financial news polling
  • SEC EDGAR Connector - Form 4 insider trading filings

Multi-Agent Reasoning System

Agent Function
Sentiment Agent LLM-powered news sentiment analysis
Technical Agent RSI, SMA calculations from yfinance
Risk Agent Volatility-based position sizing
Insider Agent SEC Form 4 transaction analysis
Chart Agent 7-day price charts with 24h highlighting
Report Agent PDF generation with charts & tables
Decision Agent Final BUY/HOLD/SELL recommendation

Bloomberg-Style Dashboard

  • Real-time sentiment heatmap
  • Agent consensus radar chart
  • Insider activity panel
  • One-click PDF report generation

πŸ› οΈ Technology Stack

Layer Technology
Streaming Engine Pathway
Backend FastAPI, Python 3.11
LLM LangChain, OpenRouter (Claude/Gemma)
Market Data yfinance, edgartools
PDF Reports ReportLab, Matplotlib
Frontend React 18, Vite, Tailwind CSS, Shadcn
State Zustand

Pathway xpacks.llm Integration

We use Pathway's official LLM xpack (from llm-app templates) for maximum performance:

Component Pathway xpack Class
Adaptive RAG pw.xpacks.llm.question_answering.AdaptiveRAGQuestionAnswerer
Document Store pw.xpacks.llm.document_store.DocumentStore
LLM Chat pw.xpacks.llm.llms.OpenAIChat
Embeddings pw.xpacks.llm.embedders.OpenAIEmbedder
Splitter pw.xpacks.llm.splitters.TokenCountSplitter
Vector Search pw.indexing.UsearchKnnFactory
REST Server pw.xpacks.llm.servers.QASummaryRestServer

Adaptive RAG uses a geometric retrieval strategy - starting with 2 documents and expanding only when the LLM needs more context, saving tokens without sacrificing accuracy.


⚑ Quick Start

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • API Keys: OpenRouter, NewsAPI

1. Clone & Setup

cd "AlphaStream"

# Install Python dependencies (using uv)
cd backend && uv sync && cd ..

# Install frontend dependencies
cd frontend && npm install && cd ..

2. Configure Environment

# Backend environment (required)
cd backend
cp .env.example .env
# Edit .env with your API keys:
# - OPENROUTER_API_KEY (required - LLM access)
# - NEWS_API_KEY (required - NewsAPI)
# - FINNHUB_API_KEY (optional - additional news)
# - ALPHAVANTAGE_API_KEY (optional - sentiment data)
# - MEDIASTACK_API_KEY (optional - global news)
cd ..

3. Run the System

Option A: Single Command (Recommended)

cd backend
./start.sh

This starts both Adaptive RAG and the main backend in the correct order.

Option B: Separate Terminals (for debugging)

Terminal 1: Adaptive RAG Server

cd backend
uv run python -m src.pipeline.adaptive_rag_server

Terminal 2: Backend

cd backend
uv run uvicorn src.api.app:app --host 0.0.0.0 --port 8000

Terminal 3: Frontend

cd frontend && npm run dev

Access dashboard at http://localhost:5173

4. Run Demonstration (Optional)

Terminal 3: Demo Script

python demo_pipeline.py --ticker AAPL --output demo_output.json

The demo script:

  • Fetches initial recommendation
  • Injects bearish breaking news
  • Shows real-time sentiment change
  • Saves detailed JSON proof to demo_output.json

UI Visibility: The demo updates ARE visible in the dashboard! When the demo injects an article, the backend broadcasts via WebSocket, and the frontend updates automatically. Keep the dashboard open to see live changes.


πŸ“‘ API Endpoints

Core Endpoints

Method Path Description
POST /recommend Get trading recommendation
GET /health System health check
GET /articles/{ticker} Get related articles
GET /market/heatmap Live market sentiment data
POST /ingest Inject test article

SEC EDGAR Endpoints (Stage 5)

Method Path Description
GET /insider/{ticker}?days=90 Insider trading activity (default: 90 days)
GET /chart/{ticker} Price comparison chart
POST /report/{ticker} Generate PDF report

WebSocket

Path Description
/ws/stream/{ticker} Real-time recommendation updates

πŸ—οΈ Architecture

AlphaStream System Architecture

Pathway Streaming Engine - The Core

AlphaStream is built around Pathway, the world's fastest streaming engine. Our implementation demonstrates deep Pathway integration:

Pathway Feature Usage
pw.Schema Type-safe schemas for articles, sentiment, alerts
pw.Table Streaming tables for real-time market data
pw.io.python.ConnectorSubject Custom news connector polling multiple APIs
pw.io.subscribe Real-time callbacks on data changes
pw.apply UDF transformations for ticker extraction
pw.filter Alert generation on sentiment spikes
pw.reducers Sentiment aggregation by ticker

"Herd of Knowledge" News Aggregation

Our innovative multi-source news system fetches from 5 sources in parallel:

Herd of Knowledge

  • NewsAPI - Breaking news headlines
  • Finnhub - Company-specific financial news
  • Alpha Vantage - Sentiment-tagged articles
  • MediaStack - Global business news
  • RSS Feeds - Free, unlimited fallback

No single point of failure - if one source is rate-limited, others continue.

Data Flow

News Sources β†’ Pathway Connector β†’ RAG Pipeline β†’ Multi-Agent Reasoning β†’ WebSocket β†’ Dashboard
     ↓                ↓                 ↓                    ↓
  Real-time     pw.Table with      Hybrid retrieval    7 specialized
  polling       auto-indexing      + reranking         AI agents

πŸ“ Project Structure

AlphaStream/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ agents/
β”‚   β”‚   β”‚   β”œβ”€β”€ sentiment_agent.py   # LangChain sentiment analysis
β”‚   β”‚   β”‚   β”œβ”€β”€ technical_agent.py   # RSI, SMA from yfinance
β”‚   β”‚   β”‚   β”œβ”€β”€ risk_agent.py        # Volatility & position sizing
β”‚   β”‚   β”‚   β”œβ”€β”€ decision_agent.py    # Final recommendation (LLM)
β”‚   β”‚   β”‚   β”œβ”€β”€ insider_agent.py     # SEC Form 4 analysis
β”‚   β”‚   β”‚   β”œβ”€β”€ chart_agent.py       # Matplotlib charts
β”‚   β”‚   β”‚   └── report_agent.py      # ReportLab PDF
β”‚   β”‚   β”œβ”€β”€ connectors/
β”‚   β”‚   β”‚   β”œβ”€β”€ news_connector.py    # Pathway streaming connector
β”‚   β”‚   β”‚   β”œβ”€β”€ news_aggregator.py   # "Herd of Knowledge" multi-source
β”‚   β”‚   β”‚   β”œβ”€β”€ rss_connector.py     # Free RSS fallback
β”‚   β”‚   β”‚   β”œβ”€β”€ sec_connector.py     # SEC EDGAR (edgartools)
β”‚   β”‚   β”‚   └── polling.py           # Generic polling utilities
β”‚   β”‚   β”œβ”€β”€ pipeline/
β”‚   β”‚   β”‚   β”œβ”€β”€ rag_core.py          # RAG pipeline orchestration
β”‚   β”‚   β”‚   β”œβ”€β”€ rag_service.py       # Unified RAG (adaptive + manual fallback)
β”‚   β”‚   β”‚   β”œβ”€β”€ adaptive_rag_server.py # Pathway xpacks.llm implementation
β”‚   β”‚   β”‚   β”œβ”€β”€ pathway_tables.py    # Pathway-native tables & transforms
β”‚   β”‚   β”‚   β”œβ”€β”€ chunking.py          # Adaptive document chunking
β”‚   β”‚   β”‚   β”œβ”€β”€ retrieval.py         # Hybrid retrieval (dense + BM25 + RRF)
β”‚   β”‚   β”‚   └── reranking.py         # Cross-encoder reranking
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”‚   └── app.py               # FastAPI + Pathway integration
β”‚   β”‚   └── config.py                # Pydantic settings management
β”‚   β”œβ”€β”€ reports/                     # Generated PDF reports
β”‚   β”œβ”€β”€ tests/                       # pytest tests
β”‚   β”œβ”€β”€ .env.example                 # Environment template
β”‚   └── pyproject.toml               # Dependencies (uv)
β”œβ”€β”€ frontend/
β”‚   └── src/
β”‚       β”œβ”€β”€ App.tsx                  # Main dashboard
β”‚       β”œβ”€β”€ store/appStore.ts        # Zustand state management
β”‚       └── components/trading/      # 12 UI components
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ ARCHITECTURE.md
β”‚   β”œβ”€β”€ PROJECT_DOCUMENTATION.md
β”‚   β”œβ”€β”€ pipeline_architecture_*.png  # Generated diagrams
β”‚   └── herd_of_knowledge_*.png
β”œβ”€β”€ demo_pipeline.py                 # Automated demo script
β”œβ”€β”€ demo_live.py                     # Live demonstration
└── docker-compose.yml

πŸ§ͺ Testing

# Run all tests
cd backend
uv run pytest tests/ -v

# Test real-time dynamism
uv run python scripts/inject_article.py "Breaking News" "Content here"
# Watch recommendation change in <2s

🐳 Docker Deployment

docker-compose up --build

Access at http://localhost:8000 (API) and http://localhost:5173 (Dashboard)


πŸ“Š Demo: Proving Real-Time Dynamism

Automated Demo Pipeline

Run the complete demonstration with:

python demo_pipeline.py

This script automatically:

  1. Starts the backend server
  2. Gets initial AAPL recommendation
  3. Injects a bearish article
  4. Shows recommendation change in <2 seconds
  5. Generates PDF report

Manual Demo

  1. Start the system
  2. Search for "AAPL" β†’ Note recommendation
  3. Inject bearish article:
    curl -X POST http://localhost:8000/ingest \
      -H "Content-Type: application/json" \
      -d '{"title":"Apple Faces Lawsuit","content":"Major legal trouble..."}'
  4. Watch recommendation change via WebSocket
  5. Generate PDF report with updated analysis

πŸ“ License

MIT License. Built for DataQuest 2026 Hackathon.


πŸ™ Acknowledgments

  • Pathway - Streaming engine powering real-time RAG
  • OpenRouter - LLM API access
  • edgartools - SEC EDGAR data access

About

Real-Time Financial Intelligence Powered by Pathway Streaming Engine

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •