freshcrate
Home > AI Agents > swing-trading-agent

swing-trading-agent

Multi-agent swing trading system — automated screening, research, and execution with backtesting and live trading

Description

Multi-agent swing trading system — automated screening, research, and execution with backtesting and live trading

README

Swing Trading Agent

An autonomous trading agent that manages a portfolio across multiple daily cycles — screening candidates, reading news, sizing positions, placing orders, and adjusting stops — without manual intervention. It supports backtesting on historical data, paper trading against live markets via Alpaca, and fully automated live trading.

The agent doesn't just pick stocks. Each cycle builds on the output of the previous one: EOD signals flow into morning order decisions, which feed into intraday position management. News research, quantitative indicators, and a structured playbook all factor into every decision, and the agent manages the full lifecycle of each position from entry through exit.

Dashboard

How It Works

The agent runs three trading cycles per day, each designed for a specific decision point in the market. Each cycle is coordinated by three components, all powered by Amazon Bedrock foundation models via Strands Agents SDK:

  • Quant Engine — Screens the S&P 500 universe using technical indicators (RSI, MACD, ATR, Bollinger Bands, ADX) and ranks candidates by composite momentum and mean-reversion z-scores. Detects the current market regime (trending, mean-reverting, transitional, high-volatility) to guide strategy selection. All indicators are pre-computed deterministically — no LLM inference on math.
  • Research Agent — Reads news articles and earnings data for shortlisted candidates to assess sentiment, identify catalysts, and flag risks (e.g., fraud, regulatory action, upcoming earnings). Outputs qualitative research findings that the PM Agent uses alongside the quant context.
  • Portfolio Manager (PM) Agent — Makes the final trade decisions (enter, exit, hold, tighten, watch) by weighing quant signals, research findings, and a structured playbook of entry/exit rules. Manages position sizing (fixed 2% risk per trade with ATR-based stops), portfolio-level constraints (sector caps, correlation limits, drawdown circuit breakers), and cross-cycle continuity through persistent decision logs.

Trading Cycles

Cycle Time (ET) What it does
EOD Signal 4:00 PM Screens S&P 500 with a quant engine, researches top candidates via news, generates entry/exit signals with position sizing and stop levels
Morning 9:00 AM Checks pre-market news and overnight gaps, confirms or rejects EOD signals, places orders at market open
Intraday 10:30 AM+ Monitors open positions for anomalies, auto-tightens trailing stops, exits positions if conditions deteriorate

Architecture

Architecture

  • AgentCore Runtime — Hosts the trading agent as a managed container. EventBridge rules trigger cycles on schedule.
  • DynamoDB — Hot path storage for session data, cycle results, and portfolio state.
  • S3 — Cold path storage for backtest datasets (historical bars, news) and agent code.
  • Frontend & API Server — React dashboard + FastAPI backend for monitoring and control.

External Integrations

Provider Purpose
Alpaca Markets Broker API — order execution, positions, account data (paper + live)
yfinance Market data — daily/hourly bars, SPY benchmarks
Polygon.io Historical news articles with per-ticker sentiment (used in backtesting)

Features

Customizable Playbook

The agent ships with a default swing trading playbook (momentum + mean reversion), but the real value is making it yours. Edit entry criteria, position management rules, and risk thresholds through the Settings UI or directly in the playbook/ markdown files. Tune the quant engine parameters — regime thresholds, scoring weights, stop multipliers — to match your trading style.

Playbook Editor

Backtesting

Validate your playbook and quant engine changes against historical market data. Modify a rule, run a backtest, and see how it would have performed — iterate until the strategy fits your risk appetite.

Backtest Cycles

  • Replay EOD → Morning → Intraday cycles on historical datasets
  • Full session tracking: cycles, trades, portfolio metrics, forward/backward price charts
  • Compare runs side-by-side with cumulative returns, drawdown, and exposure benchmarked against SPY

Analysis

Paper Trading

Once satisfied with backtest results, connect to Alpaca's paper trading environment to run the agent against live market data without risking real money.

Paper Trading

  • Start/stop the agent from the dashboard
  • Real-time portfolio tracking: positions, cash, total return
  • Session resume — stop and restart without losing history
  • Same cycle logic as live trading, with paper broker

Prerequisites

  • AWS Account with Bedrock model access enabled (Claude Sonnet or similar)
  • Node.js 18+ and npm (for CDK deployment and frontend)
  • Python 3.11+ (for the agent runtime and API server)
  • AWS CLI configured (aws sts get-caller-identity should succeed)
  • Alpaca API keys (free paper trading account)
  • Polygon.io API key (optional) — required for news-informed backtesting. Without it, backtests run with neutral sentiment (no news signals). Free tier works. Live/paper trading uses yfinance for news instead.

Deployment

The project uses AWS CDK for infrastructure provisioning. A single script handles everything:

# Full deployment (first time)
./deploy.sh

# Deploy only storage (S3 + DynamoDB)
./deploy.sh storage

# Deploy only runtime (ECR + AgentCore)
./deploy.sh runtime

# Fast code sync (no Docker rebuild — updates agents, tools, playbooks)
./deploy.sh sync-code

After deployment, config/cloud_resources.json is generated automatically with your S3 bucket, DynamoDB table, and AgentCore runtime ARN.

Getting Started

1. Deploy infrastructure

git clone https://github.com/kevmyung/swing-trading-agent.git
cd swing-trading-agent

# Deploy all AWS resources
./deploy.sh

2. Install Python dependencies

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

3. Start the dashboard

cd frontend
npm install
npm run dev

This starts both the React frontend (port 5173) and the FastAPI server (port 8000).

4. Configure API keys

Open the dashboard at http://localhost:5173 and go to Settings:

  • Alpaca API Key / Secret — from your Alpaca paper trading account
  • Account Name — identifies your trading session; changing it starts a new session

5. Refresh backtest data

Navigate to Backtest > Fixture Data and click Refresh to download historical market data (S&P 500 list, daily/hourly bars, earnings dates, news articles).

Data Refresh

6. Run a backtest

Navigate to Backtest and select a dataset to evaluate the strategy on historical data.

7. Start paper trading

Navigate to Paper Trading and click Start Agent. The agent will begin executing cycles according to the market schedule.

Project Structure

swing-trading-agent/
ā”œā”€ā”€ agents/            # Core trading logic — EOD, Morning, Intraday cycles
ā”œā”€ā”€ api/               # FastAPI server — REST endpoints for dashboard
ā”œā”€ā”€ backtest/          # Backtesting framework with mock broker
ā”œā”€ā”€ cloud/             # AgentCore entrypoint (main.py for container runtime)
ā”œā”€ā”€ config/            # Settings (pydantic-settings) and cloud resource config
ā”œā”€ā”€ frontend/          # React + TypeScript + Vite dashboard
ā”œā”€ā”€ infra/             # AWS CDK stacks (TypeScript)
ā”œā”€ā”€ playbook/          # Investment decision framework and rules
ā”œā”€ā”€ providers/         # Broker (Alpaca) and market data abstractions
ā”œā”€ā”€ scheduler/         # APScheduler job definitions for trading cycles
ā”œā”€ā”€ state/             # Portfolio state management (positions, cash, stats)
ā”œā”€ā”€ store/             # Session storage (local JSON + DynamoDB/S3)
ā”œā”€ā”€ tools/             # LLM tool definitions (data, research, execution, risk)
ā”œā”€ā”€ main.py            # CLI entrypoint — scheduler, single cycle, or session mode
ā”œā”€ā”€ deploy.sh          # One-command CDK deployment script
└── requirements.txt   # Python dependencies

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache License 2.0. See the LICENSE file.

Release History

VersionChangesUrgencyDate
0.0.0No release found — using repo HEADHigh4/21/2026

Dependencies & License Audit

Loading dependencies...

Similar Packages

ai-trading-agentšŸ¤– Build and optimize an AI trading agent using JavaScript for efficient and intelligent trading decisions on financial markets.main@2026-04-21
hermes-gatešŸ›ļø Hermes Gate — Terminal TUI for managing remote Hermes Agent sessions with auto-reconnect, detach support, and zero config0.0.0
tradingPaper-first SPY options validation platform with broker-backed scorecards, hard risk gates, paired-trade accounting, and live dashboards.main@2026-04-21
ATSAn AI-driven hybrid algorithmic trading bot that dynamically switches between mean-reversion and trend-following strategies based on market regimes, powered by Google Gemini.main@2026-04-19
auto-deep-researcher-24x7šŸ”„ An autonomous AI agent that runs your deep learning experiments 24/7 while you sleep. Zero-cost monitoring, Leader-Worker architecture, constant-size memory.main@2026-04-19