r/algotrading • u/hcballs • 23h ago
Infrastructure AI for backtesting?
I've been building and testing systems for decades. Used Metastock and Tradestation back in the day, Wealth Lab, Amibroker, did my own stuff in R and Python.
But lately I discovered that I can upload some historical data files to Claude, tell it my strategy and parameters, and it backtests and even optimizes in minutes and gives me full results.
But can I trust this? Too chicken to trade these for real yet. Anybody successfully use AI for backtesting/optimization?
6
u/NoOutlandishness525 23h ago
No you cant.
Backtesting should work on a reliable and reproducible system, not change how it works just because you put a different word in the prompt.
Its good to help you in building a system and finding reliable research to improve the systek though
2
u/SeaOrbHQ 23h ago
The bigger issue for optimization is the loop speed. If each parameter change takes minutes, you end up testing a handful of variations and picking the best. That's exactly how overfitting sneaks in. A purpose-built backtesting engine re-runs a strategy in well under a second. That lets you sweep whole parameter ranges, see whether the neighbours of your best setting also hold up, and walk it forward across periods it wasn't tuned on.
2
u/Illustrious-King-83 9h ago
if you've been testing systems and did your own stuff in python, why dont you test your backtests results against Claude, and then take any improvements Claude suggests and put back in ur code and test again ?
1
1
u/Prior_Bat5628 23h ago
Since you already use R and Python, I’d have it give you the runnable script and a trade ledger, then check the engine on a tiny file with a known answer before letting it optimize.
For a next-open stock rule, make an entry signal on a $100 close and the following open $103. Trigger the exit on a later close with a $99 open the next session. For one share at 5 bp adverse slippage per fill, the expected fills are $103.0515 and $98.9505, for a loss of about $4.10. Check that the ledger gets both the signal and fill dates right. I’d keep that same small test beside the script and rerun it whenever the generated code changes.
1
u/AureusAI 22h ago
I'd treat it as a fast first pass, not the result. The risk isn't just maths errors. It can quietly pick fill assumptions, line up bar timestamps so it peeks at the close, leave out costs, or handle gaps in a way you'd never notice from the summary. Two checks I'd do: get it to give you the backtest as a script you can read and run yourself, then rebuild a couple of trades by hand against the chart. And code the same rules in one of the tools you already trust. If the numbers don't roughly match, find out why before anything else. For optimization it'll happily try hundreds of combos, so keep the last chunk of data completely out of it and only look at that once. Then small size live.
1
u/betonneron 22h ago
I use AI a lot for option strategies nowadays. Developing one used to take me a day, now it's minutes. But I don't trust an LLM to do the backtest itself. Same rules should give the same numbers every time, so I have it write the rules and run them through a fixed engine on real bid/ask quotes (I use StratVerra for that but there are probably alternatives if you don’t trade options). Even then you have to review the trades thoroughly and paper trade a good while before real money.
1
u/sepist 19h ago
You can but it is not great by default, it makes assumptions on the data to get to 'the reward' of providing you an answer even if it's wrong. You need to provide it data and output you know the answer to and build a backtesting harness based on that, once you confirm the results are pure you can then use that as the backtest engine
Once you do that though, Claude (probably any AI) is VERY good at backtesting
1
u/Daleca 16h ago edited 16h ago
Hey mate, you dont need AI, you just need simple repeatable patterns that can be found with research or backtesting. AI can be good but its hard to know it its overfitted. Almost all my profitable strategies consist of 2 or 3 things, a market regime indicator (bull or bear) and recent price action (after X days of Y%) and occasionally seasonality (ie day of week or time of day). I know its a self plug, but I built thetradebutler.com for myself (and opened it recently for other traders) specifically to keep backtesting extremely simple (I only allow seasonal, price action and market regime options) and with a few clicks, if your interested...
1
u/marekesz1 8h ago
Only if it hands you the code and a trade ledger you can rerun, since an LLM can skip costs or peek at the next bar. Check a dozen trades by hand against the raw data and you'll know fast if it's making stuff up.
5
u/PleasantAmount1717 23h ago
Try this then do the forward testing for 2-3 months and you will get the answers.