Step-by-Step Guide: Time Series Momentum Trading with Python

Поділитися
Вставка
  • Опубліковано 27 вер 2024
  • In this video I am going over a simple time series momentum trading strategy and code that in Python. Time Series Momentum is taking the past return of an asset and is buying the asset when the past return is positive and short sells the asset when the past return is negative.
    Potential follow up topics:
    - cover the short side
    - factorize to optimize parameters
    - Backtesting and train-test-split
    - Exit the strategy with a target profit / Stop Loss
    So push this topic pls by liking, commenting, sharing :-) Thank you very much
    Check out my website here:
    www.pythonforf...
    Get the Notebook/Source code by becoming a Tier-3 Channel member:
    / @algovibes
    If you are interested in cross-sectional momentum or other trading strategies be sure to check out my other videos!
    Disclaimer:
    This video is not an investment advice and is for educational and entertainment purposes only!
    #pythonprogramming #trading #momentum

КОМЕНТАРІ • 37

  • @anilmm2005
    @anilmm2005 2 місяці тому +4

    This was long time coming and an extremely important topic. Looking forward to the follow-up video for providing more guidance on it. Thank you.

  • @mayankjain24in
    @mayankjain24in 2 місяці тому +2

    always learn something new from you .... your approach towards solution is very precise..

    • @Algovibes
      @Algovibes  2 місяці тому

      thanks mate, delighted to read that :-)

  • @TycoonCapitall
    @TycoonCapitall 2 місяці тому +2

    Hopefully we get a cross-sectional momentum strat tutorial!

    • @Algovibes
      @Algovibes  2 місяці тому

      There already is a couple of them :-) Be invited to explore the Python for Finance playlist!

  • @saxegothaea_conspicua
    @saxegothaea_conspicua 2 місяці тому +2

    amazing video!!

    • @Algovibes
      @Algovibes  2 місяці тому

      @@saxegothaea_conspicua thank you mate

  • @andreoproprio
    @andreoproprio 2 місяці тому +2

    For illustration purposes it's fine to use the Close, but bear in mind in real life you must use Adj Close, as the price series for the Close are distorted caused by dividends and splits.

    • @Algovibes
      @Algovibes  2 місяці тому

      yessir! Also mentioning that in the vid btw

  • @jean-francoislebroch9171
    @jean-francoislebroch9171 2 місяці тому +1

    Great

  • @javierloa9197
    @javierloa9197 Місяць тому +1

    When is the factoring video coming out?

    • @Algovibes
      @Algovibes  Місяць тому

      Have too see, video is on the edge of becoming worth it. Will see what I can do!

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

    i'm a beginner with all of this but it is possible to implement this strategy with your binance bot ?

  • @froggoman4756
    @froggoman4756 2 місяці тому

    Could you expand on the main reason/difference between using Close and Adj Close? I'm curious as to how/why it changes how you calculate the Open? (in general I always used Adj Close but now I'm questioning in which situations I should use it and when I shouldn't)

    • @andreasklippinge9665
      @andreasklippinge9665 2 місяці тому

      Adj Close adjusts for dividends/splits etc.

    • @froggoman4756
      @froggoman4756 2 місяці тому

      @@andreasklippinge9665 thanks, I'm aware of what it "is", but my initial question remains. How does it change what you need to do for the Open? (as mentioned in the video only briefly)

    • @andreasklippinge9665
      @andreasklippinge9665 2 місяці тому

      @@froggoman4756 ah, my bad.

    • @Algovibes
      @Algovibes  2 місяці тому +1

      Hi :-) You just need to adjust the Open by the same factor you adjusted the Close for.

  • @its_code
    @its_code 2 місяці тому +1

    ❤❤❤😊

  • @deekshitpatel4647
    @deekshitpatel4647 2 місяці тому +1

    Sir great knowledge gained from you i have learnt a lot from you
    @algovibes
    Can you please make a video on Renko Trading Strategy backtest?

    • @Algovibes
      @Algovibes  2 місяці тому

      Happy to read man! Thanks a lot for the suggestion, will see what I can do.

  • @int2str
    @int2str 2 місяці тому +1

    Not a python expert here, but I feel like there's a bug in the logic. If you're setting "in_position" to True, and then immediately calculate the profit and set in_position back to false, you will "buy" on consecutive days, which presumably is not realistic/desired.
    But again, not a Python expert here....

    • @jalexisg
      @jalexisg 2 місяці тому

      The bot should buy only when in_position = False, so after buy in_position will be True and will hold True for 5 days.

    • @int2str
      @int2str 2 місяці тому +1

      @@jalexisg Incorrect. The "if not in_position" sets "in_position" to True and then the next "if in_position" sets it right back to false. That's the bug.

    • @jalexisg
      @jalexisg 2 місяці тому

      @@int2str Yes, it's a bug. I meant it "should" buy only if in_position = False.

    • @Algovibes
      @Algovibes  2 місяці тому

      Doesn't have an impact, anyhow here you go:
      profits = []
      in_position = False
      sellidx = pd.to_datetime('1900-01-01')
      buyprice = None # Initialize buyprice outside the loop
      for index, row in df.iterrows():
      if not in_position and row.signal and index > sellidx:
      buyprice = row.buyprice
      in_position = True
      elif in_position:
      sellprice = row.Close # Assume the current row's Close price is used for selling
      sellidx = index
      profit = (sellprice - buyprice) / buyprice
      profits.append(profit)
      in_position = False

  • @Arivan_Abdulla
    @Arivan_Abdulla 2 місяці тому +2

    Thanks so much for the video man Very helpful

    • @Algovibes
      @Algovibes  2 місяці тому

      happy to read! Thx :-)

  • @traderjoe54
    @traderjoe54 2 місяці тому +2

    love your work, thanks

    • @Algovibes
      @Algovibes  2 місяці тому

      Love having you on board! thanks mate

  • @tr0wb3d3r5
    @tr0wb3d3r5 2 місяці тому +2

    The 🐐, ty a ton for the teachings💖

    • @Algovibes
      @Algovibes  2 місяці тому

      Thank you mate, nice comment 😆

  • @factoryofgaming5229
    @factoryofgaming5229 2 місяці тому

    I wrote my thesis in momentum trading strategies. I think this is an misrepresentation of the concept. Momentum in this form relies on a portfolio of stocks rather than a single asset, both long and short, making it self financing. This is open to broad market risk. Also, you conveniently pick a stock that we all know went up significantly over the backrest period. It would be nice to see this on a portfolio of say 20 equities, as by then you diversify much of the market risk away. Still, great video, but needs more depth.
    Edit: I was talking about cross sectional momentum. Apologies!

    • @Algovibes
      @Algovibes  2 місяці тому +1

      As you mentioned: Different story but I have great news for you - I covered cross-sectional momentum on my 9 hour Python for Finance course :-)
      If you need a free option its also covered in the Python for Finance playlist.