Skip to content

feat(trading-strategies): momentum-rotation strategy (top 5, monthly rebalance)#1138

Open
bennycode wants to merge 3 commits into
feat/momentum-scorecardfrom
feat/momentum-rotation
Open

feat(trading-strategies): momentum-rotation strategy (top 5, monthly rebalance)#1138
bennycode wants to merge 3 commits into
feat/momentum-scorecardfrom
feat/momentum-rotation

Conversation

@bennycode

Copy link
Copy Markdown
Owner

Builds the live momentum-rotation strategy: hold the top 5 picks from momentum + scorecard, equal-weight, and rebalance monthly (when the 12-1 momentum window rolls).

Stacked on #1136 (the scorecard). Base will retarget to main once that merges.

Design

  • computeRebalance (pure, tested): equal-weight, low-churn. Sell names that left the target set, buy new entrants at equity / positionCount, hold unchanged names untouched. An unchanged set produces an empty plan (no fees).
  • MomentumRotation (orchestrator): S&P 500 12-1 momentum -> scorecard -> best 5 -> read Alpaca positions/equity -> plan. plan() is read-only (preview/paper); rebalance() places the orders (sells first to free cash, then notional buys).
  • Shared momentumRanking util: the price-fetch + rank logic is extracted from the report so the report and rotation use one implementation (DRY).

Scope / constraint

The scorecard depends on current analyst data (no point-in-time history), so this is live/forward only and cannot be backtested faithfully.

Verification

Read-only plan() run against a live account produced a correct minimal plan (held the 3 unchanged names, swapped the 2 that changed). Full package suite: 243 tests green.

A live strategy that holds the top picks from momentum + scorecard and rebalances
when momentum changes (monthly, since the 12-1 window is a monthly snapshot).

- computeRebalance: pure, equal-weight, low-churn rebalance. Liquidate names that
  left the target set, buy new entrants at an equal-weight slice (equity / count),
  and leave unchanged holdings alone, so an unchanged set trades nothing.
- MomentumRotation: orchestrator that ranks the S&P 500 by 12-1 momentum, scores
  the top winners, keeps the best 5, reads Alpaca positions/equity, and either
  previews the trades (plan(), read-only) or executes them (rebalance()).
- Extract the momentum ranking (price fetch + rank) into a shared util so the
  report and the rotation share one implementation.

The scorecard uses current analyst data, so this runs forward only (live/paper),
not as a backtest. Verified end to end with a read-only plan() against a live account.
…ation provider-agnostic

Lets the momentum rotation run on free TipRanks data instead of paid FMP.

- exchange: new TipRanksAPI client. The TipRanks MCP is a stateless HTTP RPC, so a
  single tools/call POST returns the data (no SDK or session). Two batch calls
  (getAssetsData + getTechnicalAnalysis) cover the whole scorecard.
- TipRanksScorecard: orchestrator that feeds TipRanks data into the existing pure
  computeTipRanksScorecard, handling nulls.
- MomentumRotation now takes a PortfolioScorer (a rank() method) instead of a fixed
  FMP scorecard, so either provider can drive it. Added a matching rank() to the FMP
  MomentumScorecard.

Trade-off: the TipRanks rubric is backward-looking (no forward P/E, growth, revision,
or falling-knife guard) and its quotes can lag, so it trades a weaker basket — free,
but not as sharp as FMP. Verified end to end with a read-only plan().
A one-shot entrypoint that runs the momentum rotation from env config. Reads keys
from packages/exchange/.env (Alpaca + TipRanks/FMP), builds the rotation, and prints
the plan.

- Dry-run by default (read-only, no orders). Set ROTATION_EXECUTE=true to place them.
- Scorer defaults to the free TipRanks; ROTATION_SCORER=fmp switches to FMP.
- ALPACA_USE_PAPER=true targets the paper account.

The rebalance is low-churn and idempotent, so it can be cron'd on any cadence
(monthly is natural) and only trades when the top picks actually change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant