Skip to content
Get App

I Built the Viral Claude Code Trading Strategy Properly — Watch What Happens

Algovibes rebuilds a viral 'Claude-built' Bitcoin HMM trading strategy properly, with train/test split, realistic fees, and no test-set leakage, revealing how overfitted AI trading strategies fail out

Key Takeaways

  • Strategies that look excellent in-sample can fail badly on unseen data, a classic overfitting pattern.
  • Proper validation requires locking the test set and avoiding any leakage in scaling, feature engineering, and parameter selection.
  • Realistic transaction costs and drawdown constraints are essential when evaluating trading strategies.
  • Viral AI-built trading claims should be scrutinized for out-of-sample performance and hidden optimization.
  • HMM regime detection is not inherently invalid, but market regimes may shift, limiting predictive stability.

What the video covers

  • The video responds to a viral claim that an AI model built with Claude returned 240% trading Bitcoin, which the creator previously criticized as overfitted with hidden grid optimization.
  • The creator rebuilds the strategy using a Hidden Markov Model for regime detection with 2.5x leverage, using 760 days of hourly Bitcoin data from Binance.
  • A 70/30 train/test split is applied before any processing so that no test-period information leaks into features, scaling, or parameters.
  • Features include candle range relative to price, volume change, and eight technical indicators (RSI, momentum, volatility, ADX, EMAs, MACD) converted into confirmation scores.
  • The HMM uses seven full-covariance Gaussian states, fit with 50 random restarts to avoid local optima, and states are labeled bullish, bearish, neutral, or chop by their mean returns.
  • A backtest engine applies 0.1% maker/taker fees, minimum hold periods, and cooldown periods to entries and exits.
  • A grid search over roughly 240 parameter combinations optimizes Sharpe ratio minus a drawdown penalty, using only training data.
  • On the training data the strategy shows a Sharpe ratio of about 1.63 and max drawdown of 47%, but on held-out test data performance collapses.
  • Test results show a Sharpe ratio around -2.64, a 63% drawdown, and a 22% win rate, illustrating how AI-generated trading strategies often look strong until tested out of sample.
  • The creator argues that HMM regime models aren't inherently useless, but that regimes found in one period may not persist, and that results depend heavily on careful validation.

Answers

Questions about this video

What viral claim is this video responding to?

The video responds to a viral claim that an AI model built in 10 minutes with Claude returned 240% trading Bitcoin. The creator had earlier argued those results were overfitted and driven by hidden grid optimization.

Why does the creator split the data before doing anything else?

The creator splits 70% training and 30% testing first to ensure nothing from the test period leaks into features, scaling, or parameter selection. The test set is locked from that point forward.

How did the strategy perform on the test data?

On the training data it showed a Sharpe ratio around 1.63 and a 47% max drawdown, but on the test data it collapsed to a Sharpe of about -2.64, a 63% drawdown, and a 22% win rate.

Full Transcript — Download SRT & Markdown

00:01
Speaker A
A few weeks ago, a video went viral claiming an AI model built in 10 minutes with Claude returns 240% trading Bitcoin. I made two videos about it, called the results overfitted, found grid optimization hidden, and claimed the numbers couldn't be real.
00:20
Speaker A
A few people in the comments said, "Okay, prove it. Build it yourself then." Nobody actually said that, but just act like they did so it comes across more dramatic. So I did I took the same concept hidden markoff model
00:34
Speaker A
regime detection 2.5 times leverage and spend a significant amount of time building testing and tweaking a proper version for you real train test split real transaction cost zero parameter peaking on test data I'm not going to tell you the result yet but what came
00:54
Speaker A
out is one of the most interesting and revealing things I have shown on this channel and also a pretty good illustration of why AI trading strategies often look great until they don't.
01:10
Speaker A
One quick thing before we start. Videos like this take a lot of my time. If you find this useful, the channel membership is the direct way to support it. $15 a month. You get all the code. The link is
01:22
Speaker A
below. All right. Code walk through. Nobody has the attention span for these anymore and YouTube punishes me when people drop off early. So, I'm asking you directly, please stay. I keep it as concise and precise as possible. If anything is
01:42
Speaker A
unclear, just drop me a comment below. I read all of them. Standard libraries, nothing special here. The only thing worth pointing out up front fees are 0.1% maker and taker which is just the standard Binance fee. And I put in a 50%
02:03
Speaker A
maximum drawdown limit here. This is feeding into the optimizer later. I don't want the grid search finding a parameter combination that looks great on sharp ratio but blows up 80% of the portfolio to get there.
02:18
Speaker A
Then I'm just pulling price data for Bitcoin. Nothing special here. 760 days of hourly Bitcoin directly from Binance.
02:28
Speaker A
And after loading that, so first I'm just printing out what I pulled here from which date to which date. And then directly after that, I'm doing the train test split. Super important. 70% training, 30% testing. I split here
02:47
Speaker A
before doing anything else because I want to make absolutely sure nothing from the test period leaks into the training process. Not the features, not the scala, not the parameters. The test set is locked from this point forward.
03:07
Speaker A
Then I have a train set and a test set. Perfectly fine. And we move on to the feature engineering part. This is just the exact same as in the video and in the previous videos. Nothing new here.
03:23
Speaker A
So, three features are going into the HMM returns range, so how wide the candle was relative to price, which captures intraday volatility and then volume change, whether activity is increasing or fading. These three together give the model enough signal to
03:47
Speaker A
distinguish between different market environments. At least that's the idea. And as you see this is done separately on the train and test set. No mixing.
04:02
Speaker A
Next we got the scala and hmm training. There are two important things here. First the scala is fit on training data only and then applied to test data. If you fit it on the full data set you are
04:18
Speaker A
normalizing your training inputs using future return statistics. That would also be data leakage. Then we got the HMM itself. Seven states full coariance Gaussian distributions meaning each state gets its own normal distribution describing what returns range and volume typically look like
04:44
Speaker A
when the market is in that state. For instance, a crash state will have a distribution centered around large negative returns with high variance. A corn bull state will be centered around small positive returns with low variance.
05:03
Speaker A
What's the point of doing this loop here? So we run 50 random seats because HMM generally use expectation maximization and algorithm to fit these distributions.
05:16
Speaker A
And this algorithm can get stuck in local optima depending on where it starts. So what I'm doing here is I'm just randomly trying 50 different starting points and keep the model with the highest log likelihood and that is
05:33
Speaker A
the model that best explains the training data. Once trained, I'm using the model to assign states to both data sets. The scalar transforms the test features using training statistics only.
05:50
Speaker A
transform, never refit. Now, what is this about? This is about labeling the regimes. Now, the HMM has no idea what a bull market is. It just found seven clusters of market behavior until now.
06:12
Speaker A
So, what I'm doing here is I'm averaging the return by the state. So this is taking the mean return on the training data set grouped by the state and the highest average return becomes the bull state. The lowest average
06:32
Speaker A
return becomes the bare state. The rest just gets labeled based on whether their mean return is positive, negative or close to zero. So we got bullish, bearish, neutral or chop.
06:48
Speaker A
We also define three sets here as you see bull states which is just the single best state all bull states which includes every state with a positive mean return and bear states which includes everything negative. The grid search later on will
07:09
Speaker A
test combinations of these later. Now this will also print out a regime summary output. We will take a look at that at the end when the notebook is executed or when we take a look at the output of this notebook.
07:26
Speaker A
Then we got our favorite tool in the world technical indicators. Again just eight random in quotation mark uh technical indicators computed on top of the raw price data. So we got for instance RSI 10 period momentum rolling volatility volume versus its 20 period
07:47
Speaker A
average ADX EMA 50 EMA 200 and MACD with the signal line computed on both training and test separately as you see here.
08:01
Speaker A
Each of these eight indicators and this is happening here in the count confirmations function gets turned into a binary check. RSI below 90, momentum above 1%, volatility below 0.6%.
08:18
Speaker A
Volume above its average ADX above 25 and so on and so forth. I mean you can read that for yourself.
08:25
Speaker A
We then just count how many pass and store that as a confirmation score per candle. The grid search later on will decide how many of those need to pass before we enter a trade.
08:40
Speaker A
Moving on to the most exciting part, the core engine, the back test function. This is a lot of code, so I'm not going to waste your time going through this line by line, but I'm giving you the core idea. For each candle, we check two
08:57
Speaker A
things. Should we exit if we are in a trade, and should we enter if we are not? The exit then fires when the current state is in the bare state set, and we have held the position for at
09:11
Speaker A
least the minimum hold period. The minimum hold prevents the bottle from getting whips sorted out of trades immediately after entering.
09:20
Speaker A
The entry fires when the current state is in the bull state set. Enough confirmations have passed and we have waited through the cooldown period since the last exit.
09:34
Speaker A
Transaction costs are applied on the notional value fees baked into the entry price. take a fees deducted from the exit. So let me give you an example where this is happening. So for instance you apply the makeup fee here when you
09:53
Speaker A
entry and you also will apply that when you exit for instance here. Now this will print out some statistics. We will take a look at them in a couple of seconds or maybe minutes.
10:10
Speaker A
Next, we got the grid search. Let me pull this so you can see as much of the code as possible. And what looks cryptic in the first place is actually super simple. We just trying to find the best
10:23
Speaker A
parameters, but only again on training data. So we got roughly 240 combinations of confirmation thresholds, cooldown periods, minimum hold times, and different combinations of bull and bear state sets.
10:41
Speaker A
Every combination gets scored by sharp ratio minus a drawdown penalty. If the max drawn exceeds 50% the score gets penalized because a strategy that achieves a great sharp by risking let's say 80% of the portfolio is actually good risk management and if you ask me
11:03
Speaker A
if I may add I also think that 50% draw down is actually pretty insane. So if I would do that prudently I probably would rather take 20 or 25% here. But anyhow we take 50% for now looping through all
11:21
Speaker A
those parameters and we got some output. This will be interesting later on when we check the output which will be the case in a couple of seconds. So the last part here is going to be to apply everything we
11:37
Speaker A
trained the model on and everything we fed to the model including the grid search optimization we now apply to the test data.
11:50
Speaker A
So those exact lock parameters we just calculated we are applying to 30% of the data the most recent data the testing data from the beginning. Just to make this crystal clear the model has never seen this data. The parameters were
12:10
Speaker A
never tuned on it. Whatever comes out now is the honest answer if this strategy is working or not. if it's correctly identifying states and can make profitable trades based on that. So let's see what this is printing out and
12:29
Speaker A
just imagine a drum roll now. So these are just some random plots. We will take a look at that uh in the end.
12:37
Speaker A
But let's go through the output together and see what is the actual result of this HM model with the proper train test split. So, as you see, we are downloading BTC hourly data from Binance from February 2024 to March 2026.
12:57
Speaker A
Then we got the train test split. So, we got 12.7K candles in the training data and we are testing that on this time frame. We got the best seat. This is just random information, not anything bearing anything for now. And we got the regime
13:15
Speaker A
summary including the mean hourly return on those regimes. Now we are going through the train results again and as you see we are getting quite an insane result here as we saw in the um video from the beginning and in the previous series. So
13:38
Speaker A
this is nothing new. We got an insane sharp ratio of 1.63. We got a max drawdown of 47%.
13:48
Speaker A
We got a win rate of 60%, total return 226% versus buy and hold 84% and an alpha of 142%.
13:58
Speaker A
Now let's see what the test results are. And I just leaked already the total return as I just saw. But anyhow, we got the test results here. And the this is the real the honest answer on this model. We got a total return of
14:14
Speaker A
minus60%. So you lost over half of your invested capital. In this case, you would have lost in our case 60k versus a buy and hold return of 41%.
14:27
Speaker A
You also have to take that into consideration, right? The training data was in a totally different environment than the testing data. But this is this is how markets work, right? So you never know and this was the core idea from
14:43
Speaker A
this HM model to identify in which market we are and the model clearly failed on doing that. It doesn't work.
14:53
Speaker A
That's the result here. Anyhow, we have an alpha of minus 20% or - 19% here, which says that even if you take this model and say, okay, this was a rough market. We were in a bare market, it could have
15:13
Speaker A
protected our capital better than just staying in the market. So, it could have generated some alpha even though it would have been yielding a negative return. But this isn't the case. It is worse than being invested in this bare
15:29
Speaker A
market. So like I mean you have a sharp ratio of minus 2.64 and a draw down of 63%. So this is and I mean a win rate of 22%. What should I even say? It's probably one of the worst
15:43
Speaker A
things you could have been doing over the last x month whatever the testing period was.
15:53
Speaker A
We have a trade lock here. We have a nice visualization. So obviously all these uh charts are being AI generated.
16:01
Speaker A
I don't do them anymore. I think that's one of the greatest things about AI. You can just pull any chart with just one or two prompts. you know, my opinion on the rest of AI being very low quality and
16:12
Speaker A
gas lightning and mostly BS, but it can generates very nice charts very quickly and I'm overly using that. So, you see the nice train test split here. Pretty nice to see. So, difficult market environment, but again, the model should
16:29
Speaker A
have prevented us from making so much losses. It failed. Now, this is also nice to see. We got the buy and hold here. We got the HMM strategy over the uh training periods here. So, it clearly outperformed buy
16:45
Speaker A
and hold as we saw in the previous videos. But then you see the testing period also. Nice to see it.
16:54
Speaker A
It was falling with the market but was even worse performing than the market as you also see in this chart here. So overall, as expected, this strategy doesn't work. That is not a big surprise.
17:11
Speaker A
Does it mean HMM models don't work? By no means. And I'm very happy to play around with that further. I'm happy to do some experiments. I think just from an ad hoc reasoning I don't think that the factors we take into consideration to
17:32
Speaker A
determine the states are properly defined. So for instance for me it isn't reasonable to use the volume change.
17:41
Speaker A
What what does that tell me in this case? So I I kind of disagreed on the uh input parameters and yeah I mean I am happy to play around with that but I need the uh incentive to do that. So if you are
17:58
Speaker A
interested in that become a member get access to this code play around with it for yourself and I thank you very much for watching and looking forward to see you in the upcoming videos. Cheers. Bye bye.
Topics:Bitcoin tradingHidden Markov Modeloverfittingbacktestingtrain test splitalgorithmic tradingClaude AIquantitative financegrid searchdata leakage

Get More with the SozAI App

Transcribe recordings, audio files, and YouTube videos — with AI summaries and speaker detection. 30 minutes free.

Or transcribe another YouTube video here →