← Latest papers
💬 NLP

QuantCode-Bench: A Benchmark for Evaluating the Ability of Large Language Models to Generate Executable Algorithmic Trading Strategies

This paper introduces QuantCode-Bench, a comprehensive benchmark designed to evaluate large language models' ability to generate executable algorithmic trading strategies for the Backtrader framework, revealing that current models struggle primarily with correctly operationalizing financial logic and adhering to task semantics rather than with syntactic code correctness.

Original authors: Alexey Khoroshilov, Alexey Chernysh, Orkhan Ekhtibarov, Nini Kamkia, Dmitry Zmitrovich

Published 2026-04-17
📖 5 min read🧠 Deep dive

Original authors: Alexey Khoroshilov, Alexey Chernysh, Orkhan Ekhtibarov, Nini Kamkia, Dmitry Zmitrovich

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you have a brilliant, hyper-intelligent robot chef. You can ask this chef to cook anything, and it can usually follow a recipe perfectly, chopping vegetables and seasoning meat with surgical precision.

But now, imagine you ask this chef to invent a new, secret recipe for a dish that doesn't exist yet, based only on a vague description you gave it. And here's the catch: the dish doesn't just need to look good on paper; it actually has to taste delicious when you eat it, and it has to be the exact dish you asked for, not just a random soup that happens to be edible.

This is exactly what the paper QuantCode-Bench is about, but instead of a chef, it's testing Large Language Models (AI) on their ability to write trading strategies for the stock market.

Here is the breakdown in simple terms:

1. The Problem: "It Compiles, But It Doesn't Work"

Most AI benchmarks test if a robot can write code that doesn't crash (syntax). It's like checking if the robot chef can chop an onion without cutting its finger.

  • The Old Way: If the code runs without errors, the AI gets a passing grade.
  • The Reality of Trading: In the stock market, code that runs without errors can still be useless. Imagine a robot chef who makes a perfect bowl of water. It's "edible" and "safe," but if you asked for a "spicy curry," the robot failed.
  • The Goal: The researchers wanted to see if AI can take a human's idea (e.g., "Buy when the price drops, sell when it rises") and turn it into a strategy that actually makes trades in the real world.

2. The Test: "QuantCode-Bench"

The team created a giant test kitchen called QuantCode-Bench.

  • The Ingredients: They gathered 400 different trading ideas from places like Reddit, Twitter (TradingView), and GitHub. Some were simple ("Buy low, sell high"), and some were complex ("Use a specific math formula to predict the weather and trade based on that").
  • The Framework: They forced the AI to use a specific tool called Backtrader. Think of this as a very picky, strict kitchen. If you hold a knife wrong, the kitchen locks up. The AI has to learn the specific rules of this kitchen to succeed.

3. The Four-Stage Filter (The "Taste Test")

To pass the test, the AI's code has to survive four increasingly difficult hurdles:

  1. The Grammar Check (Compilation): Does the code have typos? Can the computer read it?
    • Result: Almost all top AIs pass this. They are great at grammar.
  2. The Safety Check (Backtest): Does the code run without crashing when fed historical data?
    • Result: Most top AIs pass this too.
  3. The Action Check (Trades): Did the strategy actually buy or sell anything?
    • Result: Here is where things get messy. Many AIs write code that runs perfectly but never places a single trade. It's like a chef who prepares a meal but never serves it.
  4. The "Did You Listen?" Check (The Judge): An AI judge reads the code and compares it to your original request. Did you ask for a "spicy curry" and did the robot make a "spicy curry," or did it just make any food?
    • Result: This is the hardest part. Even the smartest AIs struggle to perfectly match the intent of the human.

4. The Results: One-Shot vs. The "Do-Over"

The researchers tested the AI in two ways:

  • The "One-Shot" Challenge: The AI gets one chance to write the code. If it fails, it fails.
    • Outcome: Even the smartest AIs only got about 70-76% of the tasks right. They could write the code, but they often misunderstood the logic of the trade.
  • The "Agentic" Challenge (The Do-Over): The AI writes code, gets a error message (e.g., "You didn't buy enough"), and gets to try again up to 10 times.
    • Outcome: This was a game-changer. With feedback, the best AIs jumped to 95-98% success.
    • The Lesson: The AI isn't "dumb"; it just needs a human (or a computer) to say, "Hey, you missed a detail," and then it can fix it.

5. Why Do They Fail?

The paper found that the AI isn't failing because it can't write Python code. It's failing because:

  • The "Ghost" Logic: The AI writes code that looks right but the conditions are so strict that the stock price never triggers a trade.
  • The "Wrong Tool" Problem: The AI uses the wrong math formula for the job.
  • The "Hallucination": The AI thinks it knows how a specific financial tool works, but it actually doesn't.

The Big Takeaway

Writing code that runs is easy for modern AI. Writing code that does what you actually meant is still very hard.

The paper concludes that for AI to be truly useful in finance (or any complex field), we can't just ask it to "write code." We need to give it a chance to fail, learn, and fix itself. If we treat AI like a junior employee who needs a manager to review their work and say, "Try again, but fix this specific part," they become incredibly powerful. But if we expect them to get it perfect on the first try, they will often disappoint us.

In short: The AI is a brilliant apprentice chef. It can chop perfectly, but it still needs a head chef to tell it, "No, I wanted it spicier," before it can cook a masterpiece.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →