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.

Implementation:HKUDS AI Trader DataLoader

From Leeroopedia


Knowledge Sources
Domains Frontend, Data_Loading, Financial_Data
Last Updated 2026-02-09 14:00 GMT

Overview

Frontend JavaScript class that loads, processes, and exposes all trading agent data and price history for the AI Trader web dashboard.

Description

The DataLoader class is the central data access layer for the AI Trader frontend. It handles loading agent position JSONL files, computing asset value histories, fetching market price data (individual JSON files for US stocks, merged JSONL for A-shares), and calculating portfolio metrics. It supports multi-market switching (US, CN, CN hourly) and integrates with CacheManager for performance optimization and ConfigLoader for market-specific paths.

Usage

Include this script after config-loader.js and cache-manager.js. A global DataLoader instance is created in asset-chart.js and exposed as window.dataLoader for use by other modules.

Code Reference

Source Location

Signature

class DataLoader {
    constructor()
    setMarket(market)                            // Switch between "us", "cn", "cn_hour"
    getMarket()                                  // Return current market identifier
    getMarketConfig()                            // Get current market config from ConfigLoader
    async initialize()                           // Load YAML config and set data paths
    async loadAgentList()                        // Discover agents with position data
    async loadAllAgentsData()                    // Load all agents, prices, and compute metrics
    async loadAgentData(agentFolder)             // Load single agent position + asset history
    async loadPriceData(symbol)                  // Fetch OHLCV price data for a symbol
    async loadBenchmarkData()                    // Load benchmark (QQQ/SSE-50) data
    calculateAssetHistory(positions, priceData)  // Compute daily portfolio value series
}

Import

<script src="assets/js/data-loader.js"></script>

I/O Contract

Inputs

Name Type Required Description
window.configLoader ConfigLoader Yes Configuration for market paths and agent lists
CacheManager class Yes Cache layer (instantiated internally)
position.jsonl files JSONL Yes Agent position log files served via HTTP
Price JSON files JSON Yes OHLCV market data files served via HTTP

Outputs

Name Type Description
allAgentsData Object Map of agent name to {positions, assetHistory, return}
benchmarkData Array Benchmark time series [{date, value}]

Usage Examples

const dataLoader = new DataLoader();

// Initialize with config
await dataLoader.initialize();

// Switch to Chinese A-share market
dataLoader.setMarket("cn");

// Load all agent data (positions + computed asset histories)
const allData = await dataLoader.loadAllAgentsData();

// Access individual agent
const geminiData = allData["gemini-2.5-flash"];
console.log("Asset history points:", geminiData.assetHistory.length);
console.log("Total return:", geminiData.return.toFixed(2) + "%");

Related Pages

Page Connections

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