<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: deepak deepak</title>
    <description>The latest articles on DEV Community by deepak deepak (@deepak_deepak_0910c659393).</description>
    <link>https://dev.to/deepak_deepak_0910c659393</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3972483%2F248c2516-9fd3-4494-b14a-81507c7be3d2.png</url>
      <title>DEV Community: deepak deepak</title>
      <link>https://dev.to/deepak_deepak_0910c659393</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/deepak_deepak_0910c659393"/>
    <language>en</language>
    <item>
      <title>Look-ahead bias is quietly breaking your AI agent backtests</title>
      <dc:creator>deepak deepak</dc:creator>
      <pubDate>Sun, 07 Jun 2026 16:01:45 +0000</pubDate>
      <link>https://dev.to/deepak_deepak_0910c659393/look-ahead-bias-is-quietly-breaking-your-ai-agent-backtests-3ani</link>
      <guid>https://dev.to/deepak_deepak_0910c659393/look-ahead-bias-is-quietly-breaking-your-ai-agent-backtests-3ani</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  What look-ahead bias actually is
&lt;/h2&gt;

&lt;p&gt;At time &lt;code&gt;t&lt;/code&gt;, your agent should only see data up to and including bar &lt;code&gt;t&lt;/code&gt;. The moment it can peek at bar &lt;code&gt;t+1&lt;/code&gt; - or computes an indicator over the &lt;em&gt;entire&lt;/em&gt; series, or normalizes using stats from the whole dataset - its decisions are cheating and the equity curve is fiction.&lt;/p&gt;

&lt;p&gt;It is the single most common way backtests lie.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why AI-agent frameworks make it worse
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: make look-ahead a hard error
&lt;/h2&gt;

&lt;p&gt;Instead of &lt;em&gt;hoping&lt;/em&gt; your agent does not peek, make peeking impossible. &lt;strong&gt;bar-by-bar&lt;/strong&gt; feeds your agent a frozen, point-in-time view that only exposes bars up to &lt;code&gt;t&lt;/code&gt;. Read the future and you get an exception, not a silent bug:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LookaheadError: look-ahead blocked: requested bar 6 but only bars 0..5 are visible at t=5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  bar-by-bar in 60 seconds
&lt;/h2&gt;

&lt;p&gt;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 &lt;em&gt;by construction&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;bar_by_bar&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Harness&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;momentum_agent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;synthetic_series&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Harness&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;synthetic_series&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;momentum_agent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# total_return, sharpe, max_drawdown, ...
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nb"&gt;.&lt;/span&gt;
bar-by-bar run &lt;span class="nt"&gt;--agent&lt;/span&gt; momentum
bar-by-bar lookahead-demo     &lt;span class="c"&gt;# watch the guard block a cheating agent&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it matters
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;It is MIT and open source: &lt;a href="https://github.com/Viprasol-Tech/bar-by-bar" rel="noopener noreferrer"&gt;https://github.com/Viprasol-Tech/bar-by-bar&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Not financial advice - backtests are not guarantees.&lt;/em&gt; If it helps you ship a more honest backtest, a star means a lot. Built by &lt;a href="https://viprasol.com" rel="noopener noreferrer"&gt;Viprasol Tech&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>ai</category>
      <category>machinelearning</category>
      <category>trading</category>
    </item>
    <item>
      <title>The math of finding edge in prediction markets (and the open-source tools I built)</title>
      <dc:creator>deepak deepak</dc:creator>
      <pubDate>Sun, 07 Jun 2026 14:42:54 +0000</pubDate>
      <link>https://dev.to/deepak_deepak_0910c659393/the-math-of-finding-edge-in-prediction-markets-and-the-open-source-tools-i-built-3775</link>
      <guid>https://dev.to/deepak_deepak_0910c659393/the-math-of-finding-edge-in-prediction-markets-and-the-open-source-tools-i-built-3775</guid>
      <description>&lt;p&gt;Prediction markets (Kalshi, Polymarket) went mainstream in 2026. What most people miss is that the &lt;em&gt;edge&lt;/em&gt; is real and measurable — but it's scattered, and the fees quietly kill the naive version of it.&lt;/p&gt;

&lt;p&gt;I build trading systems, and I kept running into the same three problems. So I open-sourced two tools to solve them. This post is the math behind them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem 1: "Free money" that isn't (fee-adjusted arbitrage)
&lt;/h2&gt;

&lt;p&gt;A binary market has a YES and a NO contract. If they pay $1 on resolution, then in an efficient market:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;YES_price + NO_price = $1.00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sometimes they don't. If you can buy YES at $0.48 and NO at $0.49, that's $0.97 for a guaranteed $1.00 payout — a locked-in $0.03. Free money!&lt;/p&gt;

&lt;p&gt;Except… fees. Kalshi's trading fee is roughly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;fee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.07&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;contracts&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;   &lt;span class="c1"&gt;# in cents
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the numbers and a 3-cent gross "arbitrage" can become a &lt;em&gt;loss&lt;/em&gt; after both legs' fees. The naive scanners that just check &lt;code&gt;YES + NO &amp;lt; 1&lt;/code&gt; will happily hand you negative-EV trades.&lt;/p&gt;

&lt;p&gt;The fix is to compute everything &lt;strong&gt;fee-adjusted&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;edgehunt.arbitrage&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;single_market_arbitrage&lt;/span&gt;
&lt;span class="n"&gt;op&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;single_market_arbitrage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;market&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fee_model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;KalshiFeeModel&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fee_adjusted_profit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Problem 2: the same event, two prices (cross-venue arbitrage)
&lt;/h2&gt;

&lt;p&gt;The same event can trade at 47c YES on Kalshi and imply 51c on Polymarket. Buy YES on the cheaper venue, NO on the dearer one, and — fee-adjusted — you can lock a spread regardless of outcome. Doing this by hand across venues in real time is impossible; it's a scan-and-rank problem:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;edgehunt.scanner&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Scanner&lt;/span&gt;
&lt;span class="n"&gt;board&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Scanner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;feeds&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;kalshi&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;polymarket&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;&lt;span class="nf"&gt;scan&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Problem 3: you have an edge - how much do you bet? (EV + Kelly)
&lt;/h2&gt;

&lt;p&gt;Your model says an outcome is 60% likely but the market prices it at 47c. &lt;strong&gt;Expected value&lt;/strong&gt; (fee-adjusted) tells you &lt;em&gt;if&lt;/em&gt; to bet; the &lt;strong&gt;Kelly criterion&lt;/strong&gt; tells you &lt;em&gt;how much&lt;/em&gt; so you grow long-run without going bust:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;edgehunt.ev&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;expected_value&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;edgehunt.kelly&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;kelly_fraction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stake&lt;/span&gt;

&lt;span class="n"&gt;ev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;expected_value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.47&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;edge_prob&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;f&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;kelly_fraction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.47&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;edge_prob&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;stake&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bankroll&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# half-Kelly is safer
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Half-Kelly is usually the sane default — full Kelly is mathematically optimal but brutally volatile.&lt;/p&gt;

&lt;h2&gt;
  
  
  Putting it together: edgehunt scan
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/Viprasol-Tech/edgehunt" rel="noopener noreferrer"&gt;&lt;strong&gt;edgehunt&lt;/strong&gt;&lt;/a&gt; ties all of this into one command — a live terminal dashboard that ranks every opportunity, fee-adjusted, with Kelly sizing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;              edgehunt :: ranked opportunities  (bankroll $1,000)
 # | Venue             | Market                       | Type          | Edge/EV   | Fee-adj profit | Kelly stake
 1 | kalshi/polymarket | incumbent wins popular vote? | ARB (x-venue) | $0.131/pr |        +15.1%  |       $500
 2 | kalshi            | BTC above $100k on Dec 31?   | ARB (1-mkt)   | $0.030/pr |         +3.1%  |       $500
 3 | kalshi            | Fed cuts rates in March?     | MISPRICE      |  +22.0pts |        +60.6%  |       $164
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It runs &lt;strong&gt;offline in 60 seconds&lt;/strong&gt; with a built-in fake feed (no API keys); wire a real Kalshi/Polymarket feed with a tiny adapter. Pure Python, MIT, 85 tests.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/Viprasol-Tech/edgehunt
&lt;span class="nb"&gt;cd &lt;/span&gt;edgehunt &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nb"&gt;.&lt;/span&gt;
edgehunt scan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Bonus: give your AI agent the same edge (marketsmith)
&lt;/h2&gt;

&lt;p&gt;The obvious next step in 2026 was to expose this to AI agents over the &lt;strong&gt;Model Context Protocol&lt;/strong&gt;. &lt;a href="https://github.com/Viprasol-Tech/marketsmith" rel="noopener noreferrer"&gt;&lt;strong&gt;marketsmith&lt;/strong&gt;&lt;/a&gt; is an MCP server with tools like &lt;code&gt;search_markets&lt;/code&gt;, &lt;code&gt;get_odds&lt;/code&gt;, &lt;code&gt;find_arbitrage&lt;/code&gt;, &lt;code&gt;compute_ev&lt;/code&gt;, and &lt;code&gt;suggest_kelly&lt;/code&gt; — so you can ask Claude or Cursor to find a fee-adjusted arb and it actually can.&lt;/p&gt;

&lt;h2&gt;
  
  
  A note on honesty
&lt;/h2&gt;

&lt;p&gt;These are &lt;strong&gt;analytics tools, not execution bots&lt;/strong&gt;, and nothing here is financial advice. Backtests and scans are not guarantees — fees, slippage, and resolution risk are real. Start read-only and understand every number before risking capital.&lt;/p&gt;

&lt;p&gt;Both are MIT and open source:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;edgehunt: &lt;a href="https://github.com/Viprasol-Tech/edgehunt" rel="noopener noreferrer"&gt;https://github.com/Viprasol-Tech/edgehunt&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;marketsmith: &lt;a href="https://github.com/Viprasol-Tech/marketsmith" rel="noopener noreferrer"&gt;https://github.com/Viprasol-Tech/marketsmith&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the math or the tools help you find an edge, a star genuinely helps me prioritize what to build next. Built by &lt;a href="https://viprasol.com" rel="noopener noreferrer"&gt;Viprasol Tech&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>opensource</category>
      <category>trading</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
