feat(trading-strategies): momentum-rotation strategy (top 5, monthly rebalance)#1138
Open
bennycode wants to merge 3 commits into
Open
feat(trading-strategies): momentum-rotation strategy (top 5, monthly rebalance)#1138bennycode wants to merge 3 commits into
bennycode wants to merge 3 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).
Design
computeRebalance(pure, tested): equal-weight, low-churn. Sell names that left the target set, buy new entrants atequity / 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).momentumRankingutil: 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.