LLM Integration (AlphaGPT)

AlphaGen supports a "System 2" thinking approach where an LLM (Large Language Model) generates hypotheses (alphas), and the AlphaGen evaluator verifies them.

The Workflow

Implemented in scripts/llm_only.py and alphagen_llm/prompts/interaction.py.

  1. System Prompt: The LLM is given a strict grammar definition (see alphagen_llm/prompts/system_prompt.py). It is instructed to act as a quant researcher.
  2. Zero-shot / Few-shot Generation: The LLM generates a list of potential alphas.
  3. Validation:
    • AlphaGen parses the strings. Invalid formulas are discarded.
    • Valid formulas are backtested.
  4. Feedback Loop (Refinement):
    • AlphaGen constructs a prompt containing the performance of the generated alphas.
    • "Alpha X had IC 0.05 (Good), Alpha Y had IC 0.00 (Bad). Try to generate variations of X and avoid patterns in Y."
    • The LLM generates a new batch based on this feedback.

Iterative Improvement

This process is cyclical. The DefaultInteraction class manages the session history. It uses a LinearAlphaPool to track the best alphas found across all LLM interactions, ensuring that the LLM is constantly pushed to find signals that complement the existing portfolio, not just repeat known signals.