YouTube2Text

Sonnet 5 + Claude Code strategy makes 369% — Transcript

by Algo-trading with Saleh · 3,476 words · 480 segments · language en · Watch on YouTube

Full transcript

  1. 0:00The Anthropic team just released Claude
  2. 0:02Sonnet 5. Claude Sonnet used to be my
  3. 0:04favorite model of all time because it
  4. 0:07gave me the best quality comparing the
  5. 0:09results. Especially in the past where I
  6. 0:11would just wanted the $20 subscription
  7. 0:13model of Anthropic, Claude Sonnet was a
  8. 0:15really good deal for me. So, I'm really
  9. 0:17excited to try out this new version. As
  10. 0:19you guys know, on this channel what I
  11. 0:21care for is the performance of the model
  12. 0:24specifically for trading. I want to see
  13. 0:26how good of a strategy it can write for
  14. 0:28me and how good it is at following
  15. 0:30instructions to do real research for me.
  16. 0:33That includes running the backtest,
  17. 0:34doing optimization to find the best
  18. 0:36parameters of the strategy, and running
  19. 0:38Monte Carlo sessions to ensure the
  20. 0:40results that it finds for me aren't
  21. 0:41overfit. Now, before we continue, I got
  22. 0:43to say I am not a financial advisor and
  23. 0:45this video is for educational purposes
  24. 0:47only. So, with that out of the way,
  25. 0:49let's get right into it.
  26. 0:54So, here's a blog post by the Anthropic
  27. 0:56team and as you can see, here's the
  28. 0:59benchmark So, for agent coding, which is
  29. 1:01exactly what we need, it is a scoring
  30. 1:0363%
  31. 1:05which is almost 5% above Sonnet 4.6,
  32. 1:09which was a really good model by the
  33. 1:11way. Like, I've been using it until
  34. 1:12yesterday. And Opus 4.8, which is the
  35. 1:16easiest and my main driver because I
  36. 1:18have a max subscription plan of
  37. 1:20Anthropic, is still beating it. So, it
  38. 1:23is 69%. So, let's not forget this. And
  39. 1:26the same really goes for other stuff.
  40. 1:27So, in this one, it is just 2% below
  41. 1:30Opus 4.8, but it is beating Claude 4.6
  42. 1:34by significant margin, actually. And in
  43. 1:37the knowledge work, which is also
  44. 1:39important because we can consider this
  45. 1:42one for how good the model is at, for
  46. 1:44example, with its trading knowledge. So,
  47. 1:47not just following the tools or doing
  48. 1:49agent work for us, but it's actual
  49. 1:52knowledge. Like, what sort of indicators
  50. 1:54should it use? Or if it's not doing
  51. 1:56well, let's say in a range market, what
  52. 1:58should it do? So, that sort of thing.
  53. 2:00But, guys, I think the main reason that
  54. 2:02Anthropic didn't release the model that
  55. 2:04is actually beating Opus, because that's
  56. 2:06how they used to do it in the past, is
  57. 2:08because they were worried that the model
  58. 2:10is going to get flagged just like Claude
  59. 2:11Fable, so they didn't want it to get
  60. 2:14banned. I'm guessing that's why they are
  61. 2:16doing it this way, but overall, the fact
  62. 2:18that it's doing better than Sonnet 4.6
  63. 2:20is a good sign and enough for me. Now,
  64. 2:23as always, guys, I'm using framework for
  65. 2:26doing the algo trading side of things.
  66. 2:27So, if you haven't installed it already,
  67. 2:30now's a good time to do so. Here's the
  68. 2:32documentation where you can find
  69. 2:33everything that you need. And next, I'm
  70. 2:35going to use the Claude code inside the
  71. 2:37terminal, which is running inside my
  72. 2:39code editor. And the first step is to
  73. 2:41ensure the Jesse MCP has been added to
  74. 2:44your Claude code. For that, I'm simply
  75. 2:46going to copy this address from here and
  76. 2:48paste it here. Now, you need to be
  77. 2:49careful with this address. You see, it
  78. 2:51says using the port 9002, but for my
  79. 2:54project, actually running on port 9007.
  80. 2:57But, it doesn't matter, because I have
  81. 2:59already added this before, and Jesse MCP
  82. 3:01is connected to my Claude code. And just
  83. 3:03to ensure, I will simply say, "Hey, can
  84. 3:06you access Jesse MCP?" And yes, it says
  85. 3:10Jesse MCP is connected and working. Now,
  86. 3:12by the way, guys, the Sonnet 5 is
  87. 3:14available and it's been selected here.
  88. 3:16And if you haven't already switched to
  89. 3:18it, you're going to need to run {slash}
  90. 3:20model and then pick Sonnet, which is now
  91. 3:23using Sonnet 5. All right, so, to prompt
  92. 3:25the agent. So, I'm simply going to say,
  93. 3:27"Hey there, do research and find me two
  94. 3:29trading strategies. Each one of them
  95. 3:31should have a sharp ratio above one in
  96. 3:33the last 4 years. They should be trend
  97. 3:36following, include both long and short
  98. 3:38positions, and risk 3% of the account's
  99. 3:40capital per each trade. In the first
  100. 3:42strategy, once the position is open,
  101. 3:45close it using a trailing stop. In the
  102. 3:47second strategy, close the position at a
  103. 3:49specific points determined by the ATR
  104. 3:52indicator. You can test them on BTC,
  105. 3:54ETH, and SOL on the hourly timeframe.
  106. 3:57Every time you develop a strategy,
  107. 3:59validate the result using a statistical
  108. 4:01significance test before writing the
  109. 4:03full strategy. Only proceed if the
  110. 4:05strategy's entry rules demonstrates
  111. 4:07genuine statistical significance. Feel
  112. 4:10free to use optimization to improve the
  113. 4:12results. At the end, apply Monte Carlo
  114. 4:14simulations to ensure the results are
  115. 4:16not overfit. Continue until you find
  116. 4:18strategies that fully meet the criteria
  117. 4:21requested. Do not prompt me in the
  118. 4:23meantime. Good luck. And that's it. Now,
  119. 4:25because I am pasting basically a lot of
  120. 4:28content all at the same time, I'm seeing
  121. 4:29it like this. But if I hit enter, we can
  122. 4:32see it all being applied here.
  123. 4:34Everything looks good and we can just go
  124. 4:36and let Claude do his thing. Now, one
  125. 4:38thing I really liked about this model is
  126. 4:40that it is significantly faster. Whether
  127. 4:43it is actually worth it to use this
  128. 4:44comparing to Opus, I'm not sure at this
  129. 4:47point. We're going to see, I guess, but
  130. 4:49I do know that it is a lot faster to
  131. 4:50run. So, anyways, let's go and come back
  132. 4:52later. All right, so it's been around 1
  133. 4:55hour and the agent is done. So, if you
  134. 4:57come lower, we can see that it has been
  135. 5:00calling the MCP multiple times. It first
  136. 5:03checked and ensured that the necessary
  137. 5:04candles for ETH and SOL are present in
  138. 5:07my database and apparently a little bit
  139. 5:10of BTC was missing, which it re-imported
  140. 5:12for me. Then it wrote the strategies and
  141. 5:14ran them simultaneously. And then it ran
  142. 5:16an optimization session to improve the
  143. 5:19results. And then it kept doing this and
  144. 5:21it found that most of them are overfit
  145. 5:23results. But it didn't give up and
  146. 5:25continued doing research. Long story
  147. 5:27short, at this point in time, it did
  148. 5:29find one strategy which was way above
  149. 5:32the criteria that I set for the agent.
  150. 5:35So, it had a sharper 1.52.
  151. 5:37But another one was almost as good as
  152. 5:40what I wanted, but not quite. So, the
  153. 5:42agent was being lazy here, which isn't
  154. 5:44really great. And then the agent was
  155. 5:46like, "Yeah, I'm done." Like I did his
  156. 5:48job, but it hadn't. So, first of all, I
  157. 5:51asked him to give me the URL for the
  158. 5:53dashboard so I can check them out
  159. 5:54myself, but I also specifically said
  160. 5:56that one of them hasn't met the target
  161. 5:58yet. Why did you stop? So, after I was
  162. 6:01being hard on the agent, it did continue
  163. 6:03working until this point in time, which
  164. 6:06it did indeed reach the target that I
  165. 6:08needed. And it also gave me the URLs for
  166. 6:11the dashboard so I can check the results
  167. 6:13both for the backtest and the Monte
  168. 6:15Carlo simulation in order to ensure the
  169. 6:17result isn't overfit. So, let's open
  170. 6:19this one for the backtest first, and
  171. 6:21then this one for the Monte Carlo. Now,
  172. 6:24while that's going, I want to quickly
  173. 6:25remind you guys about our Telegram. It's
  174. 6:27the fastest way to get notified about my
  175. 6:29future work, whether it's a new tutorial
  176. 6:31or a tool that I create. Also, don't
  177. 6:33forget to check out our free Discord
  178. 6:34where more than 5,000 members like you
  179. 6:36and I are hanging out there and helping
  180. 6:38out each other with algo trading so we
  181. 6:40can all succeed together. The links for
  182. 6:42both are down in the description. So,
  183. 6:44look at this. This is amazing, guys.
  184. 6:46Like this is if we compare the results
  185. 6:48to the benchmark, which is like other
  186. 6:50assets that we were trading, but this
  187. 6:52isn't really a good way to compare it
  188. 6:54because it clearly the position sizing
  189. 6:56of the strategy isn't enough. We could
  190. 6:58increase it in order to actually give us
  191. 7:00better returns than the benchmarks, but
  192. 7:03if you consider the volatility, this one
  193. 7:05is clearly winning. Now, let's scroll
  194. 7:07down. So, in this chart, which is the
  195. 7:09max drawdown, and there aren't any
  196. 7:11benchmarks here, we can clearly see that
  197. 7:13this is a smooth equity curve, and it
  198. 7:16looks amazing. And here we can see the
  199. 7:18monthly returns. You see, it's green on
  200. 7:20most months, and it is definitely green
  201. 7:23every single year. But the reason these
  202. 7:25numbers aren't like huge is because the
  203. 7:27max drawdown of the strategy is only
  204. 7:29minus 7%. So, this is really low. So, it
  205. 7:32made 75%. This can easily be increased.
  206. 7:35It's executed 1,234
  207. 7:39trades, which is amazing. The win rate
  208. 7:41was 36%. so this is something to be
  209. 7:44aware of because that means
  210. 7:45approximately like 6 and 1/2 out of
  211. 7:47every 10 trades are going to be losing
  212. 7:49ones. So, this is perfectly normal for a
  213. 7:51trend following strategy because the
  214. 7:53wins that you have are going to be
  215. 7:55significantly bigger than the losses. In
  216. 7:57fact, if we take a look at this value
  217. 7:59here, which is the average win to loss
  218. 8:01ratio, it is 2.24. This is why even
  219. 8:04though the win rate is way below 50%, we
  220. 8:07are being profitable overall. The Sharpe
  221. 8:08ratio is 1. 53. So, overall, this is
  222. 8:11great and it is executing on three
  223. 8:13symbols simultaneously. So, this is also
  224. 8:15another reason why we're getting good
  225. 8:17results. And in order to beat this, so
  226. 8:19this is what I can do. I could just
  227. 8:21click on new session and go and edit the
  228. 8:24strategy myself and go to the position
  229. 8:27sizing part, which is here. So, you see
  230. 8:29this is the quantity of the order,
  231. 8:31right? So, I could easily multiply this
  232. 8:33by something like three, which by the
  233. 8:36way, guys, I don't suggest you do this
  234. 8:37for production because you want to be
  235. 8:40completely aware of how much you are
  236. 8:42risking. So, this isn't exactly how I
  237. 8:44would do it in production, but just in
  238. 8:46order to demonstrate this in this
  239. 8:49backtest, it's a good solution. So,
  240. 8:51let's save this, go back, and give it
  241. 8:53another shot. There we go. So, now you
  242. 8:55see in the equity curve of the
  243. 8:58portfolio, which is this purple one, we
  244. 9:00are beating all the other stuff even P&L
  245. 9:03wise. So, this is pretty great to see,
  246. 9:05but of course, when we do that, the max
  247. 9:07drawdown also increases. So, it isn't
  248. 9:10minus 7% anymore, it is minus 20%, which
  249. 9:12is is still way acceptable for me. But
  250. 9:15the yearly returns have significantly
  251. 9:17increased now. We even have a year with
  252. 9:1986%. We have another one with 67, so
  253. 9:22this is pretty good. And if you want to
  254. 9:24see some of the individual trades, we
  255. 9:26can click on this view chart button
  256. 9:28here. And here is the complete list of
  257. 9:30the trades that it took. So, for
  258. 9:31example, this one looks good, so let's
  259. 9:33click on it. All right, so it went short
  260. 9:35and then closed the same trade on the
  261. 9:37same candle. In this losing one, again
  262. 9:40the same thing happened. Here we went
  263. 9:42long and then close it on the same
  264. 9:44candle. Here, here we went short and
  265. 9:48then we close it here. We can also
  266. 9:50change this into ETH to see the trades
  267. 9:53that we took for ETH. So, we went short
  268. 9:55here and then close it here. We went
  269. 9:57short here and close it here. And then
  270. 10:01short here and close it here. So,
  271. 10:02overall, I actually like the results
  272. 10:04better for ETH. So, this looks pretty
  273. 10:06good. And with this new position sizing
  274. 10:08we are making 369%
  275. 10:12but this is over 4 years. Now, another
  276. 10:14thing is the Monte Carlo simulation that
  277. 10:16we have to check out, which is how we uh
  278. 10:19stress test the strategy to ensure the
  279. 10:21result isn't overfit. So, this is how
  280. 10:23the results would look. So, this yellow
  281. 10:26line here is the original backtest and
  282. 10:29these blue lines here are the
  283. 10:30simulations. So, as you can see, the
  284. 10:32Sharpe ratio of the original is 1.5. The
  285. 10:35median is 1.41 and the best 5% is two.
  286. 10:39So, the Sharpe ratio of the original is
  287. 10:41clearly way closer to the median number,
  288. 10:43which is a really good sign. If this
  289. 10:45number was closer to two, such as 1.8,
  290. 10:491.9 or even if it was better than two,
  291. 10:52so it was clearly in the best 5% that
  292. 10:54would have been a clear signal of the
  293. 10:56strategy being overfit. But now that it
  294. 10:58is not, this is a good sign that it most
  295. 11:00likely isn't overfit. And I'm
  296. 11:02emphasizing on the word most likely
  297. 11:04because you can never be 100% sure with
  298. 11:07over fitting, so that's just something
  299. 11:08to remember, which is why we want to
  300. 11:10find as many as strategies as possible
  301. 11:12and run them simultaneously so that if
  302. 11:15one of them, for example, isn't
  303. 11:16performing well, the other would cover
  304. 11:18us. All right, so let's go back. Next,
  305. 11:20let's check out this second strategy
  306. 11:22that we found for us. So, the backtest
  307. 11:24results and the Monte Carlo. Let's open
  308. 11:26both of them. Here's the backtest. So,
  309. 11:28you see this one also looks pretty good
  310. 11:30but during this period, which includes
  311. 11:32most of 2023, I don't really like these
  312. 11:36results. But here you could say it
  313. 11:37crushed everything, so at least it's not
  314. 11:40really losing money. So I guess if you
  315. 11:41run something like this, at worst it
  316. 11:43would be neutral and at best it crushed
  317. 11:45it, which is a good sign. The average
  318. 11:46trades per month is 15, sharp ratio is
  319. 11:49one, the win rate is 36%. It executed
  320. 11:52741
  321. 11:53trades. So overall it looks good and the
  322. 11:56monthly returns also aren't that bad.
  323. 11:59So, yeah. This also looks good, but I
  324. 12:01would say the first strategy that you
  325. 12:03found for us is significant better. So I
  326. 12:05actually rather run this one. But if you
  327. 12:07check out the Monte Carlo, so this one
  328. 12:09also looks really good. Like you see the
  329. 12:11original backtest is right in the middle
  330. 12:13of the simulations, which is a really
  331. 12:15good sign. The sharp is one, which is
  332. 12:17below the median. So, if you consider
  333. 12:19this fact, this one is actually beating
  334. 12:21the first strategy because according to
  335. 12:23Monte Carlo, it's even less likely to be
  336. 12:26overfit, which is a really good sign.
  337. 12:28But still considering this and fact that
  338. 12:30it didn't really perform well during
  339. 12:322023, I prefer to run the first
  340. 12:34strategy. But the first strategy didn't
  341. 12:37really perform well during the second
  342. 12:38half of 2022, which was a bear market.
  343. 12:41In the first half, I would say it was
  344. 12:42good. So this is also something to be
  345. 12:44aware of. And also in the past few
  346. 12:46months, like in this period, it wasn't
  347. 12:48doing great, which I'm not really
  348. 12:50surprised because the market was in a
  349. 12:52really bad phase with all the
  350. 12:54uncertainty that was in the market
  351. 12:56because of the war and everything. So, I
  352. 12:58don't really expect any trend following
  353. 13:00strategy to have done well during that
  354. 13:02period. But the fact that it did make it
  355. 13:04back here also gives me confidence in
  356. 13:06running it. Now, let's copy the code for
  357. 13:09this strategy and go and check it out.
  358. 13:11Cuz I want to see, for example, how did
  359. 13:13it do the exit of the strategy? So,
  360. 13:16first of all, these are the hyper
  361. 13:17parameters that the strategy defined.
  362. 13:19These are the DNAs that it defined,
  363. 13:21which is basically the result of the
  364. 13:23optimization. And here we can see the
  365. 13:25Bollinger Bands, the trend EMA, the ATR,
  366. 13:28and these are the entry rules of the
  367. 13:30strategy, which it says the closing
  368. 13:32price must be above the upper band of
  369. 13:34the Bollinger Bands, and it should also
  370. 13:36be above the current 20 EMA, which is
  371. 13:39the moving average, and it's doing the
  372. 13:42opposite for short positions. Here's the
  373. 13:44position sizing, so the entry price is
  374. 13:45going to be the current price, which is
  375. 13:47a market order. Here's the stop, and
  376. 13:49it's using the ATR indicator, and here's
  377. 13:52the position sizing, and here's where it
  378. 13:54submit the buy order. So, it's doing the
  379. 13:56opposite for short positions, and once
  380. 13:57the position is open, using the on open
  381. 13:59position event hook, it's saying if it's
  382. 14:02a long position, submit the stop loss,
  383. 14:04and we want to use the quantity of the
  384. 14:06current position, and this is the price,
  385. 14:08and then here's where it is updating the
  386. 14:12stop loss order. So, this one is
  387. 14:14actually the one that is using a
  388. 14:15trailing stop. So, not the one that was
  389. 14:19supposed to set a specific targets for
  390. 14:21closing the position. And if we check
  391. 14:23the other one, here we can see again the
  392. 14:26Bollinger Bands, trend EMA. So, they're
  393. 14:28actually pretty similar, except that in
  394. 14:31this one, we aren't submitting a
  395. 14:33trailing stop. So, you see, in the
  396. 14:35previous one, we were using the update
  397. 14:36position method, which is this function
  398. 14:38of Jesse, which gets called every time a
  399. 14:40new candle closes. So, basically,
  400. 14:42whenever we close any candle, we want to
  401. 14:45update the stop loss. That's why we call
  402. 14:47it a trailing stop. But in this one,
  403. 14:49we're not doing that. So, once the
  404. 14:50position opens, we submit both the stop
  405. 14:52loss and the take profit, and that's it.
  406. 14:55We wait until one of them is hit. And
  407. 14:57according to this, we're getting better
  408. 14:59results if we were trading this. And
  409. 15:01actually, guys, this is exactly what I
  410. 15:03usually get in my trading, that whenever
  411. 15:06I submit specific points for a stop loss
  412. 15:08and take profit, I get way better better
  413. 15:10results if I were to use a trailing
  414. 15:12stop. But a trailing stop is something
  415. 15:14that manual traders really like, and
  416. 15:16they think it gives them better odds,
  417. 15:18but I never saw the same thing in the
  418. 15:20algo trading. So, that's one of the
  419. 15:22reasons why I like backtesting because
  420. 15:24you will be able to debunk some of the
  421. 15:25myth of the trading that's out there and
  422. 15:28you can see the results for yourself.
  423. 15:30All right, so overall I liked the
  424. 15:31results that we found, but one thing
  425. 15:34isn't exactly how I wanted it. So,
  426. 15:35initially when I wrote that prompt, I
  427. 15:37expected it to find strategies that can
  428. 15:40get me those results on each of these
  429. 15:42symbols. I didn't mean it to run them
  430. 15:44simultaneously like in this case. So,
  431. 15:46this is basically a portfolio of three
  432. 15:49symbols. And the entire portfolio is the
  433. 15:52one that is giving us these results. So,
  434. 15:53if you were to run these individually,
  435. 15:56you would not have gotten such a good
  436. 15:57number. And I'm not saying that you
  437. 15:59shouldn't run multiple symbols
  438. 16:00simultaneously. I'm just saying that's
  439. 16:02not what I expected from the model.
  440. 16:04Probably a misunderstanding on my side.
  441. 16:06I should have been more specific with
  442. 16:07the prompt. But overall, it did a good
  443. 16:09job and it did it very fast. So, all in
  444. 16:12all, I would say this is a good model
  445. 16:14and I will probably use it, especially
  446. 16:16if a speed is something that I care for
  447. 16:18because according to the benchmarks,
  448. 16:20it's not beating Claude Opus yet. So, if
  449. 16:23you want the absolute best quality, this
  450. 16:24probably isn't the answer. But if you
  451. 16:26need quality and speed at the same time,
  452. 16:29this is a better model, especially
  453. 16:31because in our use case where we give
  454. 16:33tools to the model, so specifically the
  455. 16:35MCP tools, it's not just about the
  456. 16:37quality of the model. So, the fact that
  457. 16:40the model can run faster, do research
  458. 16:42faster, that could sometimes cause
  459. 16:45better results in the end, which is what
  460. 16:47we care about. Now, I am going to submit
  461. 16:49this strategy on our strategies page on
  462. 16:52our website. So, if you haven't checked
  463. 16:53it out, please do so. There are so many
  464. 16:55strategies here. You can sort them by
  465. 16:57sharp ratio and the period and stuff.
  466. 16:59You can also see the details of those
  467. 17:02strategy results for other trading
  468. 17:04periods, symbols, and time frames. So,
  469. 17:06definitely check it out. You can also
  470. 17:08copy the source code of these strategies
  471. 17:10that I just shared with you guys on our
  472. 17:12website. If you enjoyed the video,
  473. 17:14please make sure to give it a like and
  474. 17:15subscribe to the channel if you haven't
  475. 17:17already because I publish tutorials just
  476. 17:20like this one all the time. And at the
  477. 17:21end, let me know your experience with
  478. 17:23Cloud Code in the comments. Thank you so
  479. 17:25much for watching, guys. I'll see you in
  480. 17:27the next time.

About this transcript

This page contains the full transcript of Sonnet 5 + Claude Code strategy makes 369% by Algo-trading with Saleh, generated from the public captions YouTube serves with the video. The transcript has 3,476 words across 480 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.