Logian

A real-time stock sentiment analysis system that scrapes financial news, generates vector embeddings, and scores sentiment using FinBERT — producing BUY / SELL / HOLD signals across 100 tickers simultaneously.

FinBERT all-MiniLM-L6-v2 FastAPI + WebSocket React + Vite Actian VectorAI DB Yahoo Finance
⚡
Fast Path

Microsecond signals via cosine similarity against risk-anchor embeddings stored in Actian. No ML inference at runtime.

🧠
Slow Path

Full FinBERT inference for high-accuracy scoring. Confirmed embeddings feed back into the fast path anchor cache.

📡
Real-Time Dashboard

React frontend connected via WebSocket. Live pipeline progress and score updates for all monitored tickers.

🔍
Semantic Lookup

Local web UI for querying the vector DB by ticker or natural language. No API server required.

Setup

Prerequisites: Python 3.10+, Node.js 18+, Docker.

1. Install Python dependencies

pip install -r requirements.txt
pip install actiancortex-0.1.0b1-py3-none-any.whl

2. Install frontend dependencies

cd dashboard && npm install && cd ..

3. Start Actian VectorAI DB

# First time
docker run -d --name actian-vectorai -p 50051:50051 \
  williamimoh/actian-vectorai-db:1.0b

# After restart
docker start actian-vectorai

4. Configure environment (optional)

# .env
VECTORAI_DB_ADDRESS=localhost:50051

Running

Dashboard (backend + frontend)

./run.sh

Opens the React dashboard at http://localhost:5173 and the API at http://localhost:8000.

CLI — single ticker

python src/main.py NVDA

Dual-path signal engine

# Fast + slow path on 100 tickers (slow path on 10)
python src/signals.py

# Fast path only — no FinBERT inference
python src/signals.py --fast

# Slow path on N tickers
python src/signals.py --slow 20

Batch ingest

# Run mock feed through FinBERT
python src/ingest.py

# Use your own data
python src/ingest.py data.json

Vector DB lookup tool

./run.sh lookup

Opens a local search UI at http://localhost:8050.

Pipeline

The full pipeline runs for each monitored ticker on a 10-second cycle.

  1. Scrape — Yahoo Finance RSS feed (falls back to HTML parsing). Retry logic with exponential backoff.
  2. Embed — Headline + summary concatenated and encoded with all-MiniLM-L6-v2 into 384-dim L2-normalised vectors.
  3. Store — Embeddings + metadata (ticker, headline, link, timestamp) written to Actian VectorAI DB via batch_upsert.
  4. Score — FinBERT classifies each article as positive / negative / neutral with a confidence score.
  5. Aggregate — Confidence-weighted mean of all article scores, clipped to [-1.0, 1.0]. Score ≥ 0.3 = BUY, ≤ -0.3 = SELL, else HOLD.

Dual-Path Engine

signals.py implements two parallel approaches that trade accuracy for speed. The feedback loop means the fast path improves as the slow path confirms more scores.

⚡ Fast Path
Load pre-seeded embeddings from in-memory store (backed by Actian)
Compute average embedding vector for the ticker
Dot product against 16+ risk-anchor vectors (pure NumPy)
signal = mean(pos_sims) − mean(neg_sims), scaled to [−1, 1]
~10 μs
🧠 Slow Path
Run FinBERT on each article (confidence-weighted scoring)
Re-embed articles with confirmed sentiment context
Write updated embeddings back to Actian
Append confirmed embedding to anchor cache (feedback loop)
~1–2 s
The anchor cache starts with 16 hardcoded phrases. Each slow-path run appends the ticker's confirmed embedding, so the fast path gets more accurate over time without retraining.

Score calculation

# All vectors are L2-normalised → dot product = cosine similarity
pos_sims = pos_anchors @ avg_vec   # shape: (n_pos,)
neg_sims = neg_anchors @ avg_vec   # shape: (n_neg,)

raw    = mean(pos_sims) - mean(neg_sims)   # ≈ [-0.3, +0.3] for financial text
signal = clip(raw * 3.0, -1.0, 1.0)       # scale to usable range

Ports

PortServiceProtocolNotes
50051Actian VectorAI DBgRPCInternal only — never exposed publicly
8000FastAPI backendHTTP + WSPublic API in production (put Nginx in front)
5173React frontendHTTPDev only — npm run build for production
8050Lookup toolHTTPLocal only — not deployed

API Reference

Interactive docs available at http://localhost:8000/docs when the backend is running.

GET /api/tickers Full ticker catalog
Returns all 100 tickers with company name, sector, and descriptor.
GET /api/scores All monitored scores
Current scores, recommendations, and top articles for all active tickers.
GET /api/scores/{ticker} Single ticker score
Score, recommendation, pipeline step, and top 3 articles for one ticker.
GET /api/history/{ticker} Score history
Up to 100 timestamped score data points for charting.
POST /api/monitor Start / stop monitoring
Start or stop the background pipeline for a list of tickers.
// Start
{ "action": "start", "tickers": ["NVDA", "AAPL", "TSLA"] }

// Stop
{ "action": "stop", "tickers": ["NVDA"] }
POST /api/source Toggle data source
Switch between synthetic mock data and live Yahoo Finance scraping.
{ "source": "live" }   // or "mock"
GET /api/status Engine status
Returns whether the engine is running, current data source, and active tickers.

WebSocket

Connect to ws://localhost:8000/ws for real-time push updates.

Event types

initial_state

Sent immediately on connection with current scores and engine state.

{
  "type": "initial_state",
  "data": {
    "monitored_tickers": ["NVDA", "AAPL"],
    "data_source": "mock",
    "models_loaded": true,
    "scores": { "NVDA": { "score": -0.125, "recommendation": "HOLD" } }
  }
}

pipeline_progress

Fired at each pipeline step: scraping → embedding → storing → scoring → done.

{
  "type": "pipeline_progress",
  "data": { "ticker": "NVDA", "step": "scoring" }
}

score_update

Fired after each completed pipeline cycle with the latest score and top articles.

{
  "type": "score_update",
  "data": {
    "ticker": "NVDA",
    "score": -0.125,
    "recommendation": "HOLD",
    "timestamp": "2025-03-01T14:23:11",
    "articles_processed": 30,
    "top_articles": [...]
  }
}

CLI

Run the full pipeline for a single ticker and print a report to the terminal.

python src/main.py NVDA
======================================================================
STOCK SENTIMENT ANALYSIS REPORT
======================================================================

Ticker: NVDA
Recommendation: HOLD
Sentiment Score: -0.1823 (range: -1.0 to 1.0)

Top 3 Most Influential Articles:
----------------------------------------------------------------------
1. Is Nvidia a Buy on the Post-Earnings Dip?
   Sentiment: POSITIVE (84.4% confidence)  Score: +0.8438

2. Nvidia Faces Headwinds Amid Macro Uncertainty
   Sentiment: NEGATIVE (95.4% confidence)  Score: -0.9544

Batch Ingest

Score multiple tickers at once from a structured data file or the built-in mock feed.

# Use built-in mock feed (100 tickers, randomly samples 300 articles)
python src/ingest.py

# Provide your own JSON file
python src/ingest.py data.json

Input format

{
  "NVDA": [
    {
      "source": "Bloomberg",
      "headline": "Nvidia Q4 data-center revenue smashes forecasts",
      "summary": "Nvidia posted record revenue driven by AI accelerator demand..."
    }
  ]
}

Output

TICKER: NVDA    RECOMMENDATION: HOLD   SCORE: -0.125  (3 articles)
TICKER: AAPL    RECOMMENDATION: BUY    SCORE: +0.312  (3 articles)
TICKER: TSLA    RECOMMENDATION: SELL   SCORE: -0.418  (3 articles)
────────────────────────────────────────────────────────
Total: 100 tickers | 300 articles | 12.4s

Lookup Tool

A self-contained local web UI that queries Actian VectorAI DB directly — no API server needed.

./run.sh lookup
# Opens http://localhost:8050

Supports two modes:

  • Ticker Lookup — find all stored articles for a symbol
  • Semantic Search — natural language query (e.g. "AI chip demand") finds the most similar articles across all tickers using cosine similarity

Tech Stack

FinBERT Sentiment classification
all-MiniLM-L6-v2 384-dim embeddings
Actian VectorAI DB Vector storage (gRPC)
FastAPI REST + WebSocket API
React + Vite Dashboard frontend
Recharts Score charts
Yahoo Finance Live news RSS
sentence-transformers Embedding model