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
Great tutorial! A minor point: I think the formula you use for return is not correct. The ratio should be (p2-p1)/p1.
I was waiting for someone to actually point it out. I'm pinning this comment for visibility.
@@AhmadBazzi glad I didn’t disappoint you! ;)
Would that be: returns = (stocks.shift(1)- stocks) / stocks ?
@@7vrda7 Yes I presume, or (stocks.shift(1)/stocks)-1
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%
Convex Optimization guru !
I love how you put Python with this one 🙏🏻
You're welcome Meryl !!
Amazing lecture 👌🏻
Ahmad, you are amazing!!! Great tutorial, thank you!
Nice job ! Thank you for the tutorial
Excellent stuff with no BS 🙏🏻
Thank you Elinor 🙏🏻
Pure class. As always.
underrated you are definitely
Love your tutorials
Great job as for sharing the lesson.
My pleasure, Alberta 🙏🏻
Excellent lecture, thanks for responding to my request.
My pleasure .. Glad you enjoyed it :)
I really love how you make lessons look more should be awarded prizes for that talent you got !
Thank you very much, appreciate it
Underrated ‼️
🙏🙏
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
21:23 I love the colors of your frontier.
5:34 awesome stuff man
Glad you liked it, Darrin. For the meantime, make sure you subscribe to the channel here
ruclips.net/user/AhmadBazzi
I just shared it with my colleagues 👌🏻
You ROCK, Jonathan 🙏🏻
Perfect explanation 🤩
Glad you think so!
Damn hes the best on RUclips
Thanks Ahmad 👍🏻
You're most welcome Bailey. Glad you liked it 🙏
I love you and your lectures 📕❤️
Make sure you like and subscribe to receive future notifications about the channel !!
Love the highlights part, amazing visuals, thanks for sharing.
I'm glad you found it useful !
You just saved my ass.... thannk you !!!
Such an underrated
Glad you think so Sue. Make sure you subscribe to the channel here
ruclips.net/user/AhmadBazzi
thank you
Great session Mr can this be generalized to 5 or maybe 10 stocks?
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
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?
Thank you
You're welcome Effie 🙏
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
She's an expert trader, amazing professional
Please create the series (and playlist) for the stock market analysis
Excellent remark, Sam. I had the same idea and would definitely create this over the weekend. Stay tuned 🙏🏻
It works also with short positions?
@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?
when i hit shift+enter after entering the symbol its not showing any output. It just creates a different line.
I've never heard or seen any of her clients complain of Lost....I think she's just too perfect
I love SKIPPY ❤️😍🥪
ME TOO !!
.shift(1) shift to the back not the front right ?
What if I want to do this without short selling constraints?
Thank you for great work as usual! Skippy Peanut Butter should pay you for advertising.
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🙏
They did of course @ragheb !
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?
@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.
i just needed some help please. For the sharpeRatio it keeps coming up as invalid syntax
👍 thanks for watching👆👆👆
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
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...
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 ?
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.
His argument could also refer to art, rolex, wine etc... it does not produce anything but prices are still going up
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 ;)
Got hungry after this one 🤤
Have you some peanut butter !!
That's true, most people today are seeing a lot of failures in forex and crypto sector due to poor orientations and bad experts.
Please continue the MATLAB tutorial
Can we do implement it on MATLAB ? Thanks
Sure we can.
where is the code for this project, thanks
👍🏻
is it the code available?
Ok let me get some Peanut butter first! :) Can you make a video about the GameStop scandal?
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 !!
moudle not found
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.
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).
People of amsterdam made mistake with tulip in 17th century, and the same mistake is still in the making since then. Isnt it amazing....
013
2856
Your fomular for computing returns is wrong. The correct way is "returns = (stocks - stocks.shift(1))/stocks.shift(1)"
Because a lot of investors are confused about how the traders use their money
457
Please share with us the code thanks 🙌🏻
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.
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.
It is normal to say, ,Bitcoin does not work as it affect his business
I'm happy today because of Mrs Maria Jones
+17
I remember friends calling me crazy when I started but now I shut up them with my four figure weekly returned
Buffett also said facebook stock is useless.
Everybody does the same, governmentd, politicians .....
Everythin is a vector
She's honest, anyone can start investing now. What sap
What I've always thought about this scam
He said the same thing about gold.
Damn but you’re an electrical engineer, how on earth do you know finance ? 😲
"Last night" XD ruclips.net/video/iRALBW4hBZ0/видео.html
You can join our VIP offers,,
Bitcoin has gone up 8.9 million percent while the dollar has dropped 50 percent. Which one is worthless?
if buffet wont take your crypto, i wont take your crypto.
Warren Buffett vs Michael Saylor discussion. 👍If you agree.
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.
But he has invested in a crypto exchange company ... Strange 🌸🌸🌸
And then he bought…a lot!
:)
Wow I' m just shock someone mentioned expert Mrs Maria jonesthought I' m the only one trading with her
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.
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…
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
Cryptocurrency is a very good option if you would like to trade online.
I can't make any sense out of bitcoin.
*This message has been endorsed by the U.S federal reserve.”
Imagine if he did for 5 years... Hahaha
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.
no shit
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!