How to backtest hundreds of strategies in 15 seconds or less using AI Agents
A shortcut for finding the best trading strategies
Imagine you had an idea for a trading strategy.
It can be dumb simple, like buying SPY when its below its 200-day simple moving average, and selling it when its above.
It can be complex, like rebalancing the top 50 stocks by market cap weighted by their 14-day RSI divided by their 30 day price standard deviation.
For any type of strategy, no matter the complexity, imagine someone asked you the following question.
“How do you know that these parameters are the best?”
Sure, you can manually backtest different variations of the strategy, coding up each one in Python and keeping a table of the most promising. If you’re efficient, you might even run a Grid Search, and find the best parameters after a few weeks.
(When the market regime has already changed)
Or you can use AI, and find the best parameters using plain English, a no-code backtesting tool, and the power of genetic optimization.
Best of all, it’s free to try. Here’s how it works.
A Biologically-Inspired AI Algorithm?
Instead of manually coding up a dozen strategies in Python and comparing them on metrics like sharpe ratio, maximum drawdown, and percent change, we can use a genetic algorithm.
A genetic algorithm (GA) is a biologically-inspired AI algorithm that’s very much unlike ChatGPT and other Large Language Models. Modern AI models are trained using a combination of deep learning and reinforcement learning. They use neural networks, terabytes of data, and the transformer architecture to find the relationship between words and optimize towards sentences that make the most sense.
Mathematically-speaking.
Genetic algorithms couldn’t be further from this. These algorithms use a combination of operations inspired by their real-world equivalent: selection, crossover, mutation, evaluation, and replacement operators, and use these operators to iteratively improve a population of solutions over time. Read more about it here.
In this case, we’re using genetic algorithms to help us develop trading strategies. If you’re a technical nerd (like me), we’re using NSGA-II. It stands for non-dominated sorting genetic algorithm, and it helps us find a population of solutions with their own unique strengths and weaknesses.
For example, in trading, you might find one conservative strategy with a crazy high risk-adjusted return (also called sharpe ratio) but a very low total raw gain. And then, you might find another with a crazy high total return but a steep and stomach-churning drawdown (or the maximum fall from the top of the graph to the bottom).
But don’t let this theory confuse you. Let me show you an example of an optimized portfolio.
A previously-successful optimized portfolio
Earlier this year, I created a simple rebalancing strategy using UPRO and GLD. I then used the optimizer to improve it.
The original strategy was simple (and described in detail in this article): every year, rebalance your portfolio to 50% UPRO and 50% GLD. I tested it out and saw it was a fairly successful trading strategy!
So I then decided to optimize it.
The end result is this outstanding portfolio.
Press enter or click to view image in full size An optimized UPRO-GLD strategySince its deployment on May 12th, this portfolio’s returns have skyrocketed. It’s up 35%, has a sharpe ratio of 3.26, and a sortino ratio of 4.55. It also has a maximum drawdown of 4%, indicating that the most steep fall from the top of the graph was only 4%.
This is incredible.
Thus, I’ve proven that the optimization process CAN work. Here’s how to apply it for your own strategy, step-by-step.
Want to see the exact rules for the optimized strategy? Subscribe to this portfolio on NexusTrade!
How AI Agents Help Create Market-Beating Strategies
Press enter or click to view image in full size Using an AI agent to autonomously create trading strategiesTo create an optimized trading strategy, we’re going to use NexusTrade’s AI agent.
NexusTrade’s Agent is unlike any chatbot. Using Aurora, we can send a single request and generate a dozen different unique trading strategies simultaneously.
In this example, I said the following:
Create the best strategy to rebalance the top tech stocks
After a simple request, the AI’s goal is to ask follow-up questions, such as:
- What is your primary performance objective?
- What is your tolerance for risk?
- How do you define “top tech stocks”?
I answered these questions, and Aurora starts running. Specifically, she runs in a loop of the following processes:
- Financial Research: Searching the web or running queries to find information
- Strategy Generation: Using the research findings to create different trading strategies
- Testing: Simulating how those strategies performed in the past
- Optimization: Using the genetic algorithm to improve the strategy’s parameters
- Iteration: Repeating this process to find the best trading strategy
Press enter or click to view image in full size The AI creates different competing the ideas and figures out which are promisingAs the user, you can choose between semi-automated or fully-automated mode. In this way, it’s JUST like Cursor and Claude code, just for algorithmic trading! You can direct Aurora to investigate specific trading ideas.
When Aurora finds a promising strategy, she’ll automatically optimize it. Let me describe this part in more detail.
Using Genetic Algorithms to Create the Best Possible Strategy
Press enter or click to view image in full size Aurora, the AI Agent, will automatically launch an optimization on promising portfoliosWhen Aurora finds a promising strategy based on your risk profile across several historical periods, she’ll automatically launch an optimization.
The optimization has several inputs including a population size, objective functions, and start and end-date. It’ll also automatically split the data into a training set and validation set, to test the robustness of the strategy out of sample. The training set is also split further into different windows in the past.
Press enter or click to view image in full size You can see the optimization happen in real-timeWhen running an optimization:
- We generate a backtest per window in the training set (default: 3)
- We generate this many backtests per individual in the population (default: 20)
- We pick the best individuals in the population and keep them for the next generation. This causes our population to continue to improve
- We repeat for the number of generations (default: 20).
By default, we generate over 1200 backtests that complete in about 15 seconds (depending on the complexity of our strategy). This lives up to the promise of the title of the article: “How to backtest hundreds of strategies in 15 seconds or less using AI Agents”.
Following the optimization, Aurora reads and interprets the results. It sees how well it does during training and how well it does in the validation set.
However, just because we optimize a portfolio doesn’t mean we’ll automatically find the world’s best trading strategy. There are some caveats.
The Optimization Process Doesn’t Always Work
The optimization process, while powerful, doesn’t always work. Let’s talk about why.
When optimizing a trading strategy, sometimes, the strategy’s performance degrades in the validation set.
Press enter or click to view image in full size The AI can automatically detect if an optimization resulted in overfittingThe AI is equipped to automatically detect performance degradation, but even this isn’t perfect. Even if a strategy looks perfect, it may fail next year for a variety of reasons. Maybe the strategy primarily trades Apple, and Tim Cook gets convicted of fraud. The AI can’t predict the future; it can only perform analysis based on what’s happened in the past.
In this case, while the optimization failed on some runs, it succeeded flawlessly on others. Here is the final result.
Our Final Result: A Powerful Optimized Tech Trading Portfolio
Press enter or click to view image in full size Our final optimized portfolio earned 43% since 03/12/2025 (compared to SPY’s 16%)The end result of this process is a highly profitable trading strategy that significantly outperformed the broader market.
Within the past 6 months:
- It achieved a percent return of 43% vs SPY’s 16%
- It had a sharpe ratio of 1.54 vs SPY’s 0.92
- It had a sortino ratio of 1.73 vs SPY’s 1.32
- It’s maximum drawdown was only slightly higher at 19% vs SPY’s 15%.
The Next Step: Paper-Trading
As I mentioned before, even if the optimization process works, it may not hold up in the real-world. The next step is to paper-trade the strategy to see how it performs in the real-world.
You can subscribe to the final optimized portfolio and see the real-time trading results here. Six months from now, we can all see if this optimized portfolio stands the test of time.
But you don’t have to subscribe to the portfolio to wield the power of AI.
You can instead use Aurora right now to create your own trading strategy based on your own preferences and risk tolerance! A powerful AI agent for algorithmic trading is within your grasp.
Will you take it?