Algorithmic trading system for the Argentine market (CEDEARs). Combines data ingestion, technical analysis, strategy backtesting, signal generation, and portfolio management.
- Docker and Docker Compose
- Python 3.12+
- Poetry
git clone https://github.com/MauroPerna/ar-trading-bot
cd ar-trading-bot
# Copy environment file
cp .env.example .envThe default .env values work out of the box with docker-compose.
docker-compose up -dThis starts:
- PostgreSQL 16 on port 5432
- Redis 7 on port 6379
poetry install# if the plugin is not yet installed
poetry self add poetry-plugin-shellpoetry shellpoetry run alembic upgrade headpoetry run python main.pyThe API will be available at http://localhost:8000
# Health check
curl http://localhost:8000/health
# API docs
open http://localhost:8000/docssrc/
application/ # FastAPI app, DI container, lifecycle
domain/
etl/ # Data extraction, transformation, enrichment
signals/ # Signal generation and aggregation
strategies/ # Backtesting engine and strategy selection
portfolio/ # Portfolio optimization (Markowitz, HRP)
trading/ # Trade execution (FakeBroker for dev)
infrastructure/
broker/ # Broker clients (IOL, FakeBroker)
data/ # Data providers (yfinance)
database/ # SQLAlchemy models and repositories
scheduler/ # APScheduler jobs
config/ # Settings and configuration
Transforms OHLCV data into actionable signals:
- Technical indicators (pandas-ta): RSI, MACD, Bollinger Bands, etc.
- Custom analyzers: Breakout, Fair Value Gap, Trend
- Interpreters: Momentum, Structure, Volume, Volatility, Risk
Backtesting engine powered by backtesting.py:
- Fetches historical data from yfinance
- Runs signal engine
- Evaluates multiple strategies
- Ranks by Sharpe ratio, drawdown, win rate
- Persists best strategy per symbol
Two optimizers available:
- Markowitz: Mean-variance optimization (max Sharpe)
- HRP: Hierarchical Risk Parity
StrategyPerTickerJob: Monthly strategy re-evaluationGenerateSignalsJob: Hourly signal generationPortfolioWeightsJob: Monthly portfolio rebalancing
poetry run pytestdevelopment: Auto-creates default portfolio, enables hot reloadproduction: Requires manual setup, no auto-seeding
Key environment variables:
| Variable | Description | Default |
|---|---|---|
DB_URL |
PostgreSQL connection string | - |
ENVIRONMENT |
development/production | development |
LOG_LEVEL |
DEBUG/INFO/WARNING/ERROR | INFO |
SCHEDULER_TIMEZONE |
Timezone for jobs | America/Argentina/Buenos_Aires |
IOL_USERNAME |
IOL broker username | - |
IOL_PASSWORD |
IOL broker password | - |
# Stop the API (Ctrl+C in the terminal)
# Stop Docker services
docker-compose down
# Stop and remove volumes (clean slate)
docker-compose down -v