Algorithmic Trading in Python - Simple Moving Averages & Optimization [Follow Up vid]

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

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

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

    No doubt the best youtube channel for python Algo trading , very practical and concise , good job

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

      Thank you for your kind words my friend :-)

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

    Great video, can you please tell me what IDE are you using in this video?
    Thanks.

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

      Thanks for watching and your comment :-)
      I am using Jupyter Notebook.

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

    your tester on 18.18 is it possible to show in more detail and expanded the code how to calculate optimization parameters in several columns at the same time TP, SL, TStop , TStep???
    this is the only and so important and the explanation is available! YOU ARE THE BEST !

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

      Thank you my friend ❤️ Also thanks for the suggestion!

  • @Bengt.S
    @Bengt.S Год назад +1

    Thanks a lot Algovibes for an excellent presentation! How can I get the number of buys and sells that is suggested?
    Actually how many times the position goes from 0 to 1 or vice versa?

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

      Welcome mate! Just browse the Python for Finance / Cryptobot playlist and look for SMA videos. I have covered basically everything around it including this one. Thanks and cheers!

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

    Didi I get it right that one can get hold of the actual script becoming a Tier-2 Channel member?

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

      Meanwhile it's Tier-3. Looking forward to welcome you as a channel member! :-)

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

    Thanks!

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

    Really appreciate these videos. Thank you. How did you get dark mode with Jupyter Notebook?

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

      Thank you mate. It's the Monokai theme from Jupyter themes.

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

    If I want to use it for an actual trading, do I just need to add a line of code to "create_order" in the definition of strategy? I'm very new to this area and your videos are excellent learning materials!

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

      Thank you mate. Well can you elaborate where in this video I am using create_order? :D

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

    You made a copy of the dataframe in Line 2 of strategy(). How would you call that original df, now, after naming the copy df as well?

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

      df is only defined locally (within the strategy function) so I see no problem here. But you can actually name it whatever you like in case you find this disturbing.

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

      @@Algovibes You mentioned it was a copy, which suggests the original can still be retrieved. I just wonder how you would retrieve the original given the code you showed in Line 2?

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

      (bump)

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

      @@markk4203 Yes, the original can still be retrieved with the globally defined variable df (e.g. print(df)). The changes to the data frame are only applied locally (within the function).

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

    do you have any more video on optimization ??? You have touched on an IMPORTANT TOPIC, optimization takes hours in the metatrader if you do it with a small step, stoploss, takeprofit, trailing, why so long, do you think? Maybe because of the built-in genetic algorithms?

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

      Pretty straightforward: I didn't work with Metatrader yet. Any suggestions what in particular you would be interested in?

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

    @Algovibes Any chance to create a grid strategy with python?

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

      Pretty cool idea. Not on my list right now but might indeed be an interesting thing to code.

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

    I am confused why in the performance function the buy and hold return changes when you change the SMA inputs. Isn't that a buy and hold over the same horizon independent of the SMA strategy? How are those related? Thanks

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

      Just due to the fact that some returns are getting cut off when the SMA changes as with a longer or shorter SMA period more oder less rows are getting dropped when applying the dropna function.

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

      @@Algovibes i think i see. So just the entry and exit positions are adjusted by the SMA used. I wonder if it's better to start the buy at t0 since the entry assumption is purely based on the SMA signal which a buy n hold strategy would completely ignore

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

      ​@@kptrzk9398 You can do that but if you do so you would have to go back t0 - SMA period for calculating the SMA strategy returns to really compare those strategies. We are basically doing that here and just cutting off the SMA period. I don't really see a benefit of not doing the cut off.

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

    One other question: how would you change color of the tick labels to stand out against the black background? Thanks!

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

      import matplotlib as mpl
      color = 'white'
      mpl.rcParams['text.color'] = color
      mpl.rcParams['axes.labelcolor'] = color
      mpl.rcParams['xtick.color'] = color
      mpl.rcParams['ytick.color'] = color
      Source: stackoverflow.com/questions/48958208/how-do-you-change-the-default-font-color-for-all-text-in-matplotlib

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

    Great video. Could you make machine learning video for similar optimisation?

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

      Thanks a ton Sahila,
      already got a lot of that stuff covered. Be invited to check out my Python for Finance playlist and the cryptobot playlist (and the Machine Learning playlist as well). Let me know if you need anything else and I am happy to cover that in future videos!

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

    Thanks alot. Especially the part where you present different MA pairs. Really appreciate it.

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

      Appreciate your comment! Credits for this one should go to Deepak Kanungo (Referenced in the video description).

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

      @@Algovibes Thanks again. Just wondering, I notice that your notebook has the timer (showed as -----100%------) when you run a cell, how do you enable it?

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

    Hey there, you have by far the most interesting yt channel out there for this topic!
    I am also getting into Python atm.
    I would have one question.
    Is it also possible to test „all“ possible combinations instead of just adding the value „5“ on both sides?
    I mean when I would have 1,2,3 and 11,12,13
    That I am not just testing
    1-11
    2-12
    3-13
    But also
    1-12
    1-13
    2-11
    2-13
    3-11
    3-12
    How would that look like?
    Thanks in advance :)
    Greetings from Augsburg

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

      Hi buddy,
      thanks a lot for your comment. Yep that's indeed an interesting question!
      I would probably solve it with a nested logic.

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

      Hi Philipp,
      If you have found out how to do this, could you share the code pls? I am also getting into Python atm and struggling to solve this. Thanks in advance.

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

    You have used ML for optimization strategies ???

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

      Played around with different ML stuff but wouldn't say I was "using" it for the purpose of optimization.

  • @mp-xt2rg
    @mp-xt2rg 2 года назад +1

    Aren't the realtime averages different than what's displayed on your historical charts since the future data isn't available yet? Have you tested your algorithms feeding the data in without it knowing what coming next?

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

      Hi man, that is covered in e.g. my cryptobot playlist. Be kindly invited to check that out.

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

    Hi Algovibes,
    Thanks a lot for sharing these tricks that we can do using Python in real life.
    I have one question- can you guide me, what could be the best possible way to identify if we have a growing SMA or a falling SMA on any particular stock using python??

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

      Hi man,
      welcome! :-)
      Can you elaborate on why do you want to check that?

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

      @@Algovibes actually the way you are back testing a strategy, I also want to back test one strategy and it requires to shortlist only those stocks which have rising SMA 200

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

    Isn't it better to calculate edge with stratret divided by ret? Is this because of the log? EDIT: Why is the return on just holding different every time?

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

      Return differs because of dropping another number of rows due to the rolling function. Hope this is answering your question!

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

    Great work!!! I didn't understand why buy and hold returns are changing.

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

      I figure out! It's because dropna after rolling method.

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

      Thanks for watching and your comment mate, you figured it out perfectly :-)

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

    Good afternoon. Please tell me why the 1 day timeframe was downloaded? and how to change your code to download 5 minutes

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

      Hi buddy,
      Covered other time intervals here:
      ruclips.net/video/BhOdgrxWi5c/видео.html

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

    Great video ...
    Bravo from Morocco

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

      Thank you my friend :-)
      Greetings to Morocco 🇲🇦

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

    Great video! However, when I include the drop NA I get different results than if I do the returns calculations in excel.

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

      Thanks a lot man. That's because when dropping the NaN row, you will also delete the row containing the return of that particular day.

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

    Thank you for the vid, I never tought about this ideia of multiplying the condition column * percentage change, good job !
    Greetings from Brazil

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

      No credits to me! I recently found this in an algorithmic trading course. The reference is in the video description! (Deepak Kanungo)

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

      Btw Greetings back to 🇧🇷:)

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

    Thank you for that video, but having problem with yfinance data downloading ''json.decoder.JSONDecodeError:'' Any thoughts how to fix it?

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

      Ok somehow fixed it in Jupiter, but got another issue.
      Error in def strategy
      ----> 7 df['position'] = np.where(df['SMA1'] > ['SMA2'], 1, 0)
      ValueError: ('Lengths must match to compare', (1265,), (1,))

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

      Whoever got that problem: Update yfinance. I had the same problem as well.
      There is something wrong with you SMA calculation. Please double check that. You are comparing 1265 rows to a single row right now.

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

    Not sure if I am correct, but seems there is a minor bug in the performance function, at which after taking exponential of the cumulative log return, we need to minus 1 before the actual cumulative return is returned. Otherwise the result will be incorrect and will always be a positve number, distorting the simulation result.

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

      It's not a bug. It's just what you want to have. If you want to have the amount where you want to multiply the invested amount with, you are taking my approach. If you want to have the actual performance (in %) you are subtracting a 1.
      Let me just give you an example:
      1999-01-22 NaN
      1999-01-25 1.104763
      1999-01-26 1.019049
      This is the return series using no -1 subtraction. To calculate your gain you just take the 1.019... and multiply it with your invested amount -> that's your "end" capital.
      But if you want to tell someone how much profit you made you say "Hey I made" 1.019... - 1-> 1.9% win"
      Makes sense to you?

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

      @@Algovibes Ok this makes sense. My comment was based on the fact that I was trying to derive the actual PnL, and therefore I need to -1. Thanks for prompt sharing ! :)

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

    the dataframe will be erased after turning off the computer and how to save the received stock date to the database on your computer so that later you can quickly load and process ?

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

      Can you elaborate? I don't see the coherence with the content in this video. Maybe I am getting you wrong.

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

      @@Algovibes Thanks! And everything is very simple, in this video you saved quotes to a dataframe in IDE, so I asked how to save quotes to a database on my computer maybe SQL or maybe you wrote a graphical application on PyQt5 for quick subsequent optimization of the strategy. And records in the database of optimization results.

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

    Thanks bro ,can u plz make one vedio on STC indicator ......i search all around but I cannot find out ...plz make one

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

      Thanks for watching and your comment :-) Appreciate it!
      Noted that but have some other stuff planned beforehand.

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

      @@Algovibes ok

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

    Great as always! :)

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

      Thank you my friend!

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

    clear, understandable, amazing videos from Algovibes , thx you very much

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

      Thank you my mate! :-)

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

    Thanks for the video, can you publish the source code?

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

      Thanks for watching :-)
      Source code will be published once I set up a website for that.

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

    hello video is not clear. please upload in higher resolution. currently it is 360p. thanks

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

      The Video is uploaded in HD but is still processing. It is unfortunate but there is nothing I can do about it. Please check again in some hours.

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

      Watching in 480 now and totally legible.

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

    interested combine and OPTIMIZE !!! TP, SL, TStop , TStep at the same time in one table as in this video 18 min 18 sec

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

      Is this for spot trading or futures trading?