Commit Graph

3 Commits

Author SHA1 Message Date
ahmet guzererler 02cbaecf62
feat: Add macro scanner feedback loop and lessons memory (#124)
* feat: add macro scanner feedback loop and lessons memory

- Implements `LessonStore` to persist JSON screening lessons
- Adds `selection_reflector.py` to fetch performance and news, and generate LLM lessons
- Adds `memory_loader.py` to filter negative lessons into `FinancialSituationMemory`
- Integrates a rejection gate in `candidate_prioritizer.py` based on past negative lessons
- Adds `reflect` command to CLI

Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>

* feat: update macro scanner feedback loop for dual-lesson output (Trend DNA)

- Update `selection_reflector.py` to calculate exact terminal returns, `mfe_pct`, `mae_pct`, and `days_to_peak`.
- Update LLM prompt to generate distinct `screening_advice` and `exit_advice`.
- Update `lesson_store` tests to reflect new schema.
- Update `memory_loader.py` to use `screening_advice` for negative selection filtering.
- Update `micro_summary_agent.py` to inject `exit_advice` into PM context for current holdings.
- Update `cli/main.py` default horizons to `30,90` and print dual-advice columns.

Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>

* fix: resolve bugs in macro scanner feedback loop

- Address Key mismatch (stock_return_pct vs terminal_return_pct)
- Fix missing persistence of mfe_pct and mae_pct
- Use create_report_store() instead of raw ReportStore() in load_scan_candidates
- Clean up unused imports in fetch_news_summary
- Ensure default horizons match code in cli description
- Create isolated `_local_safe_pct` to remove cross-module dependency

Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>

* fix: address PR 124 feedback on macro scanner memory feedback loop

- Use `l.get('screening_advice')` gracefully in `memory_loader` to prevent KeyErrors.
- Properly instantiate `selection_memory` inside the graph in `portfolio_setup.py` and pass it to the prioriziation rejection gate.

Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
2026-03-26 23:44:44 +01:00
copilot-swe-agent[bot] 96a2c79cb3 Implement Portfolio Manager Phases 2-5: risk evaluation, candidate prioritization, holding reviewer agent, PM decision agent, trade executor, and portfolio graph orchestration
Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
2026-03-20 14:44:22 +00:00
copilot-swe-agent[bot] 1444e8438c feat: Portfolio Manager Phases 2-5 — risk evaluation, candidate prioritization, LLM agents, trade executor
- tradingagents/portfolio/risk_evaluator.py: pure-Python risk metrics
  (log returns, Sharpe, Sortino, VaR, max drawdown, beta, sector
  concentration, portfolio/holding aggregation, constraint checking)
- tradingagents/portfolio/candidate_prioritizer.py: conviction × thesis ×
  diversification × held_penalty scoring; sorted candidate ranking
- tradingagents/portfolio/trade_executor.py: executes BUY/SELL decisions
  (SELLs first), pre-flight constraint checks, EOD snapshot
- tradingagents/agents/portfolio/holding_reviewer.py: LLM agent using
  run_tool_loop() — reviews all holdings, outputs HOLD/SELL JSON
- tradingagents/agents/portfolio/pm_decision_agent.py: pure-reasoning LLM
  agent (no tools) — produces structured BUY/SELL/HOLD decision JSON
- tradingagents/portfolio/portfolio_states.py: PortfolioManagerState
  (MessagesState + Annotated _last_value reducers)
- tradingagents/graph/portfolio_setup.py: PortfolioGraphSetup — sequential
  6-node workflow with factory-pattern non-LLM nodes
- tradingagents/graph/portfolio_graph.py: PortfolioGraph — mirrors
  ScannerGraph pattern with mid/deep_think LLM tiers
- tests/portfolio/test_risk_evaluator.py: 28 tests (pure Python)
- tests/portfolio/test_candidate_prioritizer.py: 10 tests (pure Python)
- tests/portfolio/test_trade_executor.py: 10 tests (MagicMock repo)
- tradingagents/portfolio/__init__.py: exports new symbols

All 93 tests pass (4 integration skipped, no regressions).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-20 14:38:48 +00:00