Stock Market Analysis & Markowitz Efficient Frontier on Python | Python # 11

Поделиться
HTML-код
  • Опубликовано: 14 июн 2024
  • Let's reach 100K subscribers 👉🏻 l-ink.me/SubscribeBazzi
    📚About
    In Portfolio (or mean-variance) theory, the efficient frontier is a set of points (or portfolios) in which no other point achieves higher return given a certain risk. It is a spectrum that is closely related to the Markowitz Portfolio Optimization problem. In this lecture, and in an attempt of achieving the optimal portfolio in two different ways, we show how to plot the efficient frontier on a scatter plot containing different portfolios. This lecture is outlined as follows:
    ⏲Outline⏲
    00:00 Highlights
    00:23 Introduction
    01:41 Setting Jupyter Lab
    02:11 Pandas Datareader
    04:42 Reading Stocks
    06:04 Dataframe Concatenation
    07:25 Returns
    08:15 Log Returns
    09:18 Sharpe Ratio
    11:49 Log Asset Returns
    12:14 Volatility Per Portfolio
    13:02 Return vs Volatility Scatter Plot
    18:34 Sharpe Ratio Maximization (1st way)
    19:28 Scatter Plot: Returns vs Volatility
    22:01 Optimal Weights by Markowitz Portfolio Optimization (2nd way)
    28:00 Efficient Markowitz Frontier
    32:30 Important Message
    33:36 Outro
    Instructor: Dr. Ahmad Bazzi
    🏗️Material
    Browser: www.google.com/chrome/
    Jupyter: jupyter.org/
    Google: www.google.com/
    Pandas: pandas.pydata.org/
    DataReaders: pandas-datareader.readthedocs...
    MATPLOTLIB: matplotlib.org/
    datetime: docs.python.org/3/library/dat...
    SciPy: www.scipy.org/
    NumPy: numpy.or/gj
    📕 Related Lectures (Prerequisites)
    Pandas Tutorial: • Pandas Python Programm...
    NumPy Tutorial: • NumPy Linear Algebra |...
    Python Tutorial: • Python Programming in ...
    MATPLOTLIB Tutorial: • MATPLOTLIB in one vide...
    SciPy Tutorial: • SciPy Programming | Py...
    Stocks Programming: • Stock Market Analysis ...
    Markowitz Portfolio Optimization: • Stock Market Analysis ...
    📈 Related Stocks
    NASDAQ: www.nasdaq.com/
    CEVA: www.ceva-dsp.com/
    GOOGLE: www.google.com/
    Tesla: www.tesla.com/en_eu/models
    Zomedica: zomedica.com/
    🎵 Thanks freesound.org and Setuniman and all the users in this list for the following sounds I have used;
    freesound.org/people/Setunima...
    / ahmadbazzi
    🔴 Subscribe for more videos on Stock Market Analysis and Financial Analysis on Python.
    👍 Smash that like button, in case you find this tutorial useful.
    👁‍🗨 Speak up and comment, I am all ears.
    #PythonProgramming #Trading #Stocks

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

  • @vahidmoosavi3097
    @vahidmoosavi3097 2 года назад +22

    Great tutorial! A minor point: I think the formula you use for return is not correct. The ratio should be (p2-p1)/p1.

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

      I was waiting for someone to actually point it out. I'm pinning this comment for visibility.

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

      @@AhmadBazzi glad I didn’t disappoint you! ;)

    • @7vrda7
      @7vrda7 2 года назад

      Would that be: returns = (stocks.shift(1)- stocks) / stocks ?

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

      @@7vrda7 Yes I presume, or (stocks.shift(1)/stocks)-1

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

      BE CAREFUL, you can compute like that with stocks only because you don't have negative values or 0. If the initial value is negative, and the final value is more negative, then the return will be positive. In such a case, the positive return represents a loss rather than a profit. If the initial value is zero, then no return can be calculated.
      Ahmad, what you've done is not a problem at all, you can use Rlog=ln(Vf/Vi), also knows as force of interest.
      For example, if a stock is priced at 3.570 USD per share at the close on one day, and at 3.575 USD per share at the close the next day, then the logarithmic return is: ln(3.575/3.570) = 0.0014, or 0.14%.
      working with ln is good because you just have to divide by t to get the logarithmic rate of return : rlog=ln(Vf/Vi) / t.
      so Rlog = rlog*t under an assumption of reinvestment.
      For example, if the logarithmic return of a security per trading day is 0.14%, assuming 250 trading days in a year, then the annualized logarithmic rate of return is 0.14%/(1/250) = 0.14% x 250 = 35%

  • @wildabedolla7853
    @wildabedolla7853 3 года назад +161

    Convex Optimization guru !

  • @merylparmer3752
    @merylparmer3752 3 года назад +11

    I love how you put Python with this one 🙏🏻

  • @kamrynmiguel8455
    @kamrynmiguel8455 3 года назад +9

    Amazing lecture 👌🏻

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

    Ahmad, you are amazing!!! Great tutorial, thank you!

  • @7vrda7
    @7vrda7 2 года назад

    Nice job ! Thank you for the tutorial

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

    Excellent stuff with no BS 🙏🏻

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

      Thank you Elinor 🙏🏻

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

    Pure class. As always.

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

    underrated you are definitely

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

    Love your tutorials

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

    Great job as for sharing the lesson.

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

      My pleasure, Alberta 🙏🏻

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

    Excellent lecture, thanks for responding to my request.

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

      My pleasure .. Glad you enjoyed it :)

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

    I really love how you make lessons look more should be awarded prizes for that talent you got !

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

      Thank you very much, appreciate it

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

    Underrated ‼️

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

    This is really helpful for my situation right now, I will make some research and start right away, but do not know the amount for a startup now

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

    21:23 I love the colors of your frontier.

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

    5:34 awesome stuff man

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

      Glad you liked it, Darrin. For the meantime, make sure you subscribe to the channel here
      ruclips.net/user/AhmadBazzi

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

    I just shared it with my colleagues 👌🏻

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

      You ROCK, Jonathan 🙏🏻

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

    Perfect explanation 🤩

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

    Damn hes the best on RUclips

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

    Thanks Ahmad 👍🏻

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

      You're most welcome Bailey. Glad you liked it 🙏

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

    I love you and your lectures 📕❤️

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

      Make sure you like and subscribe to receive future notifications about the channel !!

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

    Love the highlights part, amazing visuals, thanks for sharing.

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

      I'm glad you found it useful !

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

    You just saved my ass.... thannk you !!!

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

    Such an underrated

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

      Glad you think so Sue. Make sure you subscribe to the channel here
      ruclips.net/user/AhmadBazzi

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

    thank you

  • @23yle
    @23yle 3 года назад

    Great session Mr can this be generalized to 5 or maybe 10 stocks?

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

    to get annual expected return you should multiply mean log returns by number of days in a year right? or, in that case, multiply it by the number of days in the period selected

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

    For the same set of stocks and same date range, I am getting a different set of sharpe ratio and different weights. I wonder what went wrong. I used both 'Close' and ''Adj Close', but both sharpe ratio (max) and weights are widely different. I wonder why?

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

    Thank you

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

      You're welcome Effie 🙏

  • @AdityaGupta-xg7ez
    @AdityaGupta-xg7ez Год назад

    Hi Ahmad , I hope you are doing well could you also please teach the code to integrate the plot SML , CAL , CML line on this very specific efficient frontier graph code tutorial you have provided , thank you so much in advance

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

    She's an expert trader, amazing professional

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

    Please create the series (and playlist) for the stock market analysis

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

      Excellent remark, Sam. I had the same idea and would definitely create this over the weekend. Stay tuned 🙏🏻

  • @zando3345
    @zando3345 11 месяцев назад

    It works also with short positions?

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

    @Ahmed I am having an issue where VS Code is saying there is a size limit. I have changed all file size and download columns to have no constraints but it will still not work. Do you have any suggestion on how I can. get this to work?

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

    when i hit shift+enter after entering the symbol its not showing any output. It just creates a different line.

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

    I've never heard or seen any of her clients complain of Lost....I think she's just too perfect

  • @johannariffle5585
    @johannariffle5585 3 года назад +11

    I love SKIPPY ❤️😍🥪

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

    .shift(1) shift to the back not the front right ?

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

    What if I want to do this without short selling constraints?

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

    Thank you for great work as usual! Skippy Peanut Butter should pay you for advertising.

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

      That's funny haha .. I should be thanking them for the great product !! Thanks for leaving a comment and subscribing to the channel. It is very much appreciated, Ragheb🙏

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

      They did of course @ragheb !

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

    Hi Ahmad, i am trying to use datareader in python but i am getting this error ''ModuleNotFoundError: No module named 'pandas_datareader' '' can you please help me?

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

    @2 the top for the sake of civilization, it’s better to focus on producing assets, things produced out of thin air that sucks up a lot of financial commitment isn’t good for us in the long run. I think that’s also part of his point too.

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

    i just needed some help please. For the sharpeRatio it keeps coming up as invalid syntax

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

    👍 thanks for watching👆👆👆

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

    Thank you Ahmad for this amazing lecture, I am using the same tickers and the date range but still I got different optimal weights. Can you please elaborate why this could be? I could not figure it out. thanks

    • @user-gv6gk8vd7h
      @user-gv6gk8vd7h 2 года назад

      You get different weights bacause our sharp ratios array is based on randomly generated portfolios from which we get one with maximum sharp ratio value, so result can be different running same code...

  • @2512greg
    @2512greg 2 года назад

    I don't know why but when i write this line of code :expectedReturn[k] = np.sum( meanLogRet = w ) i have this error : _sum_dispatcher() got an unexpected keyword argument 'meanLogRet' i have already install numpy i don't how to do it please can you help me ?

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

    Exactly unlike Tulip big corporations can transfer billions of dollars and only pay a few cents in fees compared to them transfering by bank and paying a huge fee. So bitcoin do have its utility.

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

    His argument could also refer to art, rolex, wine etc... it does not produce anything but prices are still going up

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

    Bitcoin is a as any other currency. Like gold or paper banknotes. They don't have a value on their own, but are important for trading. You can trade with Bitcoin and there are countries that legalised Bitcoin as offical currency alongside their own (you can buy for groceries with Bitcoin). I understand Warren's point of view, because he's right on principle. But I will still choose to have some Bitcoin as I will choose to have some paper banknotes ;)

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

    Got hungry after this one 🤤

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

      Have you some peanut butter !!

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

    That's true, most people today are seeing a lot of failures in forex and crypto sector due to poor orientations and bad experts.

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

    Please continue the MATLAB tutorial

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

    Can we do implement it on MATLAB ? Thanks

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

    where is the code for this project, thanks

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

    👍🏻

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

    is it the code available?

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

    Ok let me get some Peanut butter first! :) Can you make a video about the GameStop scandal?

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

      Haha, sounds like a great plan Leo !! I need to research more stuff about the incident, but definitely would consider it for future videos. Thanks for the great idea !!

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

    moudle not found

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

    The greatest investors of their time will of course defend their investment. After all they decide how much is your production worth and crypto is threating their power.

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

    Buffet doesn't understand. He's looking at it as gold. Gold never became a worldwide means of exchange. People stopped using gold and started using bank notes that listed the amount of gold they were worth (like checks).

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

    People of amsterdam made mistake with tulip in 17th century, and the same mistake is still in the making since then. Isnt it amazing....

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

    013

  •  Год назад

    2856

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

    Your fomular for computing returns is wrong. The correct way is "returns = (stocks - stocks.shift(1))/stocks.shift(1)"

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

    Because a lot of investors are confused about how the traders use their money

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

    457

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

    Please share with us the code thanks 🙌🏻

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

      I will not be providing code so that you could watch the entire series, run into errors, and report them here. I think that way we could all learn together and the community could help you further with upcoming errors.

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

    Trust me ,a couple of hours of reading is worth the opportunity that you might get. If you finished it and don’t buy the idea. I think you can now safely say that you know enough.

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

    It is normal to say, ,Bitcoin does not work as it affect his business

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

    I'm happy today because of Mrs Maria Jones

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

    +17

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

    I remember friends calling me crazy when I started but now I shut up them with my four figure weekly returned

  • @Manlikejj.__
    @Manlikejj.__ Год назад

    Buffett also said facebook stock is useless.

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

    Everybody does the same, governmentd, politicians .....

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

    Everythin is a vector

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

    She's honest, anyone can start investing now. What sap

  • @AkKa-sx6bz
    @AkKa-sx6bz Год назад

    What I've always thought about this scam

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

    He said the same thing about gold.

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

    Damn but you’re an electrical engineer, how on earth do you know finance ? 😲

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

      "Last night" XD ruclips.net/video/iRALBW4hBZ0/видео.html

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

    You can join our VIP offers,,

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

    Bitcoin has gone up 8.9 million percent while the dollar has dropped 50 percent. Which one is worthless?

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

    if buffet wont take your crypto, i wont take your crypto.

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

    Warren Buffett vs Michael Saylor discussion. 👍If you agree.

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

    What I don’t understand is why governments permit cryptocurrency to be used as a currency. If people think it’s valuable, then trade it like pork bellies or copper. But I thought governments want currencies to be transparent and stable, which crypto isn’t.

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

    But he has invested in a crypto exchange company ... Strange 🌸🌸🌸

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

    And then he bought…a lot!

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

    :)

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

    Wow I' m just shock someone mentioned expert Mrs Maria jonesthought I' m the only one trading with her

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

    I am having a laughing fit. Because multimillionaires don't know the value of Bitcoin and how to multiply it. When I listened to this conversation I was right when I said you don't invest in it you multiply it. And if you know what Bitcoin is for you can sell it right and multiply it right and it's all in a legal way. LMAO! I'm hysterical knowing that multimillionaires don't know that Bitcoin is worth millions if you know how to Buy it and sell it.... Interesting who knew the greats can't figure it out. See this is why you should be careful how you treat people because they will know how to do something you don't know how to do.

  • @user-vs6rl4tr7m
    @user-vs6rl4tr7m Год назад

    Tell me you don’t understand the value of decentralized currency in an age where your assets can be frozen for writing on the sidewalk with chalk…

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

    Says the guy who spinkles 1000's on his raisin bran.

  •  Год назад

    I really appreciate all your efforts for the 5btc you send to my wallet you really amaze me sir

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

    Cryptocurrency is a very good option if you would like to trade online.

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

    I can't make any sense out of bitcoin.

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

    *This message has been endorsed by the U.S federal reserve.”

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

    Imagine if he did for 5 years... Hahaha

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

    Every business on this planet is a pyramid scheme so I'm not sure what people mean by that. I don't expect to make the same amount of money as a new hire than the people who's been working in the same position more than 10 years or my boss. I don't think people understand the term Pyramid Scheme and what it means.

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

    no shit

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

    when he makes the pool of people analogy its not too people in the pool is over a billion.. warren buffet is as good as gary vee at chatting shit when it come to protecting there interest. neither care about your investments unless they are making your money!