feat(data): extend market data provider with charts, fundamentals, and quant analysis

Adds a stock data cache layer and indicator helpers (MA/RSI/MACD), expands
the MarketDataProvider interface with candles, fundamentals, related-data,
and quant analysis, and threads tags + source attribution through the
shared types. Updates affected agent tests.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-19 23:20:42 +08:00
parent 6092675f8d
commit 870b9cb2b1
12 changed files with 2187 additions and 32 deletions

View File

@@ -60,18 +60,19 @@ function analyzeEarnings(snapshot: StockSnapshot, now: Date): EarningsSignal {
}
function analyzeValuation(snapshot: StockSnapshot): ValuationSignal {
const stockPe = snapshot.pe;
const peerPes = snapshot.peers.map((peer) => peer.pe).filter((pe) => Number.isFinite(pe) && pe > 0);
if (!Number.isFinite(snapshot.pe) || snapshot.pe <= 0 || peerPes.length === 0) {
if (!Number.isFinite(stockPe) || stockPe === undefined || stockPe <= 0 || peerPes.length === 0) {
return { label: "unknown" };
}
const peerAveragePe = round(peerPes.reduce((sum, pe) => sum + pe, 0) / peerPes.length, 2);
const spreadPct = round((snapshot.pe - peerAveragePe) / peerAveragePe, 4);
const spreadPct = round((stockPe - peerAveragePe) / peerAveragePe, 4);
const label = spreadPct <= -0.15 ? "discount" : spreadPct >= 0.15 ? "premium" : "fair";
return {
label,
stockPe: snapshot.pe,
stockPe,
peerAveragePe,
spreadPct
};