Skip to content

Implement --auto-rebalance mode, signal/definitions/ declarative config, and built-in indicators#16

Merged
JetSquirrel merged 2 commits into
mainfrom
copilot/implement-next-items-phase-2-3
Mar 31, 2026
Merged

Implement --auto-rebalance mode, signal/definitions/ declarative config, and built-in indicators#16
JetSquirrel merged 2 commits into
mainfrom
copilot/implement-next-items-phase-2-3

Conversation

Copilot AI commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Advances Phase 2 (v0.4.0) and Phase 3 (v0.5.0) of the Harness pipeline: auto-rebalance closes the portfolio drift → order loop without manual intervention; the signal layer adds declarative config + built-in indicator computation.

--auto-rebalance mode (Phase 2)

New AutoCreatePending() in internal/portfolio/rebalance.go reads portfolio/diff.json and auto-generates portfolio/rebalance/pending.json when requires_rebalance: true. Guards against double-execution (no-op if pending.json already exists). Wired into the controller loop after ComputeDiff().

longbridge-fs controller --root ./fs --auto-rebalance

Signal definitions + built-in indicators (Phase 3)

New internal/signal/ package:

  • definitions.goListDefinitions() scans signal/definitions/*.json, filters enabled: true; validates type as builtin or external
  • indicator.go — Three built-in indicators reading close prices from quote/hold/{SYMBOL}/D.json:
    • SMA_CROSS — fast/slow SMA crossover with relative-distance strength
    • RSI — Wilder RSI with configurable overbought/oversold thresholds
    • PRICE_CHANGE — percentage change over a configurable window
  • signal.goComputeAll() orchestrates definition scan → kline load → indicator dispatch → per-symbol output/latest.json + history.jsonlsignal/active.json aggregation
  • output.goWriteOutput, AppendHistory, WriteActiveSignals

Example signal definition (signal/definitions/sma_crossover.json):

{
  "name": "sma_crossover",
  "type": "builtin",
  "version": 1,
  "params": { "indicator": "SMA_CROSS", "fast_period": 5, "slow_period": 20 },
  "symbols": ["AAPL.US"],
  "enabled": true
}

ComputeAll() is called each controller cycle (after research refresh, before portfolio sync) via signalpkg alias to avoid collision with os/signal. Also completes the signal/active.json aggregation item from Phase 3.

New model types added: SignalDefinition, SignalOutput, SignalEntry, ActiveSignals, ActiveSignalEntry.

…ors (SMA_CROSS, RSI, PRICE_CHANGE)

Agent-Logs-Url: https://github.com/JetSquirrel/longbridge-fs/sessions/4995d1ec-dfc9-44da-922a-2ab77dc7ed11

Co-authored-by: JetSquirrel <20291255+JetSquirrel@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement next items for auto-rebalance and built-in metrics Implement --auto-rebalance mode, signal/definitions/ declarative config, and built-in indicators Mar 31, 2026
Copilot AI requested a review from JetSquirrel March 31, 2026 16:08
@JetSquirrel JetSquirrel marked this pull request as ready for review March 31, 2026 17:04
@JetSquirrel JetSquirrel merged commit c136d78 into main Mar 31, 2026
2 checks passed
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.

[Auto-Dev] Iteration 1: implement next 3 items

2 participants