Introduction
Overview
Signal.Engine is an autonomous, high-frequency market analysis and trading system designed specifically for the Nifty 500 (Indian Stock Market). Moving beyond traditional technical indicators, Signal.Engine treats market movements as complex sequences, utilizing Generative AI for context and Reinforcement Learning (RL) for execution.
The system functions as a "Reasoning Agent" that bridges the gap between quantitative research and live execution. It integrates three distinct layers of intelligence:
- Heuristic Experts: Rule-based logic for initial filtering.
- Deep Learning (LSTM): Sequence modeling to interpret the last 50 price candles.
- RL Agent (PPO): A fine-tuned policy model trained to manage risk and maximize expected value (EV).
Core Capabilities
1. Generative Contextualization
Unlike simple classifiers, the internal "Brain" (v3.0) uses Supervised Fine-Tuning (SFT) on a "Golden Dataset" of perfect hindsight trades (ZigZag labeled). This ensures the agent possesses a "Common Sense" understanding of market structures before it even enters the RL phase.
2. Autonomous Execution
Signal.Engine is built to trade live via the Alpaca API. The deployment logic handles real-time data fetching, feature engineering (RSI, MACD, Log-Returns), and order execution (Buy/Sell/Hold) without manual intervention.
3. The Observatory (Visual Intelligence)
The system includes a modern, React-based dashboard that provides a "Glass Box" view into the agent's decision-making process, showing real-time confidence scores, rationales, and quantitative risk metrics.
System Components
For users interacting with the codebase, Signal.Engine is divided into three primary interfaces:
The Backend (FastAPI)
The API acts as the bridge between the ML models and the outside world. It manages the scanning cycles and simulation state.
- Endpoint:
GET /api/scan: Triggers the Hybrid Brain to analyze the market in the background. - Endpoint:
GET /api/results: Returns the latest trade decisions, including the "Rationale" (why the model is taking a trade) and "Confidence." - Endpoint:
GET /prediction: A legacy-compatible endpoint that provides a simple UP/DOWN/NEUTRAL forecast for a specific ticker.
The Live Trader (CLI)
The trader_alpaca.py script is the primary entry point for live or paper trading.
# Execute a dry run for a specific stock (RELIANCE)
python -m src.trader_alpaca --symbol RELIANCE.NS --qty 1
# Start live paper trading execution
python -m src.trader_alpaca --symbol RELIANCE.NS --qty 1 --live
The Training Pipeline
For users looking to retrain the agent on new market data:
train_sft.py: Trains the "Teacher" model using supervised learning.train_ppo_optimized.py: Fine-tunes the agent using Proximal Policy Optimization in a vectorized environment.
Getting Started
To utilize Signal.Engine, you must configure your environment to communicate with both the data providers and the execution broker.
1. Configuration
Create a .env file in the root directory:
APCA_API_KEY_ID="your_alpaca_key"
APCA_API_SECRET_KEY="your_alpaca_secret"
APCA_API_BASE_URL="https://paper-api.alpaca.markets"
2. Running the API
The API powers the dashboard and provides a programmatic interface for the trading logic:
python -m src.api.main
3. Accessing the Dashboard
Navigate to the frontend/ directory, install dependencies, and start the observatory:
npm install
npm run dev
The dashboard will be available at http://localhost:5173, allowing you to monitor high-confidence signals and portfolio performance in real-time.