📱

Get Our Mobile App

Take your business learning on the go!

Download on the App StoreGet it on Google Play

I Re-Created A Quant Trading Strategy With Claude Code (Nobel Prize Method)

Miles Deutscher Finance22:16

Transcription

There's one calculation that every single quant desk on earth runs every single morning, and it's not which way the market's going. Most traders don't even know the real question that it answers. At the center of it sits an equation that won a Nobel Prize in economics. And in this video, I'm going to rebuild the way a quant actually thinks from the ground up.

Here's exactly what you're going to walk away with. The full method explained properly so you don't need any sort of math or technical background. A cloud code skill which runs it for you on any asset that you trade. By the end of this video, you'll have it fully installed on your computer so you can have quant-like intelligence at your fingertips. And a custom TradingView indicator that puts the entire framework in a quantifiable data set on your chart. And here's the part that a lot of videos like this don't include. We're actually going to go backtest the data for 15 years and look at how this strategy actually performs with real market data. Oh, and all of this is for free. I'm going to show you how to install it at the end using the link in the description below. You can claim all the assets and prompts from today's video.

So, let me give you some quick context as to why I'm covering this. I've been deep in the markets for the last 7 years, and I noticed a few years ago that there was a massive shift happening with AI. I was actually one of the first people to put out AI trading bot videos on YouTube. And since then, we've had an absolute explosion with the intelligence of these models, which in my opinion make them absolutely essential if you're a trader. So, the fact we have this information at our fingertips, the fact that you can now compress strategies into a single skill, into a single file that you can use over and over again, opens up a plethora of opportunities. So, in today's video, I wanted to take a concept that real quant traders use and condense it down into something that you can tangibly interact with. And that's the power of AI. You now have the power of strategies and indicators and data that quant firms used to have access to. And as a retail trader, you can now have access to the exact same stuff. So, I personally believe there's a massive edge for anyone who augments their trading with AI.

But in order for you to understand what we're actually building here, let's talk about the theory behind today's video. I've basically reduced a quant's thinking down to eight ideas, and I'll walk you through in order how a quant would reason with a real trade, with each idea building on the last. I actually got inspiration for this concept from Louis Jackson, who did a great video on the Markov method. And that method, if you've seen it, basically models which direction the market is moving in. And it's a reasonable way to think about regimes. But today, I'm going to present the other half of the picture, the calculation that actually determines the stakes behind real positioning, aka how much money actually goes on the table per trade. And on a real quant desk, that decision is treated with just as much rigor as the overall direction of the market, because ultimately that's what determines profitability and survival of a trader.

So, before we get into anything else, let's actually define what the word quant really means, because it gets thrown around constantly, but I rarely see it explained. A quant stands for quantitative analyst. These people often study advanced mathematics, physics, or computer science, and funds will recruit top talent often on some of the highest salaries in finance. Their job is essentially to replace opinion with a real measurement. So, discretionary traders, they'll build a view on the market. Quants will build a model to represent that view. They'll test it on history, they'll model it on different variables, and they come up with a real, tangible system based on real constraints. They don't usually work as lone geniuses, although there are a few. They usually split up into different departments which handle different segments of the market. One team will typically research signals, one on risk and sizing, because every single element that comprises a trade requires a different skill set and different parameters. Now, of course, I'm generalizing here, because every single fund operates differently, but at a large scale, this is typically how you see them operate.

Now, if you're a trader, here's the fundamental difference between how you might see a chart and how a professional quant trader might see a chart. Most traders just see price, so they'll look at where it's been, they'll look at where it's going, and essentially the entire read on the market is directional. A quant will often analyze violence or volatility first. They'll look at how hard the market is moving independent of direction. So, a retail trader might think, "This feels dangerous." A quant would essentially hear an incomplete sentence. They'd be thinking, "Well, dangerous is a measurable quantity. So, what's the number?" So, instead of every morning looking at a price target like a retail trader, quants will look at volatility, value at risk, position sizing, Greeks, exposure, expected moves, and they'll apply stress test to market movement and essentially try and combine all of that into a single score. In today's video, I'm going to refer to that as the violence score, but I'm aware that it's a lot more nuanced than that in practice. And underneath that system is essentially a single mental model. And it's the most valuable idea that I want to present to you in this entire video.

For every trade that you ever take, you'll essentially just ask two questions. Which way, so in which direction do I think price will move, and how much? So, how much am I willing to stake on this position? And the second question from the start of the video is something traders often get wrong, even though it's the most important in terms of profitability and survival in the market. And that's how you can have traders with a really high win rate, but they're actually not profitable. And how you can have traders with a lower win rate, but they are profitable over time because they understand when to size and how to size. Retail treats which way will price move as essentially the entire game. Position size is usually an afterthought. Whereas a quant will rank those two questions by how answerable they are. Which way is barely answerable. It's actually the weakest signal in trading. Whereas how much you actually stake is fully controllable. It's the one variable in trading that's actually at your command. So, often a quant will invert energy allocation, meaning they'll put minimum effort on a question that can't be answered reliably, and then they'll put maximum rigor on the variable that can be controlled completely. So, the industry, the entire trading industry, sells you one question, and it's a sexy sell. Price is going to move up, price is going to move down, but the reliable funds over time have actually compounded their wealth answering the boring question and compiling it into a framework that they can use. And today, the really powerful thing I'm going to teach you is how to put a framework into a quant skill, and I'm going to give it to you today at the end of the video that you can repeatedly use. This, in my opinion, is the future of trading.

So, let's go back to what I was discussing before, the violence score. Because in order to develop a quant-like model, we need to discuss why violence can actually be predictable. It has a property that market direction doesn't have, and you can see it clearly on the chart. Market chaos typically doesn't arrive in isolation, but instead in a series of clusters. So, for example, we can look at March 2020 in the S&P, which was absolute carnage, and then we can compare that to the FTX collapse on a different asset in Bitcoin in 2022, and it paints a similar picture, but on a completely different asset. A quant doesn't settle for just eyeballing that pattern. They want to define an exact number. So, for example, I'll walk you through the thought process. On a typical day, there's roughly a 10% chance of a violent move. On a top decile day, I actually ran this based on 15 years of back-tested Bitcoin data, on a day after a violent move, that probability triples to 30%. That's the predictability I'm talking about. It's not 100%, but it's more predictable, and it's a number you can actually trade off. Then I went and checked the monthly data on the S&P 500. And if you go back to 1871, violent moves are twice as likely to follow violent months. So, that's 150 years of a completely different asset class, but it follows a similar law. So, violence isn't the one metric a quant would look at, but it is a metric which can be quantified, assigned a probability, and thus developing a framework which you can trade off. What I just referenced is something called volatility clustering. It's one of the most reliable patterns in financial data, and this is essentially the quant's worldview. Direction is close to random, but violence carries genuine information about what might happen tomorrow. If you're confused, don't worry, I'll make it really simple. The cleanest way to hold this in your head is actually seismology, or earthquakes. A major earthquake tells you nothing about the specific direction a singular building might fall, but it tells you with higher confidence that more shaking might be coming. That is exactly how a quant reads a violent trading day. Zero information about direction, but substantial information about tomorrow's volatility. Stated as a rule, direction is unpredictable, whereas magnitude typically is predictable.

Okay, here's where we get into the fun stuff, the Nobel Prize equation, which is an essential part of the framework that we're building today. Because we just confirmed that violence is predictable. So, the question now becomes, how do you predict it? And this is exactly where the Nobel Prize enters. In 2003, the economist Robert Engle won a Nobel Prize for solving this exact problem. His original model was called ARCH. His student Tim Bollerslev extended it to a system that trading desks still use today, GARCH. The Nobel Prize was for the discovery, but the GARCH extension is the tool that is still used in quantitative trading. GARCH stands for generalized autoregressive conditional heteroscedasticity. All right, I know that's an absolute tongue twister, but essentially it's a model that's used to predict market volatility, rather than, as we've been discussing, predicting the exact direction of asset prices. A quant models tomorrow's violence as a sum of three components: the base level the market always carries, which is the asset's personality, plus a fraction of today's shock, the aftershock component, and a fraction of today's violence level, which is the memory component. As an example, I fitted this to Bitcoin's entire 15-year history, and the weights it estimated tell you the whole story. The shock carries 15% of the weight, and the memory carries 85%. In practical terms, volatility is almost as persistent as it's mathematically possible to be. And that persistence is why the forecast works, because you're forecasting a quantity that hardly changes overnight. Note, this model does not deliberately claim directionality of an asset. It forecasts how violent tomorrow may be, but not in which direction. Any model which claims to accurately predict directionality needs to be met with a grain of salt because this model earned a Nobel Prize because it deliberately restricts its claims to what the data can actually support. And the restraint itself is a lesson in how quants actually think.

Okay, so let's say you're a quant and you now have this violence forecast. Here's how it becomes deterministic of an actual position size. The reasoning runs as follows. My risk on any trade equals my size multiplied by the market's violence. I can't control the violence, so instead I control the size of my position. So step one is setting an actual limit for your account. The actual annual swing that you're prepared to tolerate. Institutional desks typically run around 15%. Step two is reading the current market's level. So let me actually show you. This is the NASDAQ as I'm recording, which is moving at roughly 30% annualized if you look at the storm gauge and the market violence percentage on the storm gauge. This, which I'm going to explain very shortly, is custom-built based on the entire framework. And I'm going to give it to you at the end, but let me explain. This 30% number here means the market is more violent than 96% of the past year, which you could consider a storm by any reasonable definition. And notably, it began whilst the index was at all-time highs. As the next step, step three, you want to divide this number, so 15 over 30, which gives you 1/2, which is this number here, this sizing number, which essentially means if a trade signal fires today, it receives half of your normal size allocation. Let's say on a $10,000 baseline, this would be around $5,000. The best analogy is like cruise control. The road's gradient changes constantly, but you can control your speed to hold steady. So in this case, the market's violence changes daily, but your account risk holds steady. And note the conditional. If a signal actually fires, the reasoning never generates entries. Entries belong to a different department, which is where you can use things like the Markov method to determine which directional environment we're in.

But, you might think that a strategy like this merely smooths the ride. So, it makes highs less high, and it makes lows less low. But, that's actually not true. In reality, it can produce more money. And the reason is an empirical fact about markets. The worst losses in history do not occur on randomly distributed days. They cluster inside the violent periods. 2008, March 2020, the major crypto collapses. In each case, volatility was already elevated before maximum damage arrived. This is the aftershock logic. The shaking was already underway before the building eventually came down. So, by reducing size in a storm, you're refusing to carry full exposure during a period where there is a higher likelihood of an extreme event which could threaten your account.

All right, we're about to build, but one final thing. I want to discuss a final piece of mindset, because I believe any serious practitioner, especially before you're about to use a model like this, should explain what a model can't do. This will never call a top or a bottom. It contains, in fact, no directional information whatsoever. You probably have many indicators, many other methods, and even your own discretionary biases to come up with those conclusions yourself. If there's a crash that erupts from a full period of calm, then even if you use this, you may still catch it with full size. That's where you need stop losses and drawdown protection. There are still shock events which can't always be predicted. And you'll see in a minute why this isn't hypothetical, it's actually in the data. If you're a trader that specifically trades breakouts and you've developed an edge during these expansionary periods, then naive volatility sizing could actually work against you. If you guys like this video, I'll make it a series, and that could be a future component. So, I can't claim that this model eliminates risk or will maximize everyone's trading strategy. But, what I can say is it's a damn good place to start if you're interested in getting more into quantitative trading, and the risk frameworks that real quantitative traders will use. I believe you can expand upon what I'm about to give you to make it even better, and in fact, that's something I'm going to bring to the channel in the future. So, of course, make sure you subscribe, and we're going to continue diving into this stuff. As AI gets better, so does our capabilities to make better tools for ourselves.

All right, here we go. Everything we just walked through, the complete chain of reasoning I've encoded into a Claude skill that you can download. So, what you want to do is you want to use the link in the description below, follow the steps, and you'll get access to a GitHub. This GitHub has the entire GARCH method. So, it has the installation path, which you put into Claude code. It explains what the skill actually does. It explains the onboarding prompt, and then it has a Pine Script bonus, which I'll show you how to install on TradingView in a minute for you to get the exact overlay that I showed you before. So, what you want to do to install it is go into the installation section, click copy, then you want to go into Claude code. All right, so you want to paste it in. If you're on the terminal, {forward slash} plugin should work. If you have any issues, so if you're on the app, you can replace the {forward slash} with the word Claude if you have any errors. So, that's the route that I'm going to take. Now, it's running the plugin commands. It's installing the plugin, and the commands have successfully installed, so you now have the skill on your Claude. The other option, and this is the way that you can see the skill being written line by line, is clicking on garchmethod.md, and you can copy and paste this entire file, and you can put it into Claude code. And now, it's going to fetch the skill files from the repo. You don't need to do both methods. I'm just showing you both ways that you can install it in case you actually want to see things line by line. You can see it's installed the strategy and verified the strategy. So, what do you do now? Well, now you can just talk to it. It's a skill that you can talk to to verify against the exact method. So, let me show you an example. You could say, "What's the volatility forecast on Bitcoin?" And it's going to run directly from the skill, which is trained on all of this in the GitHub repo. And you can see that it's given me the Bitcoin volume forecast, 40.9% annualized. It's given me a calm regime. It's got the one day ahead forecast. The good thing about this is you can actually just query it. So, you could say, "Could you explain in simple terms what this means and how this should impact my Bitcoin position sizing?" So, you can actually speak to a skill that is trained on a real quant method. And you can actually just build on this over time. So, if you have refinements you want to make or improvements or if new models come out and we can refine it together even further, you can just train the skill so it gets better over time. And right now I'm creating skills for a bunch of things. I'm creating skills for different methods. I'm creating skills to help me size positions. I'm creating skills to help me execute positions, just like a real quant firm would do. Taking skills for varying parts of comprising a trade. That is really how you can get the most out of AI to be a real live trading assistant. So, it came up with a plain English version. Think about it like a weather forecast. The model says a typical day tomorrow Bitcoin moves around 2.1% which annualizes to 41%. Over the past year Bitcoin's rougher than this about 2/3 of the time. So, right now it's on the calm end. That's the calm regime. This is why it matters for sizing. Or let's say you're about to enter a position on the Nasdaq. You could say, "Help me size my Nasdaq position." And it can actually walk you through how to think of the trade like a quant. So, you can see now it's running the GARCH forecast on the Nasdaq. So, it said for the Nasdaq the model says to cut your position down and not grow it. And you can actually go back and forth and have a discussion with the model based on positions that you might want to size into. So, if you have a directional read like we discussed before, you can use this for the volatility or the risk component of sizing the trade.

But let's go a step further. Let's actually test if this can make money. So, I'll test it with a very popular strategy, the same strategy, which is an EMA cross on Bitcoin, which is trained on 15 years of data, once at a fixed size and once the quant way, using the skill. So, I just asked it to download Bitcoin price history in case it didn't have access, Right run the sizing comparison on it, and then make sure the target risk matches the EMA strategy to make sure the comparison is apples to apples. All right, so you can see the growth of $1 from 2012 with the fixed size strategy on Bitcoin, which is the gray line, and then the volatility target GARCH size line, which you can see actually ends up marginally beating the fixed strategy on Bitcoin. At the same time, the volatility targeted strategy from GARCH actually took less drawdowns than Bitcoin in the meantime as well. So, whenever you run a model like this, you can actually get volatility targeted graphs generated like this, which I think are really cool, so you can map out potential trades, which I think is valuable, and it's what a quant firm would do to visually map out a trade before they enter. And obviously, Claude does this for you if you download the skill. I think the crazy part is actually the Sharpe ratio. This is essentially the risk-adjusted return of an investment, because investments aren't just about, you know, whether you made money, it's also about how much risk you took on to make that amount of money, and you can see that the volume targeted approach had a significantly better Sharpe ratio, meaning it had better risk-adjusted returns. So, even if you make the same amount of money, if you can do so taking on less risk, then that is the better approach, and that was reflected in the drawdown charts. It simply took on less drawdown. So, the max drawdown with the volatility targeted approach that used our strategy was 63%. The max drawdown with the fixed size strategy was 81%. The worst month with our approach was 19%. The worst month normally was 40%. The final equity on our approach was 21,000, and the final equity on the fixed size approach was 17.9 thousand.

Now, I'm going to ask it, "Run the same comparison on my Nasdaq position over the last 50 years." Now, for Nasdaq, this is actually extremely interesting. It improved the Sharpe ratio. It improved every single risk number, so you took on a lot less risk, but it did cost a full point of compounded annual growth rate. So, over 50 years this would have made you 99 less dollars. So, Bitcoin won risk and absolute return. Equities didn't. Equities won the risk component, which may have enabled you to size up more, which may have enabled you to, you know, end up out-returning, but that is a variable test we need to run on new numbers. But nonetheless, it did cost in this experiment less returns. Because the size of throttle mostly trend exposure during violent rallies off the lows. However, it did earn its keep in some capacity because the goal of a fund is not to blow up. So, in the dot-com bust, where fixed sizing hit its yearly worst at minus 28.8% volume targeting kept it to roughly minus 13%. Same story in 2008, 28% versus 13% and 2022, 23% versus 13%. And its worst month was cut from 10.9% to only 7.7%. So, the takeaway with the Nasdaq is that volume targeting is buying insurance, not extra return. So, it helps the pain, but it costs you 1% compounded annual growth rate. And whether that trade is worth it, as Fable points out, depends on whether you'd actually sit through a minus 29% without capitulating. Most people wouldn't and capitulation costs more than the insurance premium. Very interesting thought process. Once again, this skill is not meant to be the only thing you use to trade. This is a tool for you to use to understand risk and to help understand what environment you're in and how to target. I do think a lot of people though, they struggle with this so much that if they had a tool like this, they would lose significantly less amounts of money cuz they'd be able to think in a different capacity when opening trades. Even if it is for riskier asset types, it can help a lot.

And it even helps when charting. So, if you go into the GitHub and you go into Pine Script and go Storm Gauge Pine, what you can do is you can copy the entire file here. You can just either copy the raw file in the top right-hand corner or simply copy and paste. Then go into TradingView. Then click on the little pyramid logo here, then I've already got one in, but I'll clear it out and show you what it would look like. Paste it in, click enter, click refresh, and this is going to load the indicator on your screen, which is this indicator here, which goes through the metrics we discussed before. So, the market violence metric, the current percentage versus the limit, the category it's in versus the last year, so we could see it's heavily in storm territory, 96% more volatile versus the past year. It has a sizing suggestion and an example on $10,000 and a suggested action based on the number above. And then you can also see the volatility bands in here as well to help you understand the movements of the market. So, this is a very helpful tool that you can use, and of course you can build upon it. The best thing about this being in cloud is that you can make tweaks and edit things over time and create your own parameters. So, if you want all of this, use the link in the description below. If you enjoyed this video, make sure to subscribe because I'm going to be doing a lot more AI trading content like this, and we can even build skills together for other areas of trading and potentially other quant strategies because there are multiple approaches here, but I wanted to touch on one of the most relevant ones today. And yeah, thank you for your time today. I'll see you in the next video. Have a lovely rest of your day. Peace out.