💰

TradingAgentsを使ってみた

に公開

TradingAgents とは

TradingAgents は、実世界の金融取引組織における職能分担を模倣することで、LLMを用いた金融市場分析および取引判断の研究を支援する目的で設計された、マルチエージェント型のフレームワークです。

https://github.com/TauricResearch/TradingAgents

各エージェントは以下のような役割を担い、段階的に分析を進めていきます:

アナリスト層(分析の基盤)

  • ファンダメンタルズアナリスト:企業財務・業績データをもとに内在価値とリスクを評価
  • センチメントアナリスト:SNSや市場心理をスコアリングし短期的ムードを推定
  • ニュースアナリスト:グローバルニュースの影響を解釈
  • テクニカルアナリスト:テクニカル指標に基づきパターン分析と予測を実行

リサーチ層(議論と評価)

  • 強気派/弱気派研究者:上記の分析結果をもとに構造的な賛否議論を実施
  • 多様な観点からのリスクと機会の評価 を通じて、バランスの取れた提言を行います

意思決定層(取引とリスク)

  • トレーダー:最終的な分析結果を統合し、具体的な取引案を提示
  • リスク管理チーム:市場の変動性やリスクファクターを検証し、必要に応じて提案を修正
  • ポートフォリオマネージャー:最終的な承認を下し、仮想取引所にて実行

環境構築と実行方法

1. リポジトリのクローン

git clone https://github.com/TauricResearch/TradingAgents.git
cd TradingAgents

2. Python仮想環境の準備(例:conda)

conda create -n tradingagents python=3.13
conda activate tradingagents
pip install -r requirements.txt

3. APIキーの設定(※すべて無料枠で利用可能)

export FINNHUB_API_KEY=your_finnhub_api_key
export OPENAI_API_KEY=your_openai_api_key

CLIによる動作確認

CLIインターフェースを利用して、エージェントによる分析・議論・取引判断のプロセスを確認できます。

python -m cli.main

ティッカー、分析日、LLM、分析の深度などを選択後、実行結果が順次表示されます。

システムフロー

以下ではユーザー入力から最終的な取引判断まで、TradingAgents における全体の分析フローを段階的に示したものです。アナリスト・リサーチ・トレーダー・リスク管理の各層が連携し、一連の意思決定プロセスを構成しています。

以下ではアナリスト層における情報収集とレポート生成のプロセスを深掘り、図示しています。各アナリストは外部APIや検索ツールを活用して専門分野のレポートを作成し、次段階の議論へと接続されます。

※ 現在の実装では、外部API連携の一部に未対応の箇所が存在します。たとえば、SimFin API による財務データ取得はコード上に記載されているものの、現時点では実装が完了しておらず、事前にローカルに保存したデータを呼び出す形になります(以下のコードに参照してください)。

また、論文や設計ドキュメントにて参照されている Twitter API についても、現状では未対応となっており、代替として Reddit API および Web Search による処理が行われています。

# TradingAgents/tradingagents/dataflows/interface.py
def get_simfin_cashflow(
    ticker: Annotated[str, "ticker symbol"],
    freq: Annotated[
        str,
        "reporting frequency of the company's financial history: annual / quarterly",
    ],
    curr_date: Annotated[str, "current date you are trading at, yyyy-mm-dd"],
):
    data_path = os.path.join(
        DATA_DIR,
        "fundamental_data",
        "simfin_data_all",
        "cash_flow",
        "companies",
        "us",
        f"us-cashflow-{freq}.csv",
    )
    df = pd.read_csv(data_path, sep=";")
    ...

出力結果

AAPLを分析対象例として、出力結果が以下になります。

Based on the comprehensive debate among the risk analysts and the reasoning outlined, the most prudent recommendation for the trader is to **Sell**.

**Rationale:**

While the Risky Analyst advocates for a high-risk, high-reward approach by emphasizing Apple’s diversification into services, potential upside in AI, and possible market rebounds, this perspective relies heavily on optimistic assumptions about Apple’s capacity to turn strategic ambiguity into growth opportunities. The risk analyst acknowledges the turbulence but leans toward capitalizing on perceived future gains, which may be ill-timed given the current environment.

Conversely, the Safe Analyst underscores significant macroeconomic uncertainties, geopolitical risks (especially US-China tensions), and the vulnerabilities associated with declining iPhone sales. Their emphasis on maintaining a cautious stance is supported by the reality that geopolitical conflicts and legal challenges can rapidly escalate, causing volatility and potential downturns. The Safe Analyst’s balanced view recognizes that hope without strategic clarity (especially in AI) and dependency on hardware sales heighten downside risks.

The Neutral Analyst offers a middle ground, highlighting market indecision reflected in technical indicators, advocating for vigilance rather than immediate action. This aligns with a risk-aware stance that neither dismisses risks nor pursues aggressive gains.

**Key Arguments Supporting the Sell Recommendation:**

- **Macro Risks Outweigh Short-Term Upside:** Despite optimistic forecasts, geopolitical tensions—particularly US-China friction—pose tangible threats to revenue streams.
  
- **Fundamental Challenges:** Declining iPhone sales continue to pressure margins, and the lack of a clear AI strategy introduces strategic uncertainty that could erode investor confidence if not addressed.

- **Technical Warning Signs:** Indicators such as RSI and MACD suggest market indecision and potential downside momentum, warning against jumping in prematurely.

- **Legal and Reputational Risks:** Ongoing legal issues could trigger volatility and damage perception, making quick gains risky.

- **Potential for Downside Amplification:** Given current conditions, short-term catalysts like earnings reports or geopolitical escalations could further depress the stock.

**Comparison to the Original Plan:**

The initial plan recommended a cautious, risk-managed approach: reducing exposure, setting stop-losses, and monitoring news before considering re-entry or shorting. The debate reinforces the prudence of this stance. Instead of maintaining or increasing positions, the analysis indicates that protecting capital now via a Sell decision maximizes risk-adjusted returns, especially as downside risks seem to be prioritizing over the prospect of immediate gains.

**Conclusion:**

Considering the arguments and evidence, I recommend **Selling** Apple stock at this juncture to safeguard portfolio value amid mounting uncertainties. This approach aligns with risk management best practices, acknowledges current market signals, and prepares for further volatility.

※ 上記の内容はすべて研究および学習目的で生成されたものです。実際の投資判断には使用しないでください。

感想

実際にTradingAgentsを使ってみて感じたこととして、やはりLLMを用いた金融取引判断は本質的に「主観性」が強く残るという点が挙げられます。エージェントごとに生成される判断は、それぞれ論理性や整合性があるものの、最終的な意思決定はモデルの温度設定やプロンプト構造、APIレスポンスの非決定性に大きく左右される場面もありました。
そのため、LLMの出力をどこまで「信頼」して取引判断に活かすかは、現時点ではまだ慎重さが求められる段階だと感じます。人間の補助ツールとしては非常に可能性がありますが、完全に任せきりにするには検証や透明性の強化が必要です。
また、LLMベースのシミュレーションはAPIコールの量が非常に多く、個人投資家が頻繁にバックテストを行うにはコスト面でのハードルもあります。
ただし、TradingAgentsはLangGraphベースで高いモジュール性を持っており、エージェントの追加や外部データ接続の拡張もしやすい構造になっています。

Discussion