Skip to content

Implement Phase 2 portfolio construction and Phase 3 research integration#12

Merged
JetSquirrel merged 2 commits into
mainfrom
claude/auto-dev-next-task-items
Mar 31, 2026
Merged

Implement Phase 2 portfolio construction and Phase 3 research integration#12
JetSquirrel merged 2 commits into
mainfrom
claude/auto-dev-next-task-items

Conversation

@Claude

@Claude Claude AI commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Implements portfolio rebalancing pipeline and Content API research feeds as specified in the five-layer harness architecture (spec.md Phase 2 & 3).

Portfolio Construction (internal/portfolio/)

Core logic (463 LOC):

  • SyncCurrent() - Computes current portfolio from account state + quotes with position weights
  • ComputeDiff() - Calculates target vs current delta, generates rebalance actions with quantity estimates
  • ProcessRebalance() - Converts portfolio/rebalance/pending.json to ORDER entries in beancount ledger
  • ValidateTarget() - Ensures target weights sum to 1.0, validates allocations

Data flow:

portfolio/target.json (user/agent writes)
  → portfolio/current.json (controller generates)
  → portfolio/diff.json (controller computes delta)
  → portfolio/rebalance/pending.json (user/agent approves)
  → trade/beancount.txt ORDER entries (controller executes)
  → portfolio/history/{timestamp}.json (controller archives)

Threshold-based rebalancing ignores adjustments <1% or $100 to reduce churn.

Research Feeds (internal/research/)

Content API integration (267 LOC):

  • RefreshFeeds() - Reads research/watchlist.json, fetches news/topics via Content API
  • GenerateSummary() - Scans feeds and quotes, produces research/summary.json availability index

Writes structured feeds to:

  • research/feeds/news/{SYMBOL}/latest.json
  • research/feeds/topics/{SYMBOL}/latest.json

Controller Integration

Added to polling loop (cmd/longbridge-fs/main.go):

  1. Portfolio sync → diff → rebalance processing (after account refresh)
  2. Research refresh (after quote updates, skipped in mock mode)

All operations are non-blocking - failures logged but don't halt the controller.

Type Definitions

Extended internal/model/types.go with:

  • TargetPortfolio, CurrentPortfolio, PortfolioDiff, Adjustment
  • RebalancePending, RebalanceOrder
  • Watchlist, NewsFeed, TopicsFeed, ResearchSummary

Maps directly to file structures defined in spec.md sections 6 & 4.

Deferred

--auto-rebalance mode intentionally omitted - manual approval via pending.json is safer for production. Current workflow requires explicit user/agent confirmation before ORDER generation.

@Claude Claude AI linked an issue Mar 31, 2026 that may be closed by this pull request
…tion

- Add portfolio package with target/current/diff calculation
- Implement rebalance pending.json to ORDER conversion
- Add portfolio history snapshot archiving
- Create research package with watchlist parser
- Integrate Content API for news/topics feeds
- Add portfolio sync and research refresh to controller loop
- All code compiles successfully

Agent-Logs-Url: https://github.com/JetSquirrel/longbridge-fs/sessions/a34a13a5-3680-43d6-8fe1-ba91755dc2cb

Co-authored-by: JetSquirrel <20291255+JetSquirrel@users.noreply.github.com>
@Claude Claude AI changed the title [WIP] Implement next 5 task items for automated development Implement Phase 2 portfolio construction and Phase 3 research integration Mar 31, 2026
@Claude Claude AI requested a review from JetSquirrel March 31, 2026 11:30
@JetSquirrel JetSquirrel marked this pull request as ready for review March 31, 2026 13:46
@JetSquirrel JetSquirrel merged commit a1c2ae6 into main Mar 31, 2026
1 of 2 checks passed
@JetSquirrel JetSquirrel deleted the claude/auto-dev-next-task-items branch March 31, 2026 13:46
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] Implement next 5 task items

2 participants