Skip to content

Add a self-contained AAPL daily strategy backtester with risk controls and documentation - #10

Draft
Netrade1 with Copilot wants to merge 5 commits into
mainfrom
copilot/complete-backtestable-trading-strategy
Draft

Add a self-contained AAPL daily strategy backtester with risk controls and documentation#10
Netrade1 with Copilot wants to merge 5 commits into
mainfrom
copilot/complete-backtestable-trading-strategy

Conversation

Copilot AI commented Jul 6, 2026

Copy link
Copy Markdown

This change adds a complete, backtestable implementation of the requested AAPL daily strategy: EMA(20/50) crossover with RSI, trend, volume, and ATR filters, plus explicit position sizing and exit rules. It turns the strategy specification into runnable code and repository-level documentation rather than a prose-only design.

  • Strategy engine

    • Adds src/aapl_strategy.py with:
      • OHLCV CSV loading and validation
      • indicator calculations for EMA, SMA, RSI, and ATR
      • next-open entry/exit execution
      • 2% equity-at-risk position sizing using the 12% hard stop
      • exit handling for hard stop, trailing stop, profit target, and bearish EMA cross
      • summary metrics including profit factor, drawdown, win rate, Sharpe, CAGR, and final equity
  • Execution model

    • Encodes the strategy as daily close signal evaluation with fills at the next session open
    • Applies explicit slippage assumptions in both directions
    • Keeps the implementation cash-constrained so position size cannot exceed available capital
  • Test coverage

    • Adds tests/test_aapl_strategy.py covering:
      • SMA / EMA / RSI / ATR computations
      • position sizing math
      • CSV validation for invalid market data
      • a deterministic trade path that exercises live strategy behavior
  • Documentation

    • Replaces the placeholder README with a usable strategy spec:
      • entry and exit rules
      • risk model
      • data requirements and assumptions
      • expected backtest shape and limitations
      • CLI usage for running the backtester
  • Repo hygiene

    • Adds .gitignore entries for Python bytecode and __pycache__

Example usage:

python src/aapl_strategy.py /absolute/path/to/aapl_daily.csv

Core sizing logic now implemented in code:

stop_price = entry_price * (1 - config.hard_stop_pct)
risk_budget = equity * config.risk_per_trade
shares = floor(risk_budget / (entry_price - stop_price))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants