You can't trust a backtest that can see the future. In 2026 everyone is wiring LLM agents into trading and decision loops and backtesting them - and almost every setup leaks future data into a 'historical' decision. A backtest with look-ahead bias looks incredible and loses money live.
What look-ahead bias actually is
At time t, your agent should only see data up to and including bar t. The moment it can peek at bar t+1 - or computes an indicator over the entire series, or normalizes using stats from the whole dataset - its decisions are cheating and the equity curve is fiction.
It is the single most common way backtests lie.
Why AI-agent frameworks make it worse
CrewAI, LangGraph, AutoGen and friends are built for conversations and tasks, not point-in-time simulation. The path of least resistance is to hand the agent the whole dataframe (or a tool that can query anything), and nothing stops it from reading tomorrow. The leak is invisible: your tests pass, your backtest rips, and live trading quietly bleeds.
The fix: make look-ahead a hard error
Instead of hoping your agent does not peek, make peeking impossible. bar-by-bar feeds your agent a frozen, point-in-time view that only exposes bars up to t. Read the future and you get an exception, not a silent bug:
LookaheadError: look-ahead blocked: requested bar 6 but only bars 0..5 are visible at t=5
bar-by-bar in 60 seconds
A framework-agnostic harness: feed any agent point-in-time bars, it returns a Decision per bar, and you get PnL / Sharpe / Sortino / max-drawdown - with look-ahead impossible by construction.
from bar_by_bar import Harness, momentum_agent, synthetic_series
result = Harness().run(synthetic_series(), momentum_agent)
print(result.metrics) # total_return, sharpe, max_drawdown, ...
pip install -e .
bar-by-bar run --agent momentum
bar-by-bar lookahead-demo # watch the guard block a cheating agent
Any agent works - wrap your LLM or strategy as a callable that takes the frozen view and returns a Decision. If it tries to look ahead, the run fails loudly instead of lying.
Why it matters
If you are putting an LLM agent anywhere near money, an honest backtest is the difference between a real edge and an expensive illusion. Make look-ahead a loud error, not a hope.
It is MIT and open source: https://github.com/Viprasol-Tech/bar-by-bar
Not financial advice - backtests are not guarantees. If it helps you ship a more honest backtest, a star means a lot. Built by Viprasol Tech.
Top comments (0)