ForEach icon
Request icon
Script icon
ChatCompletion icon
Queries icon
SlackIncomingWebhook icon
Schedule icon

AI-Powered Stock Watchlist Analysis with Daily Alerts and PostgreSQL Logging

Automate daily stock analysis with Kestra and OpenAI GPT-4o. Fetch Yahoo Finance data, compute RSI and momentum, log to PostgreSQL, and alert Slack.

Categories
AIBusiness

Automate daily stock watchlist analysis with AI. This blueprint pulls 30 days of price history for a configurable list of tickers from Yahoo Finance, computes technical indicators (daily and monthly momentum, a 14-day RSI, proximity to 52-week highs and lows), then sends those signals to OpenAI GPT-4o for risk-calibrated BUY/HOLD/SELL/WATCH recommendations. Every signal is logged to PostgreSQL for backtesting and a formatted briefing is delivered to Slack before market open. It solves the problem of manually scanning a watchlist each morning by turning raw quotes into explained, confidence-scored recommendations on a reliable schedule.

How it works

  1. The market_open_daily io.kestra.plugin.core.trigger.Schedule trigger fires Monday to Friday at 14:00 UTC (09:00 ET market open).
  2. fetch_market_data (io.kestra.plugin.core.flow.ForEach with concurrencyLimit: 5) iterates the watchlist input and runs fetch_quote (io.kestra.plugin.core.http.Request) against the Yahoo Finance chart API for a 30-day daily range per ticker.
  3. prepare_analysis_data (io.kestra.plugin.scripts.python.Script) parses the raw quotes and computes day and month change percentages, a 14-day RSI approximation, and 52-week levels, emitting clean signals via Kestra.outputs.
  4. generate_ai_analysis (io.kestra.plugin.openai.ChatCompletion, model gpt-4o) consumes those signals with a jsonResponseSchema so GPT-4o returns a strict JSON object of recommendations, confidence scores, rationale, and risk flags, calibrated to the risk_profile input.
  5. log_to_postgres (io.kestra.plugin.jdbc.postgresql.Queries) creates the stock_analysis_log table if needed and inserts every recommendation joined to its price metrics.
  6. send_alerts (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) posts the market summary and per-ticker calls to Slack.

What you get

  • A daily, hands-off market briefing in Slack with explained recommendations
  • Quantitative indicators (momentum, RSI, 52-week proximity) computed before the AI sees them
  • Structured, schema-validated GPT-4o output instead of free-form text
  • A growing PostgreSQL signal history for win-rate analysis and backtesting
  • Tunable behavior via watchlist, analysis_horizon, and risk_profile inputs

Who it's for

  • Quantitative analysts and traders who want AI to augment a technical workflow
  • Portfolio managers tracking a specific watchlist before intraday decisions
  • Algorithmic trading teams building a signal-logging layer ahead of automated execution
  • Finance students learning to pair technical indicators with LLM reasoning

Why orchestrate this with Kestra

A scheduled cron in a script or a standalone OpenAI call cannot coordinate multiple systems, retry a flaky quote fetch, or keep an audit trail. Kestra runs this end to end from a declarative YAML flow: an event-driven Schedule trigger replaces fragile crontab entries, per-task retries and bounded ForEach concurrency handle Yahoo Finance rate limits, and execution lineage links every Slack alert back to the exact quotes, Python signals, and GPT-4o response that produced it. Neither OpenAI's API nor a database scheduler can fan out HTTP calls, run Python, call an LLM, write to PostgreSQL, and notify Slack as one observable, replayable pipeline.

Prerequisites

  • A Kestra instance (0.20.0+ recommended)
  • A reachable PostgreSQL database
  • A Slack incoming webhook
  • An OpenAI account with API access to gpt-4o

Secrets

  • OPENAI_API_KEY: OpenAI API key for the ChatCompletion task
  • SLACK_WEBHOOK_URL: Slack incoming webhook URL for alerts
  • POSTGRES_URL: JDBC URL for the PostgreSQL database
  • POSTGRES_USER: PostgreSQL username
  • POSTGRES_PASSWORD: PostgreSQL password

Quick start

  1. Add the secrets above to your Kestra instance.
  2. Copy this blueprint into a flow and adjust namespace if needed.
  3. Edit the watchlist, analysis_horizon, and risk_profile inputs to your strategy.
  4. Run once manually to verify quotes, the GPT-4o response, the PostgreSQL insert, and the Slack post.
  5. Let the Schedule trigger run it automatically each weekday morning.

How to extend

  • Add a human-approval gate (io.kestra.plugin.core.flow.Pause) before any execution step.
  • Connect a broker API (Alpaca, Interactive Brokers) for paper trading.
  • Enrich with fundamentals (P/E, earnings dates) from Alpha Vantage or Financial Modeling Prep.
  • Add position-sizing logic driven by the AI confidence scores.
  • Swap Slack for email or Microsoft Teams notifications.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.