Skip to content

Tianning-lab/MomentumFlowAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

MomentumFlow AI

Confluent Kafka R Shiny Python MIT License

Real-time AI-Powered Trading Signals for S&P 500 Momentum Strategies

๐Ÿ† Confluent AI Partner Catalyst Hackathon 2025


๐Ÿ“– Overview

MomentumFlow AI is a real-time momentum trading scanner that leverages Confluent Kafka streaming to deliver institutional-grade market analysis. Built for the S&P 500, it combines proven momentum trading strategies with live data streaming and AI-powered pattern recognition.

Key Features

  • ๐Ÿ“Š Stock Scanner โ€” Scans 534 S&P 500 stocks against 5 momentum criteria
  • ๐Ÿ“ˆ Trend Indicator โ€” EMA-based trend detection (Bullish/Bearish/Neutral)
  • ๐Ÿšฉ Bull Flag Detection โ€” Automated pattern recognition with adjustable thresholds
  • ๐Ÿ“ฐ Live News Feed โ€” Google News streaming with sentiment analysis
  • ๐Ÿงฎ Risk Calculator โ€” Position sizing with scaling protocols
  • ๐Ÿ’ก Trade Ideas โ€” Auto-generated setups based on score + patterns

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Yahoo Finance   โ”‚     โ”‚   Confluent Kafka   โ”‚     โ”‚    R Shiny       โ”‚
โ”‚  Google News     โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚   (Cloud - Zurich)  โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚    Dashboard     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚                     โ”‚     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚  โ€ข stock_prices     โ”‚
   Python Producers      โ”‚  โ€ข stock_news       โ”‚      REST API Consumer
                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Kafka Topics

Topic Content Update Frequency
stock_prices OHLCV + Momentum Scores ~2 min cycle
stock_news Headlines + Sentiment ~5 min cycle

๐Ÿ“ Project Structure

MomentumFlowAI/
โ”œโ”€โ”€ app_dark_theme.R          # Main Shiny application
โ”œโ”€โ”€ kafka_producer.py         # Stock price streaming producer
โ”œโ”€โ”€ kafka_news_producer.py    # News streaming producer
โ”œโ”€โ”€ README.md                 # This file
โ”œโ”€โ”€ LICENSE                   # MIT License
โ””โ”€โ”€ docs/
    โ””โ”€โ”€ MomentumFlowAI_Hackathon_Submission.pdf

๐Ÿš€ Quick Start

Prerequisites

  • R 4.x with RStudio
  • Python 3.x
  • Confluent Cloud account (free tier works)

1. Clone the Repository

git clone https://github.com/Tianning-lab/MomentumFlowAI.git
cd MomentumFlowAI

2. Install R Dependencies

install.packages(c(
  "shiny", "shinydashboard", "quantmod", "tidyverse", 
  "plotly", "DT", "TTR", "lubridate", "scales",
  "PerformanceAnalytics", "httr", "jsonlite", "base64enc", "xml2"
))

3. Install Python Dependencies

pip install confluent-kafka yfinance pandas numpy feedparser requests

4. Configure Confluent Kafka

  1. Create a Confluent Cloud account at confluent.cloud
  2. Create a cluster (Basic tier is fine)
  3. Create topics: stock_prices and stock_news
  4. Generate API keys

Update credentials in both Python files:

KAFKA_CONFIG = {
    'bootstrap.servers': 'YOUR_BOOTSTRAP_SERVER',
    'sasl.username': 'YOUR_API_KEY',
    'sasl.password': 'YOUR_API_SECRET',
    ...
}

5. Start the Producers

Terminal 1 โ€” Stock Prices:

python kafka_producer.py

Terminal 2 โ€” News:

python kafka_news_producer.py

6. Run the Shiny App

In RStudio, open app_dark_theme.R and click Run App.


๐Ÿ“Š Momentum Criteria (Adapted for S&P 500)

# Criterion Threshold Rationale
1 Price Range $5 - $500 Covers most S&P 500 stocks
2 Daily Change โ‰ฅ 0.5% Meaningful price movement
3 Relative Volume โ‰ฅ 1.0x average Confirms participation
4 Momentum Price > Open Intraday buying pressure
5 Volatility Range โ‰ฅ 0.5% Sufficient profit opportunity

๐Ÿšฉ Bull Flag Detection

Thresholds adapted for large-cap stocks:

Parameter S&P 500 Penny Stocks
Pole Return โ‰ฅ 1.5% โ‰ฅ 3%
Flag Range < 7% < 5%
Volume Decreasing Decreasing

๐Ÿ› ๏ธ Technology Stack

Layer Technology
Streaming Confluent Cloud (Apache Kafka)
Producers Python, confluent-kafka, feedparser
Data Sources Yahoo Finance, Google News RSS
Frontend R Shiny, shinydashboard
Visualization Plotly, DT
Analysis quantmod, TTR, PerformanceAnalytics

๐Ÿ“ธ Screenshots

Landing Page

Landing Page

Stock Scanner with Trend Indicator

Scanner

Bull Flag Detection

Bull Flags

Live News Feed

News


๐Ÿ—บ๏ธ Roadmap

  • Q1 2026: Options flow analysis via Kafka Streams
  • Q2 2026: Claude AI integration for natural language queries
  • Q3 2026: Multi-asset support (crypto, forex)
  • Q4 2026: Mobile app with push notifications

๐Ÿ‘จโ€๐Ÿ’ป Author

Tianning Ning
Founder & CEO, New Way Capital Advisory Limited


๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments


ยฉ 2025 New Way Capital Advisory Limited
Made with โค๏ธ in Geneva, Switzerland


Live Demo

MomentumFlow AI is live at nwc-advisory.com/app โ€” part of the New Way Capital Advisory analytics platform.

Related Tools

About

Real-time AI-Powered Trading Signals for S&P 500 - Confluent Hackathon 2025

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors