Markowitz Portfolio Solver from Scratch and Stock Market Analysis | Python # 17

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

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

  • @charlenestanton2237
    @charlenestanton2237 3 года назад +52

    You have explained in less than 50 minutes what my lecturer struggled to explain in 3 months. Thank you!

  • @leahprice1161
    @leahprice1161 3 года назад +153

    This lecture slaps harder than my dads belt.

  • @daveframi5715
    @daveframi5715 3 года назад +56

    *The following content is created under an intellectual property license* Never have I ever seen such perfect and clear explanations.

  • @frankfernandez6424
    @frankfernandez6424 3 года назад +59

    Wow now I can use your equation to do my own solver. Thanks.

  • @louisrobertson3698
    @louisrobertson3698 3 года назад +50

    This lecture will make your pocket rocket 🚀

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

      It sure did pocket made 5K USD yesterday thanks to this opt problem.

  • @karliefarrell6710
    @karliefarrell6710 3 года назад +61

    Mesmerizing insights and its for free!!.. Good job Ahmad !

  • @joelmarshall4989
    @joelmarshall4989 3 года назад +44

    I love the math flow starting at 06:40 
Thanks a lot Ahmad !

  • @aishahoura2619
    @aishahoura2619 3 года назад +34

    00:00​ Introduction
    00:47​ Markowitz Portfolio Optimization Problem (a recap)
    03:08​ Lagrangian Function
    05:38​ Optimal Weights
    11:11​ Lagrangian Multiplier Solutions
    21:35​ Our Portfolio Solver Equation
    22:17​ Python Implementation: SciPy approach (method 1)
    33:36​ Python Implementation: Our Solver (method 2)
    37:28​ Comparisons: SciPy Solver vs Our Solver
    41:00​ Summary
    41:40​ Outro

  • @elisabethgraham866
    @elisabethgraham866 3 года назад +218

    Funny. I understood most by a guy that does not look like people from Goldman Sachs

  • @thomasyonsy3261
    @thomasyonsy3261 3 года назад +7

    Suppose two portfolios A and B have an expected return of 10% each. But A’s risk is 8% while that of B is 12%. Looking at these two portfolios you would think, both give the same returns, but A has lower risk, I’ll buy A. But if you’re adventurous, you’d say portfolio A can return between 2% and 18%, while B can give between -2% and 22%. You might choose B. Portfolio B offers a chance of getting 22% return but there’s also the possibility that instead of making gains, you might end up losing money. The additional return is compensation for additional risk. Hence the notion, the higher the risk the higher the return. How do you make an optimal portfolio? By selecting the right combination of assets. If two assets are similar, then their prices will move in a similar pattern. Say, two Exchange Traded funds or ETFs from the same economic sector tend to show similar price movement, while, ETFs from different sectors show dissimilar price movements, as they lack correlation, making them a suitable set of eggs for your basket. Correlation is measured on a scale of -1 to +1. +1 indicates positive correlation where prices of two assets move par-for-par, while -1 shows negative correlation; prices move in opposite direction. If you put two assets with correlation of +1 in a portfolio, the risk they bring to portfolio will be the sum of the weighed risk of individual assets. However, if you put a pair of assets with correlation of less than 1, then the risk of the resulting portfolio will be less than the sum of the weighed risk of individual assets. By selecting different asset combinations you can achieve every risk to return combination in a portfolio. And this brings us to the efficient frontier, which is a graphical representation of different combinations of assets to achieve an optimal level of return at any given level of Risk. With risk on X-axis and return on Y-axis, this hyperbola shows all outcomes for various portfolio combinations of risky assets. This Straight Line is the Capital Allocation Line, which represents a portfolio of all risky assets and the risk-free asset, like government bonds. Tangency Portfolio is the point where the portfolio of risky assets meets the combination of risky and risk-free assets. And this portfolio maximizes return for a given level of risk. As you move towards the right along the lower part of the hyperbola you get lower returns at higher risk. Do the same along the upper part and you get higher returns at higher risk. The take away is that an asset's risk and return should not be assessed by itself, but by how it contributes to a portfolio's overall risk and return. We utilize Modern Portfolio Theory in our module 1, which has allowed us to achieve such returns…

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

    Oh my GOSHHH. I am going to watch this so many times. Bravo. The illustrations, the simplicity, the speed of speech, the examples.

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

      Wow glad you think so Belle !

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

    This video sums up what took me about 4 years of gradual self learning to know in only 42 minutes!

  • @cozmatitradulf7012
    @cozmatitradulf7012 2 года назад +23

    Al Khawarizmi re-incarnated !

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

    I have so much respect for how a good explainer you are. This video is amazing. Very clear, structured and most importanty calm (good comfort for ones who find these processes taunting already).

  • @ДенисКожин-е5ш
    @ДенисКожин-е5ш 2 года назад +1

    Clear lecture. Disclaimer: No student debt was created during the watching of this video.

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

    Your explanation makes it much easier to understand. Thanks

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

    I have never seen anybody teach so clearly

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

    In finance, the Markowitz model - put forward by Harry Markowitz in 1952 - is a portfolio optimization model; it assists in the selection of the most efficient portfolio by analyzing various possible portfolios of the given securities. Here, by choosing securities that do not 'move' exactly together, the HM model shows investors how to reduce their risk. The HM model is also called mean-variance model due to the fact that it is based on expected returns (mean) and the standard deviation (variance) of the various portfolios. It is foundational to Modern portfolio theory.

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

    MPT which is Modern Portfolio Theory considers how an investor should choose a portfolio with a good trade-off between risk and expected return. Markowitz showed that the set of possible expected returns and risks.

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

    This man is amazing.. very knowledgeable & good at explaining. Well done RUclips for recommending me here.

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

    I think one needs to be a genius in order to be able to explain such an incredibly complex thing in such a beautifully simple way.

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

    Brilliantly articulated multiple concepts within limited time, Thank you.

  • @gurhan_aydn-edits8661
    @gurhan_aydn-edits8661 3 года назад +1

    Thanks alot sir I really do appreciate your help with this video, I started off in this market not seeing the results I expected

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

    you explained it as simple as possible.. thanks

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

    A brilliant explanation of MPT. Wish I had come across this sooner. Thank you !

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

    I swear I’ve learnt more during this quarantine than all the years I was in school 🙌🏽 I’m a new person now lol

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

      Wow that is awesome. Keep up the RUclips learning Emily. RUclips is a very rich source where you could learn almost anything.

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

    This was extremely helpful and needed. Thank you so much.

  • @БеняКузин
    @БеняКузин 2 года назад

    Oh my GOSHHH. I am going to watch this so many times

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

    Portfolio management can be painful because it's all about making decisions about investment mix and policy, matching investments to objectives, asset allocation for individuals and institutions, minimising risk while keeping good returns and balancing risk against performance and not everyone could handle this successfully. Ahmad did an excellent job in clarifying all concepts jointly.

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

    Thank you very much Ahmad !

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

    Learnt more in this four lecture than in the 4 months in class ✌🏻

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

    Definitely will add this to my playlist for later! 🤙

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

    Great lecture, well done! I do have a question, for the Lagrangian function, with only a handful stocks, it suggests negative weights. Is there a way to set a constraint for long only approach? Appreciated much.

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

      Hi! I have also faced the same problem. Were you able to fix it?

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

    Amazing video needs to be shown in universities thank you for the development of this video.

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

    28:45 Thanks for showing me how to use scipy minimize function. Always had troubles with it.

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

    This video is very clear!

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

    AMAZING AHMAD !

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

    I wish my Professors approach their lectures like this.

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

    Very nicely explained. Great !!!!

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

    The Markowitz solution can easily find highly leveraged portfolios (large long positions in a subset of investable assets financed by large short positions in another subset of assets)

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

    Your content is freaking awesome

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

      I am happy that you find it awesome

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

    Love the part about making money from mathematical Convex Optimization.

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

    great teacher really helped, thanks

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

    Wow! It should have been atleast 3 hours. Tuned me in like a netflix show.

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

    Best lecture on planet earth

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

    Интересно, спасибо за видео)

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

    Интересная информация, благодарю за нее

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

    The Efficient Frontier takes a portfolio of investments and optimizes the expected return in regards to the risk. That is to find the optimal return for a risk.

  •  3 года назад

    You're a boss. This video changed my life

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

    YEAH, QUARANTINE VIDSSSSSS 2021 !!

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

    How to determine the optimal asset weights for a risky portfolio and how to allocate a portfolio between the optimal risky portfolio and the risk-free asset ?

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

      It is the w vector derived and implemented in the video.

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

    A solver using 7 lines of python code at 37:22 got me going nuts ! How did you do that Ahmad !?

  • @Faruk.00
    @Faruk.00 3 года назад

    As investopedia points out, it assumes that asset returns follow a normal distribution, but in reality returns can be more the 3 standard deviations away. Also, the theory builds upon that investors are rational in their investment, which is by most considered a flawed assumption, as more factors play into the investments.

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

    Gem of a lecture thank you

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

      Glad you think so, Gretta ! I'm very happy for you

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

    I coded one myself, but for mutual funds. This would help if you extended this functionality for that cause.

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

      It could definitely be extended and applied to hedge fund analysis.

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

    Hi Ahmad. Just one question, if we get w = [0.2, 0.3, 0.4, 0.1], does that mean we have 20% in the first stock, 30% in the second, 40% in the third, and 10% in the final stock. It all sums up to 100% ? Thank you for awesome lecture.

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

    An excellent video with useful information.

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

    Brilliant explanation

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

    Great lecture from UCLA USA

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

      Thanks and welcome. Pleasure it is !

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

    The Markowitz Portfolio Theory is no other than a combination of assets, i.e. a portfolio, is referred to as "efficient" if it has the best possible expected level of return for its level of risk usually proxied by the standard deviation of the portfolio's return

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

    VERY GOOD explanation...

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

    Now I think I’d like to see a video on Gold’s role in “Deleveraging”

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

    it was very helpful. Thanks a lot!

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

    Nice explanation, thanks for sharing

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

    Altyazılar için teşekkürler

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

    thank you so much for this clear explanation

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

    A portfolio that gives maximum return for a given risk, or minimum risk for given return is an efficient portfolio. Thus, portfolios are selected as follows:(a) From the portfolios that have the same return, the investor will prefer the portfolio with lower risk, and (b) From the portfolios that have the same risk level, an investor will prefer the portfolio with higher rate of return.

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

    Great presentation skills.

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

    Underrated GURU !

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

    great! please upload more videos about portfolio theory

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

    Excellent professor!!!!!!!

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

    You are a genius. Thank you sir.

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

    Thanks Ahmad !

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

    @Mallie Bayes, yes increasing

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

    incredible! thank you

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

    I always thought of Markowitz efficient frontier as a parabola where the optimal values lie along the upper half of the parabola line. Anyways, the Efficient Frontier gives you a way to balance your portfolio.

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

    29:21 Wow, never knew we could model the cost function as a python function

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

    Informative tutorial.

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

    Portfolios that cluster to the right of the efficient frontier are also sub-optimal, because they have a higher level of risk for the defined rate of return

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

    29:52 Sir, is the bounds necessary because it not part of the optimization problem.

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

    Please help with this problem I have homework An investor wants to put together a portfolio consisting of up to 5 stocks. Using the Markowitz method, what is the best combination of stocks to minimize risk for a given return? In this model, we calculate stock returns, the variance of each stock, and the covariances between stocks, using the Excel functions AVERAGE, VARP and COVAR.

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

    Is it possible to have zero weight in a particular stock in Markowitz portfolio optimization ? Zero weight implies that nobody wants it which will actually lead to decrease in price, however it is not feasible.

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

    How do you work out the optimization problem using Langrange?

  • @ЕвгенийКрасилов-о9о

    It's an awesome video, but... Our optimization problem had constraint to have a better (at least the same) return than a minimum acceptable return. But in scipy minimization you set this constraint to target minimum acceptable return. Why? We should just use the "ineq" type as I remember. And therefore we (probably) would get another solution. And, as I understood, your linear equation makes a minimum return as a target too (sorry, 1 am, skipped some logic, sorry :( )

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

    Thanks for the video.

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

    I wonder what the Portfolio risk formula will be if there are a million number of stocks in the portfolio.

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

      Yes the problem would be the inversion of the Sigma matrix. It would be too slow depending on the machine.

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

    Superb.. thnk you Sir :)

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

    love your videos! keep it up:)

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

    awesome quality useful content

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

    What are the requisites to study CFA?

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

    Nice handwriting I see it has improved compared to your last tutorials.

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

    Thanks a-lot sir I really do appreciate your help with this video

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

    2:33 How is minimum accepted return an input to the problem ?

  • @ccuuttww
    @ccuuttww 6 месяцев назад

    why rmin is 0.02 we expected it is some kind of dollars

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

    Very clear, thank you so much :-)

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

    Well done 👍🏻

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

    Is the CAGR true that CAGR = (end-price/start-price)^(1/years) - 1 ?

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

    2:04 relative price changes are ratio of current period vs previous one ?

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

    fantastic video !

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

    Well done boss. 💪🏻