I'm building an options trading tool with Claude Code. Everything runs in a sandbox account. This week the agent added five new option structures, and the full test suite passed: thousands of checks, all green.
Then I ran the new structures in the sandbox's practice mode, and it found three problems the tests never saw. One of them is a bug class I think every rule-heavy system has, AI-built or not.
The bug: two rules that can never both pass
For one structure, a debit spread, two rules applied at once:
- Net delta at least 0.30. This one comes from my own written trading guide.
- A width limit, about 5 points wide at today's prices. This one was borrowed from a different strategy a few days earlier, as a provisional number.
A 5-wide spread has a net delta of around 0.03. The guide asks for ten times that. No placement can satisfy both, ever.
Every rule had its own unit tests, and every test passed. Each test checked one rule at a time, so none of them could see that the two rules together block everything.
The fix: a feasibility test on real data
The idea came from my reviewer, a second AI session that checks the first one: don't only test the rules one by one, prove that a real case gets through all of them.
So the new test takes a recorded real option chain and tries every placement the structure allows. It asks one question: does at least one placement pass every rule that can block an order?
def feasible(template, chain): for placement in all_placements(template, chain): # every expiry and strike the legs allow blocking = [r for r in template.rules if r.blocks_orders and not r.passes(placement, chain)] if not blocking: return placement # at least one real trade gets through return None # the rule set can never pass: the test fails Two choices made it useful:
- Only count rules that depend on the placement. Market-state rules (like "implied volatility rank under 30") can fail for every placement on a given day, and that says nothing about the rule set. Rules that don't have a number yet are skipped too.
- Use recorded real chains, not synthetic ones. I recorded SPY, QQQ and IWM at Friday's close from a public delayed-quote file. Synthetic quotes would only tell me what I already assumed.
The numbers
With the old rules, the debit spread had 34,622 possible placements across the three chains. Zero passed.
My guide's rule wins, so the width limit now just shows on screen and no longer blocks. 97 placements pass. The old template turns the new test red on both sides of the trade, and the new one turns it green.
Even the cheapest of those 97 on SPY costs more than the size limit I set for a single trade. On Friday's prices, only the IWM one fits under it. That's a sizing decision I can live with. What the new test catches is a rule set nobody can ever meet, and that one is a bug.
The other two finds, briefly
- The at-the-money check blocked legs the tool had just placed. The price moved across the halfway mark between two strikes in the seconds between placing and checking. Now either of the two listed strikes around the price counts.
- The fee rule measured a debit trade against what it can lose. For a credit trade the price is what you can make; for a debit trade it's the opposite. Debit trades are now measured against their max profit.
Steal this
If your system has a stack of rules, add one test that takes a real case and proves at least one input gets through all of them at once. It's cheap, and it catches the contradictions your per-rule tests are built to miss.
Follow the loop
Each round of this build goes up on my YouTube channel first, with the live demo and the numbers:
Subscribe to Dr_Delta on YouTube
Have you ever had two rules in your own system that could never both be true? How did you find out? Tell me in the comments.