Featured image of post Trading Agent Dev Log #7 — DCF Valuation, Portfolio Risk Analysis, and the 6th Expert

Trading Agent Dev Log #7 — DCF Valuation, Portfolio Risk Analysis, and the 6th Expert

Adding DCF sensitivity analysis, portfolio risk metrics (VaR, beta, correlation), and a news/macro analyst as the sixth expert in the signal pipeline, plus DART integration

Overview

Previous: #6

In #7, the trading agent’s analytical capabilities were significantly expanded across 34 commits. Work included: DCF valuation with sensitivity heatmap, portfolio risk analysis (VaR, beta, sector concentration), adding the 6th expert (news/macro analyst) to the signal pipeline, DART disclosure integration, and investment memo export.


DCF Valuation and Sensitivity Analysis

Background

The existing signal pipeline had no quantitative valuation model. DCF (Discounted Cash Flow) is essential for estimating fair value, and showing sensitivity across scenarios — rather than a single point estimate — is what makes it useful for investment decisions.

Implementation

A DCF valuation service was implemented and a sensitivity heatmap table showing outcomes across WACC and growth rate combinations was added to ValuationView. The frontend visualizes this as a heatmap, making it immediately clear under which assumptions the current price looks undervalued or overvalued.

Peer comparison was also added — pulling valuation data for same-sector companies from DART so relative positioning can be assessed.

Unit tests were added to verify the core logic of the DCF valuation and portfolio risk services.


Portfolio Risk Analysis

VaR, Beta, and Sector Concentration

Portfolio-level risk analysis was implemented:

  • VaR (Value at Risk): Maximum expected loss at a given confidence interval
  • Beta: Calculated from actual portfolio data
  • Sector concentration: Detects overexposure to any one sector
  • Correlation matrix heatmap: Visualizes pairwise correlation across holdings

KOSPI200 constituent sector data was collected from NAVER Finance for sector classification.


Signal Pipeline Expansion

The 6th Expert: News/Macro Analyst

A news/macro analyst was added alongside the existing five experts (technical, fundamental, sentiment, flow, and valuation). This expert analyzes macroeconomic news and stock-specific events and incorporates them into the signal.

Google News RSS fallback — To improve news collection reliability, Google News RSS was added as a fallback. When the primary news source is unstable, it switches automatically.

DART Integration

  • Catalyst Calendar: DART disclosure schedule displayed as a timeline UI for a quick view of upcoming material events
  • Insider Trading: DART insider trading data integrated into the signal pipeline
  • Foreign/institutional investor flows: Foreign and institutional buying/selling data added to the flow analysis expert

DB Schema Expansion

8 new tables, the ANALYST role, and metadata initialization were added — all data models for the new features defined in a single pass.


Signal History and Comparison

Signal history snapshots and timeline comparison were added. Past signals can now be compared against the current signal to track how views have changed over time — useful for post-hoc evaluation of signal consistency and predictive power.


Frontend UI Improvements

  • SignalCard expansion: Expert opinion expansion display, risk_notes rendering, compact/expanded view toggle
  • SignalDetailModal: Drilldown into related order history
  • ReportViewer: Trade PnL column and rr_score color coding added
  • ScheduleManager: Cron editing and run-now button; agent names and friendly task labels displayed
  • DashboardView: report.generated event handling, performance endpoint with period selector

Investment Memo Export

A feature was added to export investment memos in HTML and DOCX formats based on signal data. Word documents are generated using python-docx.


Server Stability

MCP (Model Context Protocol) connection stability was improved:

  • Fixed missing await on async MCP context methods
  • Added auto-reconnect logic on connection failure

Server logs were monitored periodically. websockets library deprecated API warnings and other runtime errors were classified, and only codebase-level issues were selected for fixing.


Configuration Expansion

  • initial_capital and min_rr_score added to settings and the risk-config API
  • New components aligned with the existing design system
  • Vite ESM resolution error fixed (using import type)
  • Lint errors (unused vars) cleaned up

Commit Log

MessageScope
feat: show agent name and friendly task labels in ScheduleManagerfrontend
style: align new components with existing design systemfrontend
fix: use import type for ScheduledTask to fix Vite ESM resolutionfrontend
feat: add Google News RSS fallback for news collection stabilitybackend
feat: add compact/expanded view toggle to SignalCardfrontend
feat: add DOCX investment memo export with python-docxbackend
feat: add real portfolio beta calculation and correlation matrix heatmapbackend + frontend
feat: add DCF sensitivity heatmap table to ValuationViewfrontend
test: add unit tests for DCF valuation and portfolio risk servicestest
feat: populate kospi200_components sector data from NAVER Financebackend
fix: await async MCP context methods and add auto-reconnect on failurebackend
fix: replace explicit any types with proper interfaces in SignalCardfrontend
feat: add investment memo HTML export from signal databackend
feat: add VaR, beta, sector concentration risk analysisbackend
feat: add DCF valuation with sensitivity tablebackend
feat: add signal history snapshots and timeline comparisonfull-stack
feat: add peer comparison with sector-based DART valuationbackend
feat: add news/macro analyst as 6th expert in signal pipelinebackend
feat: add catalyst calendar with DART disclosures and timeline UIfull-stack
feat: add DART insider trading data to signal pipelinebackend
feat: add foreign/institutional investor trend to signal pipelinebackend
feat: add 8 new DB tables, ANALYST role, and metadata initbackend
fix: resolve lint errors (unused vars) in DashboardView and SignalCardfrontend
feat: add report.generated event handling in DashboardViewfrontend
feat: add initial_capital and min_rr_score to settings and risk-config APIfull-stack
feat: add ScheduleManager with cron editing and run-now buttonfrontend
feat: add trade PnL column and rr_score color coding to ReportViewerfrontend
feat: add SignalDetailModal with related orders drilldownfrontend
feat: add expert opinion expansion and risk_notes display to SignalCardfrontend
feat: use correct performance endpoint with period selector and metricsfrontend

Insight

34 commits is the highest count in the series so far. The trading agent is evolving from a simple signal generator into a comprehensive analysis platform covering portfolio risk management, valuation analysis, and disclosure monitoring. The addition of the 6th expert (news/macro) and the DART integration are particularly significant — they actively leverage Korea-specific data sources. The DCF sensitivity heatmap and portfolio correlation matrix are good examples of conveying complex data intuitively through visualization. On the stability front, the MCP auto-reconnect and periodic log monitoring pattern is now established — a meaningful step toward production-grade reliability.

Built with Hugo
Theme Stack designed by Jimmy