Commit Graph

5 Commits

Author SHA1 Message Date
Andrew Kaszubski 6e52e4190d feat(backtest): add BacktestEngine with slippage and commission models - Issue #42 (57 tests)
Implements comprehensive backtesting framework:
- OrderSide, OrderType, FillStatus enums
- OHLCV bar data and Signal dataclasses
- BacktestConfig, BacktestPosition, BacktestTrade, BacktestResult
- BacktestSnapshot for portfolio tracking over time
- BacktestEngine main class

Slippage Models:
- NoSlippage: Zero slippage (ideal execution)
- FixedSlippage: Fixed amount per share
- PercentageSlippage: Percentage of price
- VolumeSlippage: Volume-impact model with participation ratio

Commission Models:
- NoCommission: Zero commission
- FixedCommission: Fixed per trade
- PerShareCommission: Per share with min/max
- PercentageCommission: Percentage of trade value
- TieredCommission: Tiered by trade value thresholds

Features:
- Historical price data replay with date filtering
- Multi-symbol portfolio support
- Automatic position sizing (equal weight)
- Buy/sell signal execution with slippage
- Cash and position tracking
- Shorting support (configurable)
- Max position percentage limits
- Minimum trade value enforcement
- Strategy callback for dynamic signals
- Portfolio snapshots at each timestamp
- Drawdown tracking with peak detection
- Sharpe and Sortino ratio calculation
- Win rate, profit factor, avg trade P&L
- Total commission and slippage tracking

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 22:55:18 +11:00
Andrew Kaszubski b6eca9ea07 feat(alerts): add SMS channel with Twilio integration - Issue #41 (59 tests)
Implements SMS alert delivery using Twilio API:
- SMSFormat enum (plain, compact, detailed)
- SMSStatus enum (queued, sending, sent, delivered, failed, etc.)
- SMSConfig for Twilio credentials and settings
- SMSMessageResult for delivery tracking
- SMSBatchResult for multi-recipient sends
- SMSMessageFormatter with priority indicators
- SMSChannel implementing AlertChannel protocol
- create_sms_channel factory function

Features:
- E.164 phone number validation
- Three formatting styles (plain, compact, detailed)
- Priority indicators ([!], [!!!]) for high/critical alerts
- Category prefixes (TRD, RSK, SYS, MKT, etc.)
- SMS segment counting (GSM-7 vs Unicode)
- Messaging service SID support
- Priority filtering (send only HIGH+ alerts)
- Batch sending to multiple recipients
- Retry logic with exponential backoff
- Server error retry vs client error fail-fast
- Latency tracking for performance monitoring
- Status callback URL support
- Connection test functionality

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 22:48:00 +11:00
Andrew Kaszubski 795f970aa4 feat(alerts): add Slack channel with webhooks and Block Kit - Issue #40 (44 tests)
Implements Slack integration for alert delivery:
- SlackMessageStyle enum (simple, blocks, attachment)
- SlackConfig for webhook URL, channel, username, icon
- SlackMessageResult for delivery tracking
- SlackMessageFormatter with Block Kit support
- SlackChannel implementing AlertChannel protocol
- create_slack_channel factory function

Features:
- Three formatting styles (simple text, blocks, attachments)
- Priority-based colors and emojis
- Category emojis for visual identification
- @mention support for critical alerts
- Timestamp and source inclusion options
- Data field display in messages
- Webhook URL validation (hooks.slack.com)
- Retry logic with exponential backoff
- Rate limit handling (429 status with Retry-After)
- Server error retry (500+) vs client error fail-fast (400)
- Latency tracking for performance monitoring
- Sync and async delivery methods
- Test webhook functionality

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 22:41:45 +11:00
Andrew Kaszubski bedb59bce0 feat(portfolio): add Performance Metrics with Sharpe, drawdown, returns - Issue #31 (63 tests)
Implements comprehensive portfolio performance analytics:
- Returns calculation (daily, monthly, yearly, cumulative)
- Risk-adjusted metrics (Sharpe, Sortino, Calmar ratios)
- Volatility and downside deviation
- Drawdown analysis with period tracking
- Trade statistics (win rate, profit factor, expectancy)
- Benchmark comparison (alpha, beta, information ratio, tracking error)
- Utility functions (CAGR, rolling returns, period aggregation)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 21:44:15 +11:00
Andrew Kaszubski 6642047eaa feat(portfolio): add Portfolio State for holdings and mark-to-market - Issue #29 (68 tests)
Implements comprehensive portfolio state management:
- Holding dataclass with long/short support and P&L calculations
- CashBalance for multi-currency cash management
- PortfolioState class with:
  - Real-time mark-to-market valuation
  - Multi-currency support with exchange rate conversion
  - Thread-safe state updates
  - Position tracking with average cost calculation
  - Portfolio snapshots for historical tracking
- PriceProvider and ExchangeRateProvider protocols
- Serialization/deserialization support

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-26 21:37:17 +11:00