Efficient Frontier in Python p.1
HTML-код
- Опубликовано: 30 июл 2024
- Part 1: Building the Efficient Frontier in Python
Code available at my website: quantpy.com.au/python-for-fin...
In this series we are building the Efficient Frontier in Python with Dash as a web application over multiple tutorials.
★ ★ QuantPy GitHub ★ ★
Collection of resources used on QuantPy RUclips channel. github.com/thequantpy
★ ★ Discord Community ★ ★
Join a small niche community of like-minded quants on discord. / discord
★ ★ Support our Patreon Community ★ ★
Get access to Jupyter Notebooks that can run in the browser without downloading python.
/ quantpy
★ ★ ThetaData API ★ ★
ThetaData's API provides both realtime and historical options data for end-of-day, and intraday trades and quotes. Use coupon 'QPY1' to receive 20% off on your first month.
www.thetadata.net/
★ ★ Online Quant Tutorials ★ ★
WEBSITE: quantpy.com.au
★ ★ Contact Us ★ ★
EMAIL: pythonforquants@gmail.com
Disclaimer: All ideas, opinions, recommendations and/or forecasts, expressed or implied in this content, are for informational and educational purposes only and should not be construed as financial product advice or an inducement or instruction to invest, trade, and/or speculate in the markets. Any action or refraining from action; investments, trades, and/or speculations made in light of the ideas, opinions, and/or forecasts, expressed or implied in this content, are committed at your own risk an consequence, financial or otherwise. As an affiliate of ThetaData, QuantPy Pty Ltd is compensated for any purchases made through the link provided in this description.
This series is awesome! Thank you! I just wish there was a follow-up discussing the parameters that were implemented but not used yet
I really liked your step by step explanation. I will surely watch all your videos. Thanks for your time.
Great video, thanks!
Hi I get an error when I tried to print :"getData(stocks....) " , string indices must intgers typeerror. How I can fix it?
Thank you!!!
Same question. Did u find an answer
Great video at first! What do you think about not doing the calculation via the covariance-matrix but adding up the daily stock-returns depending on their allocation in the portfolio and just calculating the volatility and mean return of the created portfolio?
Do we need any adjustments for stocks listed on the TSX e.g. Shopify (SHOP)? AX. is giving error. Thanks !
I'm not absolutely positive if this is true, but I believe that you can remove the entire line that has stock = [stock+" .AX" for stock in stocklist] and change the final line from print(getdata(stock, start=startDate, end=endDate)) to print(getdata(stocklist, start=startData, end=endData)). I came to this conclusion because I kept getting an error in pycharm telling me that it didn't understand the symbols with .AX at the end. Once I removed the .AX line and changed the final line it interpreted the code and created the model. If you can confirm my suspicion or correct me that would be great, Thanks.
Can't understand why we use weighted sum of mean returns multiplied by amount of days. Shouldn't we use 1 * (1 +mean returns)^days_in_period ??
Amazing series, thanks for sharing!
I was wondering about whether you should be working with the log returns instead of percentage returns? Because taking the average of percentage returns doesn't really make sense (I could be wrong). Or is it just because the daily returns are usually so small that it doesn't really make a difference?
Daily log returns are approximately equal to simple returns (can be proofed by a Taylor series expansion of the function ln(1+x) ). It is allowed to sum daily log return to get a multi period return (properties of logarithms). So the average daily simple return equals the average daily log return and can thus be used to compute the yearly return as he does in the video.
Still works in 2023, with minor tweaks to the code (especially using yfinance instead of get_data_yahoo).
Hello, thanks for the video but could you please explain why we use .T after weights ? It does not work when I add it
Thanks !
it stands for "transpose", you have to transpose the weights matrix in order to multiply it with the covariance matrix, Hope this is still relevant for you one year later
I have a little problem i get the data from reuter and download it to first in excel and then i use python. I can not recreate this so well
I believe Reuters has a python API call which will get your data directly into a pandas dataframe. Just declare that you want the Close price column and you're good to go. Hopefully that helps
Hey Mate, How can I fix this error?
SymbolWarning: Failed to read symbol: 'CBA.AX', replacing with NaN.
'No data fetched using 'YahooDailyReader'
Try updating pandas_datareader
pip install -upgrade pandas-datareader
Could I get all your code. On your website code is not completely available but only partially. I would be very grateful to you
Sorry Johannes, working at putting together a github account for this youtube page. But for now all the complicated functions are on website, and the rest you'll find by watching the video's
Why don't we use adjusted close?
What's the difference? Thanks man
Also can you explain the returns and std at the end? What was impact of the output on the portfolio? Pretty much how you explain that to the investor.
Closing price represents the stocks price that is quoted at the end of a trading day. Adjusted closing price takes into account after-hours pricing (out-side of exchange hours) and other corporate actions like dividends ect. Investopedia is probably a good reference here: www.investopedia.com/ask/answers/06/adjustedclosingprice.asp
Excellent. You forgot to plot Efficient Frontier.
can you please do a similar video for 10-20 stocks. Under my python code my EF loses its carvature the more stocks i add.
did you find a solution? It's happening to me too...
If by this you mean the EF black dotted line moves left ‘no longer touching’ the simulated portfolios, this is of course expected. In the simulations each weighting is greater than 0. In the EF scipy optimisation function a weighting of 0 this allowed. This is expected.
@@QuantPy Thanks for answering! In my case I had this problem because i was using daily returns and annualized risk. Now I think is working.
Anyway thank you again, your videos are helping a lot! =)
Which Editor are you using ?
Visual Studio Code
Question: the timedelta we use is 365 and the portfolio performance is calculated on 252 days, is it correct or should both of them have the same number of days?
These don’t need to be the same. 252 is for the number of trading days per year so you get annualised numbers. Time delta is just how far we’ve chosen our data range to go back. This was in days
nice, instead of np.dot, use @ operator for clarity :-)
copied his code word for word and it didn't work