Introduction to Algorithmic Trading Using Python - How to Create & Test Trading Algorithm

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

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

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

    Excellent. I'm about to watch all the excel, python, and mysql videos on your channel. Great teacher.

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

    Great and Awesome video. Just created my first momentum strategy with python; and I look forward to creating more strategies using python. Very useful skill for the FinTech industry.

  • @swingtrader833
    @swingtrader833 3 года назад +4

    Thank you for this great tutorial! Liked and subscribed.
    I'm trying to learn python but trading tutorials that are any good are difficult to find, so your tutorials are very much appreciated.

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

      Thanks. Glad they are helping

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

    Really useful.Thank you for your sharing.Clear explanation and nice tutorial.

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

    the code is simple and beautiful. love it!

  • @VictorPérez-i8s
    @VictorPérez-i8s 6 месяцев назад

    this is excellent work! many thanks

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

    Informative tutorial. Thanks!

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

    Wow, this video was a game-changer for me! It made creating my own trading bot a breeze. Highly recommend it!
    Also, check out "Algorithmic Trading Tutorial Python | Build Trading Algorithm from Scratch" by QuantInsti - another awesome video that helped me understand the fundamentals of algorithmic trading and build my own algorithm. Super helpful and definitely worth watching!
    Big thanks to both videos for giving me the knowledge and confidence to create my trading bot. Can't wait to see what it can do! 😄🚀

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

      Glad it helped. I have a few others that work with a broker: ruclips.net/p/PLiPFKCVZWHKqtlvkq-V610SXMr2Ii9uAR

  • @SidhanthKumar-n5r
    @SidhanthKumar-n5r 10 месяцев назад

    This is awesome, thank you so much for sharing!

    • @MattMacarty
      @MattMacarty  10 месяцев назад

      Thanks. Glad it helped

  • @K-mk6pc
    @K-mk6pc 11 месяцев назад

    Thanks for the Insight sir.

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

    thanks for the vid! was looking for some help on testing system returns and this vid helped

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

    Nice video! ... thanks!

  • @PatrickBenitez6
    @PatrickBenitez6 10 месяцев назад +7

    Exceptional tutorial! I spent the past couple days researching how to calculate proper cumulative returns based on your short,long, hold signal strategy and luckily the YT algo brought your video to my home screen. Keep up the great work!

    • @MattMacarty
      @MattMacarty  10 месяцев назад

      Thank you. Glad it helped

  • @LeonardoZ-wq8vr
    @LeonardoZ-wq8vr 6 месяцев назад

    Can someone explain what's the difference between Buy/Hold (blue line) and System line (orange one) at 14:31?

    • @MattMacarty
      @MattMacarty  5 месяцев назад

      So the blue line shows what would happen if you bought in 2016 and just held gold without any adjustments. The orange line is what would have happened if you tried to catch the swings in prices based on a simple moving average.

  • @AleksOMFG
    @AleksOMFG 5 месяцев назад

    I can't get the data ( TypeError: string indices must be integers, not 'str' ) I tryied the override of yfinance but it doesn't work neither.

    • @MattMacarty
      @MattMacarty  5 месяцев назад

      Try using yfinance directly: yf.download(...)

    • @AleksOMFG
      @AleksOMFG 5 месяцев назад

      @@MattMacarty Just finished doing a program with tkinker with it thank you, Im new in coding. 😂 Great tutorial keep it up!!!

  • @munivoltarc
    @munivoltarc 5 месяцев назад

    Hi, try not to use price, lagging indicators, instead use price action strategy, will give accurate results, can you do this, many viewers are fed-up seeing these price lagging indicators usage in different channels of youtube.

    • @MattMacarty
      @MattMacarty  4 месяца назад +1

      This is for demonstrating how to write a simple back tester, not really interested in a strategy. Any strategy worth anything will not be found on RUclips.

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

    thankyou for the video @Matt Macarty, I didn't get the last part what is system return?

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

      With this simple strategy approach, you end up with a small loss over the test period (-6%).

  • @eddierosario1537
    @eddierosario1537 Месяц назад

    I wonder if you can use this on penny stocks?

    • @MattMacarty
      @MattMacarty  Месяц назад

      I mean the video is just to demonstrate some concepts, but if there is price action it shouldn't matter if it's a penny stock or not

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

    How can we get the Min and Max price dates from the 21 day's of previous High and low and to get the monthly high and low price and date and the difference between them in days and time/days ?

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

      I think probably the easiest way will be to start adding columns that track what you are looking for. If you just want to watch a max/min over a 21 day period, you can make a column something like df['21-max'].rolling(21).max(), etc.

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

    Sir, would like to ask. I thought if you're going to use the jupyter notebook, it doesn't need any internet and yet you can still use it . does using any API requires internet? complete newbie, still on learning process Sir.

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

      Some API's do require Internet. Typically if you are downloading data with an API is when you will need Internet.

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

    Great video, thank you a lot !!!
    I have a question for you Math if you don't mind of course about the trading algorithm in cryptocurrencies, my algorithm works pretty well using technical analysis RSI and CCI but I want to improve it using machine learning for merging technical analysis and fundamental analysis what can I do here? what kind of machine learning models or algorithms do I have to look at?
    my second question: I took a look at the holt winter method forecasting but I think this method will not work cause of the randomness of cryptocurrencies to change over time, is it true what I just said ? or this is a method for extracting trends and seasonality in any kind of time series

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

      Lots of people do use and try to use ML for trading algorithms. Securities are notoriously difficult to forecast (or else we would all be rich). For sure traditional time series forecasting models are pretty much useless unless you are using the model as a trading signal rather than as a forecasting tool. I think a good place to start is with Python for Finance, Hilpisch.

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

    Hi Sir. What is the setting of the blue line if I will use MA? 😊

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

      Do you mean you want the MA to be blue? You could use color = ‘b’

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

    Hello Matt, thanks for the video. I have a question, Why would you substract the returns to the system returns when your are not holding the asset, I mean when signal = -1 it reduces the system returns, but if you sold your position , the future price movement doesn't affect. Are you considered instead of multiply by -1 do it by 0?..

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

      Hi so the model assumes you are always invested, either long or short. The -1 indicates a short position. But yes if you wanted to go flat you could replace -1 with 0.

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

    great video, just wondering what AI technique did you use for this code

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

      Thanks. This one is pretty much straight forward technical indicators.

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

      @@MattMacarty ahh i see with machine learning used or neural networks at all? also what is the algorithm that is used for this? (sorry for so many questions)

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

      @@simonibra19 there's no neural networks here. This is a simple 21-9 MACD technical indicator strategy

  • @cybergrimreaper6669
    @cybergrimreaper6669 7 месяцев назад

    can i use this to trade XAUUSD?

    • @MattMacarty
      @MattMacarty  7 месяцев назад

      I would test to see how it does, and compare to various strategies. The video was meant to show people how to test strategies, not how to trade profitably

    • @cybergrimreaper6669
      @cybergrimreaper6669 7 месяцев назад

      @@MattMacarty ok sir,thank you for all the great content

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

    Hi Matt. Which software you use in order to program? I have TradeSation live data. How can i use? Thanks.

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

      I think you can use Python with many of the trading houses. I have Anaconda and a few other libraries that it doesn't come with.

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

    I have a problem in the Plot trades on time series. I can plot out all the things except the markers, it shows "ValueError: iLocation based boolean indexing cannot use an indexable as a mask"
    Please help

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

      Yes it sounds like you are trying to plot the wrong data. I would maybe creagte a separate Series based on your data mask and plot that.

  • @LamNguyen-nm1id
    @LamNguyen-nm1id Год назад

    i used a different set of data from 2021-02 to 2022-02 and upon comparing buy/hold with system, system outperforms buy/hold. what is your take on this?

    • @MattMacarty
      @MattMacarty  Год назад +2

      I am sure at times a system can outperform. The question is will the same conditions prevail in the future? And then how do you know that conditions are no longer favorable for the system? Obviously people do make money with algorithmic trading. My examples are meant to show you how construct fairly simple strategies to give you an idea of "how to".

    • @LamNguyen-nm1id
      @LamNguyen-nm1id Год назад

      @@MattMacarty that's very thoughtful thank you

  • @LamNguyen-nm1id
    @LamNguyen-nm1id Год назад

    hi, what is the idea behind plotting the mark on 9-day when entry is 2 and plotting the mark on 21-day when entry is -2? are they just for display meaning it should mean no harm if i were to plot the other day around? thank you

    • @LamNguyen-nm1id
      @LamNguyen-nm1id Год назад

      at the same time, what is the role of np.exp() here? i understand since the log return represent somewhat similar to pct_change, we should do cumprod() but i don't understand what np.exp is for, knowing that it is e**x for x to be the value of that index

    • @LamNguyen-nm1id
      @LamNguyen-nm1id Год назад

      at that*

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

      Sure you can plot on either as long as it intersects at a cross. I use the 9-day so you don't have to reverse your logic.

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

      You can arrive at the same numbers using either pct change or exp. exp is also known as instanaeous rate of return and computationally it's somewhat easier to work with than pct change. Instanteaous rate of return is used as the standard particularly when dealing with derivatives.

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

    can you make a video of how pandas performs the actual buy or sell orders ?

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

      HI. That functionality will be implemented by your trading platform. You want to find one that has an API that will allow you to integrate custom algorithms. It's not necessary to use Python though. Thinkorswim used to have a custom scripting language that let you write and run alogos but I am not sure if it still does.

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

    the short return is incorrect? if S_0 = 10 and S_1 = 11, based on your formula (LN(11) - LN(10))*(short signal -1) = -0.09531018, exp(-0.09531018) = 0.909090.
    whereas being short at 10 to 11, implies loss of (11 - 10)*(short signal -1) = -1, 9 dollars left implies 9 / 10 = 0.9 cumulative returns

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

      The return is based on the price movement for the day. If you are short and the price goes down, ignoring everything else, your position value increases by the amount the price decreased.

  • @sudzbyte2215
    @sudzbyte2215 Год назад +2

    Great vid, especially the reminder about shifting rows. Thanks!

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

      Glad it helped. Technically if you assume you update your models at the end of the day you could skip the row shift, but then you have to deal with price slip from close to open the next day.

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

    Nice video, thanks.
    A quick question - Why would you use numpy log to calculate returns? I reckon there is a more accurate pct_change() function that can be used directly. Also, numpy log also needs a diff..
    Also, could you explain how taking natural log (numpy log) and diff together end up coming close to the pct_change function result, which seems more intuitive for returns calculation?
    Update: Okay, it turned out that I didn't know about log returns till now. I went and did my homework :)
    But should we use log returns here when investment and returns are actually for discrete periods (1,2,3...n days)?

    • @MattMacarty
      @MattMacarty  3 года назад +4

      Glad it helped. You can use pandas pct_change function, but then you need to make other adjustments, so we typically use "instantaneous" rate of return. log, or LN change. This is used to make it easier to compare to other types of securities that compound interest continuously. It is also used to estimate volatility and in valuing options.

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

    wow simplemente gracias, he aprendido mucho con sus tutoriales, podría hacer un video sobre la gamma positiva y gamma negativa? saludos

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

    Great Tutorial! Thank you!

  • @juan-3350
    @juan-3350 3 года назад +1

    thank you for this. learned a lot!

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

    where can i get national stock exhange of india historical data

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

      From their website or you can buy your broker API Data if you want to use the data comercialy.

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

      You might try twelvedata or alphavantage, freeium APIs for global data.

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

      yes you can get it.i can help u out

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

    Hi, you explained very well, could you please make a video on price action kind of trading, not using lagging indicators, then it would be great to see your coding, and is it possible to do a multitime frame price action trading, if so please give the code.

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

      Thanks. You mean something like this? ruclips.net/video/YjONqP78HHw/видео.html

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

    Can you please explain the look ahead problem that we faced here!!

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

      So the data we are using implies that on the current day you know the closing price. This would not be possible until after the market has closed. I have seen it handled both ways, but you really can't get a signal until after the market closes and so it's unlikely that you would be able to act on any signal until the following day.

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

    How to Read a Binary File Like Metastock Files Using Python

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

      You can start with something like file = open([filename], 'rb'), then probably file.readlines(). And if each data point in a line is separated by a space or comma or anything you can you can split on the character.

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

      Thank you Mr.Macraty for reply, can you please explain it in a video?

  • @NeerajKumar-gk9kz
    @NeerajKumar-gk9kz 10 месяцев назад

    Plz make video trading in c+

    • @MattMacarty
      @MattMacarty  10 месяцев назад

      Sorry. I don't know the language!

  • @BLKDOLPHNDK
    @BLKDOLPHNDK 10 месяцев назад

    Python beginner thanks every tip helps

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

    thank you for the video . i think the look ahead is not a problem here if you take a decision at the end of the day . right ?
    I am creating a complex AI model and i am generating features depending on SMA and EMA . It would be important for me to know what is the best practice in this regard . i am taking decision at the end of each 1 hour candle .

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

      Yes if you can trade at the end of the day you wouldn't worry about look ahead. In practice, I guess you could assume a buy on close order, however since your model can't be updated until at least the exact close, it seems a little difficult to implement.

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

      @@MattMacarty thanks , i am taking a decision two minutes before the closing of each hour in cryptos market . I guess i shall not worry about the look ahead .

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

    Everything works great. Thanks for the soft

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

    Yahoo finance code doesn't work anymore?

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

      It should. Try pip install --upgrade pandas-datareader from the command line, then try running your code again. If that doesn't work try pip install yfinance. This will require you to modify the code to work with yfinance (yfinance.download)

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

      @@MattMacarty I figured it out in the end thanks tho

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

    Thank you for the video!

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

    Hi Matt, I am learning Python programming right now. Just started so to me everything is completely new. I would like to ask you, with all the knowledge you have, have you been able to trade using your own algorithm with Python? If so what were the results? I amorally motivated to learn this in order to be able to trade. I think is more precise then guessing using Candlestick reading. Nice content by the way, Thanks bro.

    • @MattMacarty
      @MattMacarty  2 года назад +4

      Thanks for your comment. Sadly, no I don't have an algorithm to share with you. There are a couple of websites out there that have communities sharing algorithms though. Sites like Quantopian were great for people like you. I don't have one to recommend, but do a little research and I am sure you will find what you are looking for.

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

    Thank you, boss.

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

    Hai..i have problem ..when i run my code there are some error like this
    NameError : name 'pdr' is not defined
    I already follow the instruction and also update to the anaconda prompt....but still can't.please help.

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

      Hi you can download the notebook from the link in the description. This is error means pdr has not been defined anywhere in your code. pdr is the alias I gave pandas_datareader in the first notebook cell. Maybe you have a typo?

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

      Ok sir...already get it...tq🙂

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

    Brilliant I'm falling off my chair. I tried TradeWindow etc now testing PlutoHQ Trading