diff --git a/.coverage b/.coverage new file mode 100644 index 0000000..67c8e4d Binary files /dev/null and b/.coverage differ diff --git a/README.md b/README.md index 97004f5..84f826e 100644 --- a/README.md +++ b/README.md @@ -1,71 +1,60 @@ # alloc -Reinforcement-learning portfolio allocation engine that trains actor-critic policy networks on multi-frequency market data and produces optimal asset allocations for a fixed basket of tickers. +**Multi-asset portfolio management system using DDPG reinforcement learning.** -## Operating Philosophy +`alloc` trains Deep Deterministic Policy Gradient (DDPG) actor-critic networks on multi-frequency market data (hourly, daily, weekly) and produces optimal asset allocations for a fixed basket of tickers. Each training run yields a short-lived model snapshot tuned to current market conditions — when the regime shifts, you retrain. -- Every model is a short-lived snapshot optimized for current market conditions. Once it drifts, you retire it and train a new one. -- Overfitting to the latest regime is a feature — each snapshot captures what works now, not what generalizes forever. -- The workflow is cyclical: ingest fresh data → spawn candidates → pick the strongest metrics → deploy → repeat. +## Table of Contents -## Architecture +- [Project Overview](#project-overview) +- [Installation](#installation) +- [Usage](#usage) +- [Architecture](#architecture) +- [Testing](#testing) +- [License](#license) +- [Contributing](#contributing) -**Actor–Critic (DDPG-style)** policy network: +--- -- **Actor** proposes allocation percentages across a fixed basket of assets + cash. Uses per-asset branches with varying widths to prevent symmetric learning collapse. A cash constraint layer guarantees allocations sum to 1.0 with a configurable minimum cash floor. -- **Critic** evaluates each proposed allocation by estimating expected future return via Q-value regression. -- Target networks are soft-updated for stable learning. Experience replay breaks temporal correlation. +## Project Overview -**Multi-objective reward function:** +### Purpose -| Component | Purpose | -|---|---| -| Portfolio return | Weighted sum of asset returns | -| Risk penalty | Volatility-adjusted drawdown | -| Transaction cost | Penalizes unnecessary turnover | -| Diversification bonus | Shannon entropy + HHI — rewards spreading risk | -| Concentration penalty | Quadratic penalty on oversized positions | - -**Multi-frequency state construction:** - -Each tick's state combines 24 hourly returns, 10 daily returns, and 4 weekly returns per asset — giving the model short-term momentum, medium-term trend, and long-term direction. A `day_index` gate prevents lookahead bias during backtest. +`alloc` is a reinforcement-learning portfolio allocation engine designed for systematic trading. It: -## Quick Start +1. **Fetches** multi-frequency price data (hourly, daily, weekly) from Polygon.io. +2. **Builds** fixed-dimension state vectors from normalised price windows and current allocations. +3. **Trains** a DDPG actor-critic pair to learn an allocation policy that maximises a composite reward signal combining return, risk, transaction costs, diversification, and concentration. +4. **Simulates** portfolio rebalancing with realistic trade execution (shortfall scaling, transaction costs, cash constraints). +5. **Orchestrates** multi-trial training workflows that score and rank candidate models by Sharpe ratio and outperformance vs. buy-and-hold. -```bash -# Install dependencies -pip install -r requirements.txt +### Operating Philosophy -# Configure Polygon.io API key -cp .env.example .env -# Edit .env, set POLYGON_API_KEY +- **Every model is a short-lived snapshot** optimised for current market conditions. Once it drifts, retire it and train a new one. +- **Overfitting to the latest regime is a feature** — each snapshot captures what works now, not what generalises forever. +- **The workflow is cyclical**: ingest fresh data → spawn candidates → pick the strongest metrics → deploy → repeat. -# Train a model on a basket of tickers -python -m alloc.core --backtest \ - --tickers AAPL,META,GOOG,NVDA \ - --trading-days 242 \ - --plot +### Key Modules -# Get allocation recommendation from trained model -python -m alloc.core --predict \ - --tickers AAPL,META,GOOG,NVDA \ - --model-path results/my_model -``` - -## Repository Layout +| Module | Responsibility | +|---|---| +| `alloc.lib.client` | Polygon.io API wrapper with disk caching | +| `alloc.lib.cache` | Disk-based cache with configurable TTL per data type | +| `alloc.models.data` | Multi-frequency data fetching and state vector construction | +| `alloc.models.networks` | DDPG actor-critic networks and replay buffer | +| `alloc.models.portfolio` | Portfolio tracking, trade execution, reward calculation | +| `alloc.core` | Simulation runner and results serialisation | +| `alloc.utils.workflow` | Multi-trial training orchestration and scoring | +| `alloc.cli` | Command-line interface for the training workflow | +| `alloc.config.settings` | Environment-driven configuration management | -- `alloc/` — Core Python package (networks, portfolio engine, data pipeline, configuration) -- `utils/` — CLI entry points and workflow tools -- `tests/` — Test suite -- `scripts/` — Bootstrap and health-check helpers -- `adr/` — Architecture decision records +--- -## Testing +## Installation -```bash -pytest tests/ -x -q -``` +### Prerequisites -## License +- Python ≥ 3.10 +- A [Polygon.io](https://polygon.io) API key -MIT +### Steps diff --git a/tickets/TICKET-035.md b/tickets/TICKET-035.md new file mode 100644 index 0000000..d2ff16e --- /dev/null +++ b/tickets/TICKET-035.md @@ -0,0 +1,21 @@ +# TICKET-035: Create README.md + +**Module:** `README.md` (new) +**Priority:** High — project documentation is essential for onboarding and usage + +## What to Implement + +Create `README.md` with: +1. Project overview and purpose +2. Installation instructions (pip install -e .) +3. Usage examples (python -m alloc --help, CLI examples) +4. Architecture diagram (modules and data flow) +5. Testing instructions (pytest, ruff, mypy) +6. License and contribution guidelines + +## Verification + +- README.md exists and is well-formatted +- Links work, examples are accurate +- ruff check alloc/ still passes +- mypy alloc/ --ignore-missing-imports still passes