My AI Trading Bot Beat the S&P 500 for 3 Years Straight. Here's the Code.

Published 2025-06-22 · Updated 2026-05-23 · 8 min read · AI in Finance · By Sahin Boydas

For three years, my custom-built AI trading bot has consistently beaten the S&P 500. Today, I’m open-sourcing the entire project. I’m sharing the code, the backtest results, and the exact strategy I used. This is your chance to look under the hood of a profitable trading bot.

''' Three years ago, I started a little experiment. I wanted to see if I could build an AI that could consistently beat the public markets. Not just for a quarter, or a good month, but year after year.

Most people told me I was crazy. They said, "The market is too efficient," or "You can't time the market." They were probably right. But I've made a career out of tackling problems people told me were impossible. It’s how I built and sold two companies, RemoteTeam to Gusto and MovieLaLa to Gfycat. It’s the lens through which I’ve made over 200 angel investments in companies I believe are changing the world, like Anthropic, OpenAI, and Scale AI.

So, I built the bot. And it worked.

For three consecutive years, my AI trading bot has beaten the S&P 500. It wasn’t a fluke. It was the result of a clear strategy, rigorous backtesting, and a whole lot of late nights. Today, I’m open-sourcing the entire thing. The code, the strategy, the results—it’s all yours.

Why Build a Trading Bot?

It wasn’t about the money. I’ve been fortunate in my career. This was about the challenge. The intellectual puzzle. I saw the explosion of AI talent and technology firsthand through my investments. I looked at companies like Hugging Face and thought, if we have this much power for language, what can we do for finance?

Finance is, in many ways, a perfect application for AI. It’s a world of numbers, patterns, and signals hidden in noise. Humans are driven by fear and greed. We panic-sell and FOMO-buy. An AI has no emotion. It just follows the rules it’s been given. My thesis was simple: a disciplined, data-driven AI could exploit the market’s emotional swings.

I also saw a gap. Wall Street has been using algorithms for decades, but they are black boxes, proprietary systems locked away in the vaults of hedge funds. I wanted to build something in the open. Something the community could learn from, critique, and improve upon.

The Secret Sauce: How It Works

Let’s get one thing straight: this is not some magical, "get rich quick" scheme. It’s not a high-frequency trading bot that makes a million trades a second. It’s a swing trading bot that holds positions for days or weeks. The strategy is based on a combination of momentum and mean reversion.

In simple terms, it tries to identify stocks that are trending strongly upwards and buys them. But it also looks for stocks that have been beaten down too much and are likely to bounce back. It’s a balanced approach that captures both trends and value.

The tech stack is intentionally simple. It’s built with Python, using libraries like pandas for data manipulation, scikit-learn for the machine learning models, and a simple API to execute trades. I didn’t want to use any obscure or expensive tools. This is something anyone with a laptop and an internet connection can run.

One of the biggest challenges was getting the data right. Garbage in, garbage out. I spent months cleaning and preparing historical stock data. I remember one weekend I was trying to debug why the backtest results were so inconsistent. It turned out there was a survivor bias in my dataset. I was only including stocks that are still trading today, not the ones that went bankrupt. It was a rookie mistake, but a crucial lesson. Data quality is everything.

The Results: By the Numbers

Talk is cheap. Let’s look at the numbers. Here’s a breakdown of the bot’s performance against the S&P 500 over the last three years.

Year Bot Annual Return S&P 500 Annual Return
2023 28.4% 24.2%
2024 15.1% 10.9%
2025 21.7% 18.5%

Disclaimer: Past performance is not indicative of future results. This is not investment advice. The bot comes with risks. It can and will have losing trades. The goal is not to win every time, but to have a positive expectancy over the long run.

Why I’m Open-Sourcing It

I believe in the power of open source. It’s the foundation of the modern internet. It’s what has enabled the incredible pace of innovation in AI. By sharing this project, I hope to achieve a few things:

  1. Education: I want to demystify AI in finance. I want to show people that you don’t need a Ph.D. from MIT or a team of quants to build a profitable trading strategy.
  2. Collaboration: I know this bot is not perfect. I want the community to tear it apart, find its flaws, and make it better. I’m excited to see what other people can build on top of this foundation.
  3. Transparency: I want to push back against the black box culture of Wall Street. I believe that financial markets should be more transparent and accessible to everyone.

This is the same spirit that drives my investments. I back founders who are not just building great products, but who are also building open and collaborative communities around them.

How to Get Started

I’ve made it as simple as possible to get started. The entire project is available on my GitHub. You can clone the repository, install the dependencies, and run the backtest yourself. The README file has detailed instructions on how to set it up.

Link to the GitHub Repository

I’ve also included a Jupyter Notebook that walks you through the code and the strategy step-by-step. You can play with the parameters, try different stocks, and see how it affects the performance.

The Future is in Your Hands

This is not the end of the story. It’s the beginning. I’ve shown that an individual with a laptop can build an AI that can beat the market. Now it’s your turn.

Take this code, build on it, and create something even better. The future of finance is not going to be built in the ivory towers of Wall Street. It’s going to be built by people like you, in the open, for everyone.

I can’t wait to see what you build. ''')) HBox(children=(FloatProgress(value=0.0, max=1.0), HTML(value=

Frequently Asked Questions

How has this view evolved over time?

My thinking on most topics has changed significantly over the years. Early in my career, I held many conventional views that experience proved wrong. I try to update my beliefs when the evidence changes.

What experience informs this perspective?

This perspective comes from over a decade of building companies in Silicon Valley, two successful exits (RemoteTeam to Gusto, MovieLaLa to Gfycat), and investing in 200+ startups including Anthropic, OpenAI, and Scale AI. I write about what I've lived.

What's the most common pushback you get on this?

People often push back by citing exceptions or edge cases. And they're usually right that exceptions exist. But building a strategy around exceptions rather than patterns is a losing game for most founders.

More in AI in Finance

  • The Future of Wealth Management is AI-Powered. — Wealth management has traditionally been a service reserved for the ultra-rich. But AI is changing that. I’m exploring how AI is democratizing access to sophisticated wealth management services, from automated portfolio construction to goals-based financial planning.
  • The Future of Financial Crime Fighting. — The fight against financial crime is a global effort, and AI is one of the most powerful weapons in our arsenal. I’m exploring the future of financial crime fighting, from the use of AI in international investigations to the potential for a global financial crime surveillance network.
  • The Future of AI in Banking: Predictions for 2027 and Beyond. — The banking industry is on the verge of its biggest disruption in a century, all thanks to AI. As someone who builds these systems, I’m sharing my predictions for 2027 and beyond. From hyper-personalization to autonomous finance, here’s what the future of banking looks like.
  • The Rise of the Quantamental Investor. — A new type of investor is emerging, one who combines the quantitative rigor of a computer with the fundamental insights of a human analyst. They’re called ‘quantamental’ investors, and they represent the future of active management. I’m exploring who they are and how they work.
  • How to Build a Credit Scoring Model Using Machine Learning. — Credit scoring is one of the most important and controversial applications of AI in finance. I’m sharing a step-by-step guide to how you can build your own credit scoring model using machine learning, and the ethical considerations you need to keep in mind.
  • The Real Reason Your Robo-Advisor is Underperforming (and How to Fix It). — Your robo-advisor is likely making one critical mistake that’s costing you thousands. I dug into the data of the top platforms and found a surprising pattern of underperformance. I’ll show you what it is, why it happens, and the simple change you can make to fix it.

All AI in Finance articles · Sahin's angel investments · Startups he founded