Skip to content

Automated trading agent for swing trading strategies. Implements algorithmic trading logic, market analysis, and risk management for financial markets with backtesting and live trading capabilities.

Notifications You must be signed in to change notification settings

ITlusions/ITL.SwingAgent

Repository files navigation

Swing Agent v1.6.1

Adds Copilot-friendly instructions.md and scripts/backtest_generate_signals.py (walk-forward historical signal generation). Based on v1.6 enrichments:

  • Multi-timeframe alignment (15m + 1h)
  • Relative strength vs sector ETF (default XLK) + SPY fallback
  • Time-of-day bucket (open/mid/close)
  • Volatility regime filter for KNN priors
  • Signals DB stores expectations + LLM plan + enrichments
  • Centralized database architecture with SQLAlchemy ORM
  • External database support (PostgreSQL, MySQL, etc.)

Quick Start for New Users

1. Installation

python -m venv .venv && source .venv/bin/activate
pip install -e .

2. Your First Signal

# Generate a trading signal for Apple stock
python scripts/run_swing_agent.py --symbol AAPL --interval 30m --lookback-days 30

3. Learn the System

Documentation

πŸ“š Complete Documentation - Everything you need to know

For Users

For Developers

What SwingAgent Does

SwingAgent combines technical analysis, machine learning, and AI to generate 1-2 day swing trading signals:

βœ… Technical Analysis: Fibonacci retracements, trend analysis, momentum indicators
βœ… Pattern Recognition: ML-based historical pattern matching
βœ… AI Insights: OpenAI-powered explanations and action plans
βœ… Risk Management: Automatic stop-loss and take-profit calculations

Example Signal Output

{
  "symbol": "AAPL",
  "entry": {
    "side": "long",
    "entry_price": 185.50,
    "stop_price": 182.20,
    "take_profit": 190.80,
    "r_multiple": 1.61
  },
  "confidence": 0.72,
  "expected_winrate": 0.58,
  "action_plan": "Strong uptrend with Fibonacci support..."
}

Database Configuration

SwingAgent v1.6.1 uses a centralized database architecture with SQLAlchemy ORM. By default, it uses a single SQLite file, but supports external databases for production deployments.

Default (SQLite)

# Uses data/swing_agent.sqlite automatically
python scripts/run_swing_agent.py --symbol AMD --interval 30m --lookback-days 30

External Database (PostgreSQL/MySQL)

# Option 1: Direct URL
export SWING_DATABASE_URL="postgresql://user:pass@localhost:5432/swing_agent"

# Option 2: Individual components
export SWING_DB_TYPE=postgresql
export SWING_DB_HOST=localhost
export SWING_DB_NAME=swing_agent
export SWING_DB_USER=your_username
export SWING_DB_PASSWORD=your_password

# Then run normally
python scripts/run_swing_agent.py --symbol AMD

CNPG (CloudNativePG) for Kubernetes

# For Kubernetes deployments with CNPG operator
export SWING_DB_TYPE=cnpg
export CNPG_CLUSTER_NAME=swing-postgres
export CNPG_NAMESPACE=default
export SWING_DB_NAME=swing_agent
export SWING_DB_USER=swing_user
export SWING_DB_PASSWORD=your_password

# Test configuration
python scripts/test_cnpg.py

Features

  • Centralized Storage: Signals and vector patterns stored in single database
  • Multiple Backends: SQLite for development, PostgreSQL/MySQL for production
  • Kubernetes Ready: Native CloudNativePG (CNPG) support for scalable deployments
  • Migration Tools: Automated migration from legacy separate databases

For detailed database setup:

Run live signal

python scripts/run_swing_agent.py --symbol AMD --interval 30m --lookback-days 30 --sector XLK

Generate historical signals (no look-ahead)

python scripts/backtest_generate_signals.py --symbol AMD --interval 30m --lookback-days 180 --warmup-bars 80 --sector XLK --no-llm

Evaluate stored signals

python scripts/eval_signals.py --max-hold-days 2.0

Backfill vector store from signal history

python scripts/backfill_vector_store.py

Performance snapshot

python scripts/analyze_performance.py

Train ML models

python scripts/train_ml_model.py --db data/swing_agent.sqlite

Generates baseline classification and regression models from the vector store and saves them to models/.

Database Migration

From Separate Files to Centralized Database

# Migrate existing separate SQLite files to centralized database
python -m swing_agent.migrate --data-dir data/

From SQLite to External Database

# First set up external database connection
export SWING_DATABASE_URL="postgresql://user:pass@localhost:5432/swing_agent"

# Migrate from centralized SQLite to external database
python -m swing_agent.migrate --sqlite-to-external "$SWING_DATABASE_URL"

Database Utilities

# Show current database configuration
python scripts/db_info.py --info

# Test database connection
python scripts/db_info.py --test

# Initialize database tables
python scripts/db_info.py --init

About

Automated trading agent for swing trading strategies. Implements algorithmic trading logic, market analysis, and risk management for financial markets with backtesting and live trading capabilities.

Topics

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •