Inspiration

Financial markets are defined by their unpredictability. While institutional investors use high-frequency trading algorithms and massive compute clusters to manage risk, retail traders often rely on lagging indicators that tell them what just happened, not what will happen. We were inspired to bridge this gap by building VolatilityGuard AI, a system that democratizes institutional-grade risk assessment. Our goal was to move beyond static technical analysis and create a "forward-looking" volatility gauge using Deep Learning.

What it does

VolatilityGuard AI is a real-time "Cyber-Physical System" for the stock market. It monitors TQQQ (a 3x leveraged ETF) in real-time and predicts volatility spikes before they materialize.

Real-Time Ingestion: Polls Alpaca Markets for 5-minute stock candles and streams them to Confluent Cloud (Kafka). ​ Predictive Inference: A Cloud Run service consumes this stream, processes 30-candle windows, and uses an LSTM neural network to predict the realized volatility for the next 25 minutes.

AI Risk Analysis: If volatility exceeds a safe threshold, it triggers Google Gemini Pro to generate a contextual risk report explaining why the market is turbulent.

How we built it

We architected the solution as a decoupled microservices application deployed on Google Cloud Platform.

  1. The Mathematical Core (LSTM) We chose Long Short-Term Memory (LSTM) networks to capture the non-linear temporal dependencies in price action. The model processes a sequence of 47 technical indicators (RSI, MACD, Bollinger Bands, etc.). capturing market regime. ​
  2. The Data Pipeline

Producer: A Python script on a Google Compute Engine VM (e2-micro) fetches data and serializes it to JSON.

Broker: Confluent Cloud serves as the central nervous system, buffering messages to ensure no data is lost during analysis.

Consumer: A Streamlit dashboard on Cloud Run deserializes the stream, applies a saved MinMaxScaler, and feeds it to the TensorFlow model.

Challenges we ran into

The "Flatline" Prediction: Initially, our model predicted a straight line, failing to react to spikes. We discovered that VWAP (Volume Weighted Average Price) values were massive compared to other features, crushing the LSTM gradients. I removed VWAP and fixed the scaler logic to resolve this. ​ Production Undersampling: LSTMs trained on MSE (Mean Squared Error) are naturally conservative and underestimated the magnitude of volatility spikes.

Accomplishments that we're proud of

End-to-End Cloud Native Architecture: We successfully deployed a "Producer-Consumer" architecture using Docker, Google Cloud Run, and Kafka, moving beyond a simple "notebook project" to a resilient distributed syste

Hybrid AI Approach: We combined Quantitative ML (LSTM for numbers) with Generative AI (Gemini for text), providing users with both the what (volatility score) and the why (risk explanation).

Directional Accuracy: Despite the noise of financial data, our model achieved a strong correlation in predicting the direction of volatility shifts on out-of-sample data (2020-2024).

What we learned

Market Regimes Matter: Training on pre-2020 data hurt performance because the market structure changed fundamentally after COVID-19. We learned that "more data" isn't always better; "relevant data" is key.

Feature Leakage is Subtle: We learned the hard way that scaling features on the entire dataset introduces leakage. We had to rewrite our pipeline to scale strictly on rolling windows to simulate true real-time conditions.

What's next for VolatilityGuard AI

Multi-Stock Global Model: Moving from a single-ticker (TQQQ) model to a "Global" LSTM trained on the S&P 500 components to capture broader systemic risk.

Online Learning: Implementing an "Online Learning" loop where the model runs model.fit() for 1 epoch on every new closed candle, allowing it to adapt to new market regimes in real-time.

Automated Hedging: Connecting the volatility alerts directly to the Alpaca Trade API to automatically place "stop-loss" orders when the predicted risk crosses a critical threshold.

Built With

Share this project:

Updates