Skip to main content

92. AI Engine for Market Comparisons

Status: Accepted Date: 2025-07-06

Context

The core function of the Dike tournament module is to compare two markets and decide which one is "better" or has more potential. A traditional approach would be to use a purely quantitative, rule-based system (e.g., "the market with the higher RSI and lower volatility wins"). This approach is rigid, cannot capture nuance, and struggles to compare markets with conflicting indicator signals. We want a more sophisticated and qualitative comparison method.

Decision

The core of the Dike module will be an AI Comparison Engine. We will leverage a Large Language Model (LLM) to perform the pairwise comparisons between markets.

For each comparison, the process will be:

  1. Gather a rich set of data for both markets (e.g., price action, key technical indicator values, volatility metrics).
  2. Format this data into a structured prompt for the LLM. The prompt will ask the LLM to act as an expert technical analyst and decide which of the two markets presents a better trading opportunity, and why.
  3. The prompt will require the LLM to provide its answer in a structured format (e.g., JSON) that includes the winner, the loser, and a confidence score.
  4. This structured output will be parsed and used to determine the outcome of the tournament round.

This decision is a direct application of our adr://ai-first-design-philosophy.

Consequences

Positive:

  • Sophisticated Qualitative Analysis: LLMs can understand the gestalt of the data and make nuanced, qualitative judgments that are impossible with simple rule-based systems. It can weigh conflicting indicators and provide a human-like assessment.
  • Explainability: A key part of the prompt will require the LLM to explain why it chose a particular winner. This reasoning can be logged, providing valuable insight into the tournament's results.
  • Flexibility: The comparison logic can be easily tuned by simply changing the prompt, without requiring any code changes. We can experiment with different analytical perspectives (e.g., "which market is better for a short-term momentum trade?" vs. "which is better for a long-term trend-following position?").

Negative:

  • Non-Determinism & Consistency: The LLM may not give the exact same answer every time for the same inputs. Its reasoning can be inconsistent.
  • Cost and Latency: LLM calls are significantly slower and more expensive than running a local, quantitative algorithm.
  • Prompt Engineering is a New Skill: Getting reliable, well-structured output from an LLM requires careful prompt engineering, which is a different skill set from traditional programming.

Mitigation:

  • Confidence Scoring and Validation: We will require the LLM to provide a confidence score. Low-confidence comparisons can be flagged for review or re-run. We will also have special outcomes, such as allowing both markets to advance if the LLM considers them both to be very strong.
  • Asynchronous Execution: All AI comparisons will run as independent jobs in a BullMQ queue (adr://bullmq-flow-processing), so their latency does not impact any user-facing system. We can also run many comparisons in parallel to speed up the overall tournament.
  • Prompt Engineering & Versioning: We will treat our prompts as first-class artifacts. They will be version-controlled in our codebase and we will develop a systematic process for testing and refining them to improve the reliability and quality of the AI's output. We will use the Morpheus gateway to manage these prompts.