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.
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.
| 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 |
- 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.
| 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) |
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.
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.
- 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
Once satisfied with backtest results, connect to Alpaca's paper trading environment to run the agent against live market data without risking real money.
- 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
- 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-identityshould 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.
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-codeAfter deployment, config/cloud_resources.json is generated automatically with your S3 bucket, DynamoDB table, and AgentCore runtime ARN.
git clone https://github.com/kevmyung/swing-trading-agent.git
cd swing-trading-agent
# Deploy all AWS resources
./deploy.shpython -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtcd frontend
npm install
npm run devThis starts both the React frontend (port 5173) and the FastAPI server (port 8000).
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
Navigate to Backtest > Fixture Data and click Refresh to download historical market data (S&P 500 list, daily/hourly bars, earnings dates, news articles).
Navigate to Backtest and select a dataset to evaluate the strategy on historical data.
Navigate to Paper Trading and click Start Agent. The agent will begin executing cycles according to the market schedule.
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
See CONTRIBUTING for more information.
This project is licensed under the Apache License 2.0. See the LICENSE file.






