Intraday Trading Strategy in Python [Trend following] incl. 1 month Backtest

Поделиться
HTML-код
  • Опубликовано: 20 дек 2024

Комментарии • 94

  • @Algovibes
    @Algovibes  3 года назад +3

    Hi everyone,
    thanks for watching.
    if you want to see how those kind of strategies can be implemented in live real money trading be kindly invited to check out my video:
    ruclips.net/video/rc_Y6rdBqXM/видео.html

  • @kyle_bro
    @kyle_bro 3 года назад +10

    I had to stop everything I was doing to watch this because I already know it's going to be awesome

    • @Algovibes
      @Algovibes  3 года назад +1

      What a legendary comment :-D Thanks for that and also thanks everyone liking the comment. Really appreciate it.

  • @HimanshuSharma-bz2gh
    @HimanshuSharma-bz2gh 3 года назад +1

    Duuuuuuude! Awesome job! Keep it up!!

    • @Algovibes
      @Algovibes  3 года назад

      Thanks a lot buddy. Appreciate your kind words :-)

  • @haidar901
    @haidar901 3 года назад +1

    Thank you very much, I hope more to come ! All Love and stay safe

    • @Algovibes
      @Algovibes  3 года назад

      Thank YOU for watching and your kind words.
      Love ❤️ back and you stay safe as well please!

  • @PavelSumik
    @PavelSumik 3 года назад +2

    absolutely great work , you are better and better, thx much, I am very interested in these trading techniques and backtesting

    • @Algovibes
      @Algovibes  3 года назад

      Thank you so much :-)

  • @User66866
    @User66866 3 года назад +1

    Like intraday strategy videos a lot! Thank you for sharing!

    • @Algovibes
      @Algovibes  3 года назад

      Thank YOU for watching and commenting :-)

  • @jitkadyan
    @jitkadyan 3 года назад +3

    Superb video again

    • @Algovibes
      @Algovibes  3 года назад

      Thank you very much :-)

  • @ivang4678
    @ivang4678 3 года назад +2

    I'm trying to learn Python for backtesting strats and although this is a bit advanced for my level right now (I started from 0 a few weeks ago), it's explained in an extremely clear and eloquent fashion. Would you recommend any other material on this exact topic? Thanks and keep up the amazing work!

    • @Algovibes
      @Algovibes  3 года назад +1

      Hi, thanks a lot for your comment! I personally learned a lot through university/internships but can also recommend Sentdex - a RUclips legend with incredible resources on his channel.

    • @ne2ve2
      @ne2ve2 3 года назад

      Well, you can learn Python from different sources. I've learned its basics from Coursera and Datacamp. It won't be enough by itself though, you should practice everything you've learned in different scenarios be it a web scraping program that crawls through a huge website or simple pandas dataframe analytics.
      You could also practice R for a bit, it has a similar to pandas behavior.
      If you're just starting coding, language shouldn't be that much of a difficulty, on the other hand your problem solving skill would be put to a real test.
      Btw you probably shouldn't even touch other people's code until you have a firm understanding of what's going on.

  • @amanchaure5584
    @amanchaure5584 2 года назад +2

    I have back-tested this code with the intraday data of 30+ indian stocks for the last 8 years and these are the results,
    On an average the strategy works well till 2017,
    The strategy has a 8 to 10% engagement rate per year, the returns are 5 to 6%.. which is really very good. (No. of trading days are 15 to 20 only, per year).
    So the capital is engaged for a very less time during any given year and the returns are 5 to 6%.
    But after 2017..,
    The strategy doesn't perform well. The overall returns in most of the cases are negative.. (-6 to -8%)
    This is a living proof of the fact that you can't rely on a very few strategies for eternity. Sooner or later, a lot of people will try to trade them in a very similar fashion, which will lead to mean reversion of the strategy returns.

  • @sz8558
    @sz8558 3 года назад +1

    Excellent tutorial as usual...Would be awesome to see such a strategy run for say 4weeks, and to see and analyse the daily performance with something like the pyfolio package.

  • @durgeshsinghkushwaha6815
    @durgeshsinghkushwaha6815 3 года назад +1

    Master of algo trading..

    • @Algovibes
      @Algovibes  3 года назад

      Far away from that but I am working on it 😛 Thanks for your comment tho, appreciate it :-)

  • @Asparuh.Emilov
    @Asparuh.Emilov 2 года назад +1

    I love your videos! You are so explicit, so accurate and very much comprehensive! Totally learning a lot from you bro! Thank you so much! ♥️♥️♥️

    • @Algovibes
      @Algovibes  2 года назад +1

      Really appreciate your comment and your positive attitude. Thank you so much!

  • @Anzeljaeg
    @Anzeljaeg 3 года назад +1

    Anohet thank commen , dude you rock

  • @juuttuub
    @juuttuub 3 года назад +1

    This is great. Could you show in some videos, how to iterate and find solid entry and exit values and show the statistics?

    • @Algovibes
      @Algovibes  3 года назад

      Thanks a lot for watching and your comment :-) Appreciate it. I will see what I can do! Thanks a bunch for the suggestion. Always helps me!

  • @russskinner5715
    @russskinner5715 3 года назад +1

    Another excellent video.

    • @Algovibes
      @Algovibes  3 года назад

      Thank you so much! 😊

  • @assafcohen3173
    @assafcohen3173 3 года назад +1

    Hi, this is great and thank you for creating this video. The main thing that is missing for me here is how to implement this so it runs in real time? right now we're just looking back and checking "what if...", but how would you go about making this live?

    • @Algovibes
      @Algovibes  3 года назад

      Hi mate,
      Among others I am using these strategies in my cryptobots in live trading. Be invited to check out the cryptobot playlist.

  • @rraul
    @rraul 3 года назад +1

    You are awesome, man! Thanks. Based on your momentum video i have finded a great strategy to profit in brazilian market.

    • @Algovibes
      @Algovibes  3 года назад +1

      No, u are for supporting me :-) That's really great to hear! Thank you very much for watching.

  • @fx2gbg596
    @fx2gbg596 2 года назад +1

    can you also test the opening range breakout strat in python

    • @Algovibes
      @Algovibes  2 года назад

      Thanks for the suggestion man!

  • @lhsok
    @lhsok 2 года назад +1

    Great video. I got a problem executing the code. My code is stuck at cumulated [buytime:], the notification suggests the timestamp cant be calculated with the numerical operator. can anyone help me out?

    • @Algovibes
      @Algovibes  2 года назад

      Hi man, thanks a lot.
      did you somewhere deviate from my code?
      If not can you provide me a timestamp where you are struggling?

  • @RafeedChowdhury
    @RafeedChowdhury 3 года назад +1

    Great video as usual! This code is good for backtesting. Can you make a video about london breakout trading strategy?

    • @Algovibes
      @Algovibes  3 года назад +1

      Awesome suggestion. Noted that. Thank you very much for watching! :-)

  • @jitkadyan
    @jitkadyan 3 года назад +1

    sir can we use sqlite in this scanner for fast getting results.

    • @Algovibes
      @Algovibes  3 года назад +1

      Yes sure. If you are scanning a huge amount of assets I would even recommend a more efficient solution than scraping.

    • @markk4203
      @markk4203 3 года назад

      @@Algovibes This may or may not be related but I'm going to ask here. I'm still confused as to where/when use of a database can expedite the backtesting process. I'm looking to get roughly 20 years of EOD data and then use that to study for the next year or so. I don't need to update it or maintain it after I get it. What's the difference between reading those daily .csv files in vs. creating a database after which I would then--have to import the database to dataframes? Read the database directly without need for dataframes? I don't know. And--if the database route is best with regard to speed, then can you explain how that is accomplished? Thanks!

  • @hsider
    @hsider 3 года назад +1

    Amazing work dude. The strategy gives me tiny results since it doesn't account for the down trend.

    • @Algovibes
      @Algovibes  3 года назад +1

      Thanks a lot for your appreciative comment. Yes you are absolutely right! One should account for that.
      I am actually applying a similar strategy in one of my crypto videos where I am accounting for counter movements. Be kindly invited to check that out and let me know what you think:
      ruclips.net/video/rc_Y6rdBqXM/видео.html

    • @hsider
      @hsider 3 года назад

      @@AlgovibesI will definitely see it, I've already checked a bunch of your videos. I wanted to add that, yahoo finance has new limits on data windows, your trick didn't work and may be will never do.

  • @manishagarwal8737
    @manishagarwal8737 3 года назад +1

    Really Amazing ! Can you guide us how we can use this in the live market. Do we just need to update the dates ? I mean I want a BUY or SELL signal based on the parameters I have defined in the real time market. How can I do that?
    Thanks in advance!

    • @Algovibes
      @Algovibes  3 года назад

      Thank you very much for watching and your comment. Appreciate it :-)
      I recently uploaded a video where I am doing that with cryptocurrencies using live data and store that in a SQL database.
      Be kindly invited to check that out:
      ruclips.net/video/rc_Y6rdBqXM/видео.html
      There will be videos on live trading stocks as well in the future. Before that I will do some technical analysis with cryptos using real time data.

    • @manishagarwal8737
      @manishagarwal8737 3 года назад

      @@Algovibes can you share your email id please ?

    • @Algovibes
      @Algovibes  3 года назад

      @@manishagarwal8737 I will in the upcoming weeks in the about page on my channel. Thanks for your patience.

  • @aravindakshans6998
    @aravindakshans6998 3 года назад +1

    it would be great if you could put up a multi time Frame intraday strategy

    • @Algovibes
      @Algovibes  3 года назад

      Thanks for the suggestion! :-) Really appreciate it and would be indeed quite interesting.

  • @QuanttradingVega
    @QuanttradingVega 3 года назад +1

    Hey brother i have been checking your channel since past few days , can you please tell me from where should i start learning python programming .

    • @Algovibes
      @Algovibes  3 года назад

      Hi mate, very glad to have you onboard! :-) You are kindly invited to check out my Python Introduction playlist if you like. In general there are a lot of beginner tutorials here on RUclips - number one for me personally is Sentdex.
      I personally learned the basics in university - so I have no good first hand reference. For starting out I can also recommend DataCamp.

    • @QuanttradingVega
      @QuanttradingVega 3 года назад +1

      @@Algovibes okay thanks man

  • @Simone-vd1ps
    @Simone-vd1ps 4 месяца назад +1

    Is it possible to backtest intraday data older than 60 days in python?

    • @Algovibes
      @Algovibes  4 месяца назад

      Yes it is! I am showing in some video how you can do that with database storage.

    • @Simone-vd1ps
      @Simone-vd1ps 3 месяца назад

      @@Algovibes Do you mind telling me which video in particular? Thanks for your response.

  • @jitkadyan
    @jitkadyan 3 года назад +1

    sir create a video of creating scanner using Talib technical indicator liabrary, how we get result faster from getting live data from api.

    • @Algovibes
      @Algovibes  3 года назад

      Awesome suggestion! Thank you very much :-)

  • @SP-db6sh
    @SP-db6sh 3 года назад +1

    Next topic can be, Process to build & optimize a swing trading strategy through FinRL platform for implemention of DRL on trading.

    • @Algovibes
      @Algovibes  3 года назад +1

      Well I actually planned to do a tutorial on solving the Riemann Hypothesis beforehand and after that tell James Simons on how he should improve his portfolio structure ;-)
      No my friend, I am just kidding. (Deep) Reinforcement learning will not be covered at least in the near future. To give you realistic expectations - topics on my list are among others:
      - Implementation of trading strategies in Python (and maybe R) like initial move reversal, momentum in the Indian stock market, stock recommender system (based on technical indicators) and so on but ALSO some DL stuff like LSTM.
      - basic tutorials in R / Python / SQL / Pandas / Numpy / Sklearn / Julia
      - (basic) machine learning tutorials
      - some cryptocurrency trading stuff
      - Things I find interesting
      - Deployment stuff and actually going live with some trading strategies with real money
      - Stocks in general / stock market analysis in Python
      NEVERTHELESS thank you so much for sharing FinRL. I never heard it before and it is an absolutely incredible library from what I have just read. I will definitely have a closer look to that!
      Always be kindly invited to make suggestions. I didn't mean to turn you down, just want to give you realistic expectations. I am very thankful for your suggestions so far :-)
      A lot of text but I found this important to clarify.
      Best regards

    • @SP-db6sh
      @SP-db6sh 3 года назад +1

      @@Algovibes Can you mention someone working on DRL implementation on trading perspective ?

    • @Algovibes
      @Algovibes  3 года назад

      @@SP-db6sh Unfortunately not on trading but the channel 'Machine Learning with Phil' has great content on Deep Q Learning. He also has courses and seems like a nice guy. Can recommend him definitely!

  • @sofienesdiri8470
    @sofienesdiri8470 3 года назад +1

    Can we apply this strategy on crypto?

    • @Algovibes
      @Algovibes  3 года назад +1

      Thank you very much for watching and your comment. Yes, this is also applicable to cryptos. There will be some crypto trading coverage as I am doing that myself in the near future. Thanks for your patience :-)

    • @sofienesdiri8470
      @sofienesdiri8470 3 года назад +1

      @@Algovibes i appreciate your work

  • @jackgisel3211
    @jackgisel3211 3 года назад

    Could you show us how to work with real time data? I am confused how to take the code from these videos and apply them to live trading data from a WebSocket

    • @Algovibes
      @Algovibes  3 года назад

      First of all thanks a lot for watching and your question!
      You are absolutely right. The videos are field tests and the main objective is to construct and backtest trading ideas with the help of (python) programming.
      Nevertheless I am happy to announce going live with a trading strategy will be covered in this channel within this year. Thanks for your patience.

  • @KonguNaadu
    @KonguNaadu Год назад +1

    Could you give a python code for my strategy for fee ?

    • @Algovibes
      @Algovibes  Год назад

      No but you can send me the strategy per mail and if it is interesting enough I am happy to cover it in one of my future videos.

  • @cbritton27
    @cbritton27 3 года назад

    I had issues with this line:
    exit_price = df.loc[exit_time + dt.timedelta(minutes=1)].Open
    For PENN on March 1, there is no next 1 minute time interval, so I was getting a indexer error. Not sure why yf was missing this data. Either have to search for the next available interval or use the close of the current bar.

    • @Algovibes
      @Algovibes  3 года назад

      Are you really sure? I just tested it and there is data for March 1st. I had to take 5 minute intervals as first march is now too far in the past for the 1 minute intervals. But yes as you already suggested one could also just take the next row. Might be even better. Thanks a lot for sharing!

    • @cbritton27
      @cbritton27 3 года назад

      @@Algovibes Yes, it happened for several tickers, not just PENN. But then, this is yahoo finance, so not the most reliable data source.

    • @markk4203
      @markk4203 3 года назад

      @@Algovibes ​ Are 5m and longer intraday intervals available on yf more than one month back?

  • @meetshah4800
    @meetshah4800 2 года назад +1

    How to backtest 1 min data of indices over last 5 years??

    • @Algovibes
      @Algovibes  2 года назад +1

      I have covered that in this video:
      ruclips.net/video/HB1CLz0Z1NY/видео.html
      It is on cryptos but maybe you will find something of value there as well!

    • @meetshah4800
      @meetshah4800 2 года назад

      @@Algovibes What should be changed as per video in code for Banknifty indices??

    • @meetshah4800
      @meetshah4800 2 года назад

      For stock market

  • @apurvaparekh9364
    @apurvaparekh9364 3 года назад +1

    great video, just came on my time line somehow. thanks for the simple explanation. do you have an email ID where I can reach out to you to get some doubts cleared for a similar strategy am trying to code ? cheers and god bless.

    • @Algovibes
      @Algovibes  3 года назад

      Hey mate, thanks a lot for your kind comment :-)
      Unfortunately I don't have a RUclips related mail yet but I will provide one in the about me section very soon.

  • @boomerz2478
    @boomerz2478 2 года назад +1

    All of your videos make the (understandable) German mistake that all markets and activity are rational and can be understood with logic and reason. This is true maybe 80-90% of the time but that 10-20% can really fuck you over if you have no way to adjust or control for it which you never seem to do. And that small percent can wipe out all of someone’s gains.

    • @Algovibes
      @Algovibes  2 года назад

      Wait. Wasn't it the Americans who crashed our finance system and not the germans? 😛

  • @siddharthterse8563
    @siddharthterse8563 3 года назад +1

    Hi Algovibes, Can you please share your email ID please, for enquiry ? if you are interested in project related with your skills ?

    • @Algovibes
      @Algovibes  3 года назад

      Hi and thank you very much for the request. Appreciate it. I will add an email in the upcoming weeks in the about me page.

  • @tayaamme9954
    @tayaamme9954 2 года назад +1

    Hi Algovibes,
    Thank you very much for all the helpful videos you make.
    I am trying to backtest a strategy where the asset is sold when my tp percentage is met or when the chart goes for example 1 bar in the other direction. And then I want to convert the trade to a trade in the other direction. I've tried this code, but it only calculates the first exit. I also tried the code from the video ruclips.net/video/rc_Y6rdBqXM/видео.html but it also doesn't work the way I want. I modified the codes to my liking, but unfortunately it still doesn't work the way I want. I've been searching for the right code or combination of code for several days now. I also watched all your videos in the Python for Finance playlist.
    What could I change in one of your codes to get this working? I hope you have time to help.
    Thanks again.

    • @Algovibes
      @Algovibes  2 года назад +1

      Thanks a lot Taya,
      well I can't tell. But let me tell you it is nothing unusual to come across things not working. To figure out why it doesn't work can take days or even weeks. Just try to understand why it doesn't work and try to slice the problem in as small chunks as possible.

    • @tayaamme9954
      @tayaamme9954 2 года назад

      @@Algovibes Thanks for the reply. It's so frustrating sometimes when something doesn't work out and when you've been doing it for so long. I solved the problem for now by adding extra columns with new conditions. We are now testing and fine-tuning the strategy. If this is a profitable strategy, we are happy to share it with you.
      Your videos are really helpful, thanks again for all you do.