Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:HKUDS AI Trader Trading Outcome Recording

From Leeroopedia


Knowledge Sources
Domains Trading_Systems, Data_Persistence
Last Updated 2026-02-09 14:00 GMT

Overview

A data persistence pattern that records the outcome of each trading day, including explicit "no trade" entries for days where the agent chose not to act.

Description

Trading Outcome Recording ensures every trading day has a corresponding entry in the position log, regardless of whether a trade occurred. During the agent's reasoning loop, the MCP trade tools set an IF_TRADE flag when a buy or sell is executed. After the loop completes, this flag is checked:

  1. If IF_TRADE is True, the trade was already recorded by the MCP tools, so the flag is simply reset
  2. If IF_TRADE is False, an explicit "no trade" record is appended to position.jsonl with the current positions carried forward

This guarantees a continuous position history with no gaps, which is essential for accurate portfolio valuation and metrics calculation.

Usage

Use this principle at the end of each trading day's reasoning loop to ensure position continuity. Every simulation day must have at least one entry in position.jsonl.

Theoretical Basis

# Pseudocode for trading outcome recording
def record_outcome(date, agent_id):
    traded = get_config("IF_TRADE")

    if traded:
        # Trade already recorded by MCP tools
        set_config("IF_TRADE", False)
    else:
        # No trade occurred - explicitly record
        current_positions = get_latest_position(date, agent_id)
        append_to_log({
            "date": date,
            "action": "no_trade",
            "positions": current_positions
        })
        set_config("IF_TRADE", False)

Key properties:

  • Position continuity: Every day has a position entry (trade or no-trade)
  • Flag-based detection: Uses runtime config flag set by MCP tools
  • Idempotent reset: IF_TRADE is always reset to False after checking
  • Carry-forward: No-trade days inherit the previous day's positions

Related Pages

Uses Heuristic

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment