Pairs-trading strategy from scratch in Python

Поділитися
Вставка
  • Опубліковано 21 січ 2025

КОМЕНТАРІ • 115

  • @saleh.m
    @saleh.m  17 днів тому +5

    👉 If you like my work, please consider supporting me FOR FREE by using my referral links.
    It's a win-win, you get free discounts and bonuses, and it helps me to develop more features and content:
    👉 Apex Omni - fee discounts (My favorite):
    jesse.trade/apex
    👉 Gate.io - fee discounts:
    jesse.trade/gate
    👉 Bybit - Signup bonuses:
    jesse.trade/bybit

    • @ShahrulShahrul-b3t
      @ShahrulShahrul-b3t 5 днів тому

      WHAT THE HELL ARE YOU DOING. IN CRYPTO NO SUCH THING AS 2 SIDED TRADE. FUTURES IS HARAM.

  • @BarendJEngelbrecht
    @BarendJEngelbrecht 14 днів тому +12

    it is rare to have someone as neutral and honest as you

  • @kschaef65
    @kschaef65 11 днів тому +3

    I'm glad you discussed trading fees and realistic stuff at the end.

  • @wargreymon2024
    @wargreymon2024 3 дні тому +4

    You know who is the happiest learning this? Brokers.

  • @georgio-tm2ug
    @georgio-tm2ug 20 днів тому +4

    Wow, I'm blown away, this is your best video ever!
    I'd love a follow up video
    Thank you!

    • @saleh.m
      @saleh.m  20 днів тому +1

      Wow, thank you! ❤️

  • @Seeker_of_sense
    @Seeker_of_sense 9 днів тому +2

    Yes, please do a follow up video. This was really interesting.

  • @maningaden
    @maningaden 20 днів тому

    This is so interesting, just wow 🤯
    The way you can access informations between the 2 strategies is really well explained here.
    Thank you for the amazing functionalities covered by your framework!

    • @saleh.m
      @saleh.m  20 днів тому

      Really glad you think so and that you noticed. Thank you.

  • @nielsinterdisc1647
    @nielsinterdisc1647 7 днів тому +1

    Super interesting and very clear explanation!

    • @saleh.m
      @saleh.m  5 днів тому +1

      Glad you liked it

  • @BovineJoni04
    @BovineJoni04 20 днів тому +1

    Oh wow! This one hits different, I need to watch this video mulitple times :D Thanks for all the helpful information, very intersting!

    • @saleh.m
      @saleh.m  20 днів тому

      Thank you, yes, exactly, this one is a bit too much for one setting.

  • @davidtidey
    @davidtidey 19 днів тому +1

    Great video that introduces yet more features of Jesse. It would be interesting to see the benefits of filters vs more complex criteria in the should_long/should_short functions.

    • @saleh.m
      @saleh.m  17 днів тому

      Thanks, man! Some users on Discord are already trying it out.

  • @Ashimluck77
    @Ashimluck77 13 днів тому

    explaination on point. we need more case study strategy like this brother. maybe Wd gann etc

  • @AlbertoMangones
    @AlbertoMangones 17 днів тому +1

    Love the explanation. I’m currently looking to do something similar but using spot vs futures. Same principle and this will save a ton of time

    • @saleh.m
      @saleh.m  17 днів тому +1

      Glad it was helpful!

    • @vickeyocta6744
      @vickeyocta6744 14 днів тому

      Bro can we talk ..
      I am also planning to do the same as you think.

  • @NomadPH-p7g
    @NomadPH-p7g 19 днів тому +24

    your zscore is leaking future data. you're taking standard deviation of the whole spread data in your backtest which is wrong because future data hasnt happened yet for you to take standard deviation of.

    • @saleh.m
      @saleh.m  19 днів тому +8

      We're talking about the Jupyter Notebooks. I mentioned it myself too later in the actual strategy. I fixed it.
      Please watch the whole video.

    • @randomdude79404
      @randomdude79404 18 днів тому +1

      Yes that's why it's imperative to do everything over a rolling window to prevent look ahead bias.

    • @RisingfromTheashes-jw4jy
      @RisingfromTheashes-jw4jy 18 днів тому

      You fix that at 21:10, correct?
      Also, I love your videos! I watch them whenever they come out and always look forward to them. Thank you for taking the time to make them and sharing them with us 😊
      ​@saleh.m

  • @SandervanderHave
    @SandervanderHave 19 днів тому

    This is next level! Thanks. I am going to study it and give it my best shot of improving this already great strategy, but that will be hard. Let's hope that we will find a way to make it profitable, because making money in every market is (almost) impossible.

    • @saleh.m
      @saleh.m  19 днів тому +1

      Glad you liked it. Yes, I agree. It's almost impossible, which is why we should diversify using multiple strategies.

  • @jm7476
    @jm7476 17 днів тому +1

    Great video!!! , love the explanation, new subscriber here.
    Plese, keep going!!

    • @saleh.m
      @saleh.m  17 днів тому

      Thanks for your kind words!

  • @jeff49605
    @jeff49605 20 днів тому +1

    what about using a higher TF ? like D1 ? usually it improves the ppt (profit per trade) a little

    • @saleh.m
      @saleh.m  20 днів тому +1

      Yes, exactly. Using a bigger timeframe is one way to lower the number of trades.

    • @jeff49605
      @jeff49605 19 днів тому

      @@saleh.m loved you vid ! could you do a follow-up video with Forex pairs. They all share half the price of each other so it should be very effective. and forex spread is way cheaper than crypto

  • @ff4444
    @ff4444 14 днів тому

    Thanks for taking us through this strategy 👏👏

  • @RakeshChoudhary-w1z
    @RakeshChoudhary-w1z 8 днів тому +1

    Great Work Saleh, I am watching you from the beginning. I just have one Question. Please Share your Cursor IDE setup(extensions, font, theme, etc.) at any platform. Cuz It may not matter much, but It brings the Vibe as I use to implement your knowledge while watching your Video.
    Thank You.

    • @saleh.m
      @saleh.m  8 днів тому

      Hi, I'll try to do that maybe in a separate video. I also have some huge surprises about using Jesse with AI editors such as Cursor

  • @snygg-johan9958
    @snygg-johan9958 19 днів тому

    Accidentially found your channel.
    Good stuff!

    • @saleh.m
      @saleh.m  19 днів тому

      Awesome, thank you!

  • @samylebrave
    @samylebrave 19 днів тому

    Thanks for sharing! Very nice job, I'll have a look into it

    • @saleh.m
      @saleh.m  17 днів тому

      Thanks! I'm glad you liked.

  • @zeerahdee6440
    @zeerahdee6440 17 днів тому

    Thank you so very much sir for your great job we need a follow up video ❤👍🙏

    • @saleh.m
      @saleh.m  17 днів тому

      I appreciate your nice words and thank you for your understanding.

  • @sergba
    @sergba 17 днів тому

    Why spread is different between returns?

  • @GigaChadRealington
    @GigaChadRealington 18 днів тому

    For most datasets we analyze, I’ve always been at the conundrum of how do you determine your dataset is truly stationary?

    • @saleh.m
      @saleh.m  17 днів тому +1

      The dataset isn't stationary in this case, but the two assets are cointegrated.
      Also, it's not with 100% confidence, which is why the win rate can't be 100

  • @vuela.programming3957
    @vuela.programming3957 19 днів тому +1

    Nice 👍. new year with awesome strategy

    • @saleh.m
      @saleh.m  19 днів тому

      Happy new year

  • @iankelly9181
    @iankelly9181 15 днів тому

    First time looking that this, interesting strategy. So you could set this to only do trades that show x% profit including fees/slippage?

    • @saleh.m
      @saleh.m  15 днів тому

      That's the goal, but how do you define that threshold of profit with code? It may even be simple, but honestly, I have found it difficult.

  • @vodenicite
    @vodenicite 19 днів тому

    Great, that seem very intriguing at a first glance!

    • @saleh.m
      @saleh.m  17 днів тому

      Thanks, man! I'm glad you liked it.

  • @tam_sal80
    @tam_sal80 18 днів тому +1

    Hi Saleh, such a wonderful video and I love the fact that you're trying not-so-obvious strategy. I know for a fact you did your best to explain everything, however I was curious if you could recommend me a way to spot if an asset, only one, is gonna act sideways. I have coded thousands lines of code using different strategies and back tested them and they are all doing so great, on both back test and real life trading. However, when an asset goes sideways, everything gets confusing and there are many issues to address. The only way that crossed my mind in order to make sure that the moves are less likely to be sideways is to filter assets by volatility and pick high volatility and liquid ones to trade, still I do have issues when it goes sideways and it is quite annoying to be honest. Thank you in advance!

    • @saleh.m
      @saleh.m  17 днів тому

      Hey man, thanks for noticing! It seems like you’ve put in the effort to understand the value of the video and the issue you explained.
      I totally get it; I've tried so many strategies but have never really found success in a sideways market. This strategy seems to be the best one I’ve come across-it’s given me the most progress for sideways markets, but I still can’t match the results of trend-following strategies.
      When it comes to trading just one asset in a sideways market, I’ve given grid trading and other mean-reversion strategies a shot, but none of them have impressed me in the long run. If I ever discover some solid ones, I’ll definitely make videos about them.
      And I’d appreciate it if you could update me on any progress you make with that, too!

    • @towfik_yt
      @towfik_yt 11 днів тому

      @tam_sal80 I'm also a algo trading coder. You actually wrote my thoughts here perfectly.
      Range or side ways market confuses my algo.
      Just our of curiosity, what indicators you use to identify a trend?

  • @CryptoGyaniOfficial
    @CryptoGyaniOfficial 18 днів тому

    do you have any video for new comers, how to get started with Jesse building the environment

    • @saleh.m
      @saleh.m  17 днів тому

      Hey! Yeah, please check the channel. There's for example one for setting things up with Docker.

  • @christopherruiz3406
    @christopherruiz3406 15 днів тому

    Great strategy, and set up! Is it possible to make this an indicator for Trading View? Or make a strategy to backtest it on Trading View?

    • @saleh.m
      @saleh.m  15 днів тому

      Hey man, thank you.
      No, I don't backtest on TradingView because I find it to be inaccurate. I've come across many strategies that are supposed to be profitable, for example, on UA-cam or even in the source code of strategies shared openly on TradingView. However, when I test them with Jesse, which focuses mainly on the accuracy of backtests, I find them not to be profitable at all.
      I use ThreadingView for charting, which is what they are best at.

  • @robertof6449
    @robertof6449 19 днів тому

    Great content! Congratulations!

  • @matusa6714
    @matusa6714 16 днів тому

    Congratulations, awewsome video

    • @saleh.m
      @saleh.m  15 днів тому

      Thanks so much!

  • @adityagarg190
    @adityagarg190 7 днів тому

    Amazing video, thanks for sharing

  • @SandervanderHave
    @SandervanderHave 18 днів тому

    Do you think it is possible with Jesse to test exchange arbitrage on a single coin? Could this perform better?

    • @saleh.m
      @saleh.m  17 днів тому +1

      No, it's not possible with Jesse.
      I did some testing years ago with simple arbitrage, but I found there’s a lot of competition fighting over even small profit margins. If you want to get good results, you need to be in level B or C exchanges, which can be really risky. Plus, it doesn't scale well with larger amounts of capital.
      Statistical arbitrage is a totally different game. It can easily scale with larger capital sizes.

  • @hedgefund996
    @hedgefund996 4 дні тому

    Good Educational Content

  • @vladyslavs447
    @vladyslavs447 19 днів тому

    Good point to start, thanks

    • @saleh.m
      @saleh.m  17 днів тому

      Thanks for noticing that!

  • @Daniel-eg8kz
    @Daniel-eg8kz 7 днів тому

    this was eye opening

  • @ranidushaminda
    @ranidushaminda 11 днів тому

    Cheers for your heardwork

  • @lmaoo254
    @lmaoo254 20 днів тому

    Nice Strategy!

  • @SheepInside
    @SheepInside 20 днів тому +1

    Very interesting strategy, to be honest I never tried anything like that. Very interested in a follow up video including some filters.
    Good Job!

    • @saleh.m
      @saleh.m  20 днів тому

      Thank you so much!

  • @avaneeshchotalia9234
    @avaneeshchotalia9234 19 днів тому

    Great idea!!

    • @saleh.m
      @saleh.m  19 днів тому

      Glad you think so!

  • @1ndraNugraha
    @1ndraNugraha 18 днів тому

    Any code for metatrader?

  • @sergba
    @sergba 17 днів тому

    In strategy you calculate zscore on prices

    • @saleh.m
      @saleh.m  15 днів тому

      Yes, that was my mistake, but I fixed it later in the video.

  • @jagjodhsingh2358
    @jagjodhsingh2358 13 днів тому

    This was amazing.

  • @RisingfromTheashes-jw4jy
    @RisingfromTheashes-jw4jy 18 днів тому

    I love your videos! ❤

    • @saleh.m
      @saleh.m  17 днів тому +1

      awwww thanks for your kind words!

  • @timothywoodruff7908
    @timothywoodruff7908 День тому

    Nice strat

  • @EnricoIVilGrande
    @EnricoIVilGrande 16 днів тому

    Thanks Saleh

  • @DanMarino-AI
    @DanMarino-AI 6 днів тому

    Nice!

  • @yashwardhangautam8814
    @yashwardhangautam8814 8 годин тому

    make a follow up please

  • @scrapydog
    @scrapydog 19 днів тому

    Thank you

    • @saleh.m
      @saleh.m  19 днів тому

      You're welcome

  • @optimistic5499
    @optimistic5499 17 днів тому

    Great job salah

  • @gideonfummey9020
    @gideonfummey9020 6 днів тому

    a new subscriber

    • @saleh.m
      @saleh.m  5 днів тому

      Yay! Thank you!

  • @optimistic5499
    @optimistic5499 17 днів тому

    i will start learning algo trading with you

  • @bongumusakowa5452
    @bongumusakowa5452 18 днів тому

    Awesome

  • @alek385
    @alek385 17 днів тому +1

    has anyone understand what the guy said in the video?

  • @melbamolina89
    @melbamolina89 8 днів тому

    one question? why dont u rich?

    • @saleh.m
      @saleh.m  8 днів тому +1

      One ask? why don't you watch the entire video before commenting?

  • @Seeker_of_sense
    @Seeker_of_sense 15 днів тому

    You also have a real time funding rate of about 0.01% which eat into your profits.

    • @saleh.m
      @saleh.m  10 днів тому

      The good thing about strategy is that since you have two positions, the funding fee for one of them is usually going to be the opposite of the other one. On average, they will offset each other.

    • @Seeker_of_sense
      @Seeker_of_sense 9 днів тому

      @@saleh.m Good point.

  • @sayedmuzz5727
    @sayedmuzz5727 19 днів тому

    Then get a broker that doesn't charge commission and only swap

    • @saleh.m
      @saleh.m  17 днів тому

      Does that exist in crypto?

  • @Joinswarm
    @Joinswarm 18 днів тому

    Winrate is weak . Expectancy is therefore 0.03 . (%Winners X avg$won/avg$lost) - % losers

    • @saleh.m
      @saleh.m  17 днів тому

      I don't expect this strategy to get a higher win rate. Usually, one position is long and the is short at the same time, which means one is typically losing. But we're supposed to make more on the winning one.

    • @universalhuman4417
      @universalhuman4417 13 днів тому

      when we see net profit when do we close both the trades. Is there a threshold level

  • @veritaxverity8567
    @veritaxverity8567 3 дні тому

    111

  • @user-dp1el6yg4q
    @user-dp1el6yg4q 15 днів тому

    You are great my brother ♥️