40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
# TradingAgents/graph/signal_processing.py
|
|
|
|
from typing import Any
|
|
|
|
from tradingagents.agents.utils.decision_utils import CANONICAL_RATINGS, extract_rating
|
|
|
|
|
|
class SignalProcessor:
|
|
"""Processes trading signals to extract actionable decisions."""
|
|
|
|
def __init__(self, quick_thinking_llm: Any):
|
|
"""Initialize with an LLM for processing."""
|
|
self.quick_thinking_llm = quick_thinking_llm
|
|
|
|
def process_signal(self, full_signal: str) -> str:
|
|
"""
|
|
Process a full trading signal to extract the core decision.
|
|
|
|
Args:
|
|
full_signal: Complete trading signal text
|
|
|
|
Returns:
|
|
Extracted rating (BUY, OVERWEIGHT, HOLD, UNDERWEIGHT, or SELL)
|
|
"""
|
|
parsed = extract_rating(full_signal)
|
|
if parsed in CANONICAL_RATINGS:
|
|
return parsed
|
|
|
|
messages = [
|
|
(
|
|
"system",
|
|
"You are an efficient assistant that extracts the trading decision from analyst reports. "
|
|
"Extract the rating as exactly one of: BUY, OVERWEIGHT, HOLD, UNDERWEIGHT, SELL. "
|
|
"Output only the single rating word, nothing else.",
|
|
),
|
|
("human", full_signal),
|
|
]
|
|
|
|
return self.quick_thinking_llm.invoke(messages).content
|