MENU

Fun & Interesting

Portfolio Beta Weighting with Python

QuantPy 8,327 4 years ago
Video Not Working? Fix It Now

Beta weighting is a tool that allows us to approximate our positions in terms of the same benchmark. Today we learn how to beta weight your portfolio in python. We will use three equivalent methods to estimate the beta coefficients of each security and then progress onto how you can beta weight your portfolio delta’s (the change in value given a unit change of the underlying) to get an approximation for how your portfolio will change with respect to a movement in your benchmark (whether it be a market index or specific security). We will calculate beta coefficients directly using the capital asset pricing model (CAPM) definition, and through some linear algebra tools using linear regression on individual stocks and then aggregated using a closed form solution for linear regression with a specific minimisation function. 00:00 Intro 01:04 Get stock data 04:26 Beta coefficient CAPM calculation 09:02 Beta coefficient linear regression (scipy stats module) 11:25 Beta coefficient linear algebra (closed form solution) 17:30 Beta weighted stock portfolio 24:45 What about options? 30:40 Beta weighting the Delta’s 35:23 Why it’s useful As a high-level programming language, Python is a great tool for financial data analysis, with quick implementation and well documented API data sources, statistical modules and other frameworks related to the financial industry. We will be using Jupyter Lab as an interactive web browser editor for this series due to ease of use and presenting code in a live notebook is ideal for this tutorial series. This is the fifth video of many on the topic of Python for Finance. The series will include general techniques used for financial analysis and act as an introduction for more in-depth tutorials that we may explore later (such as time series modelling, building financial dashboards, machine learning ect.). ★ ★ Code Available on GitHub ★ ★ GitHub: https://github.com/TheQuantPy Specific Tutorial Link: https://github.com/TheQuantPy/youtube-tutorials/blob/8e64e19629cee840928b51baf4660e5c777e87e7/2021/002%20Apr-Jun/2021-06-10%20Portfolio%20Beta%20Weighting%20with%20Python.ipynb ★ ★ QuantPy GitHub ★ ★ Collection of resources used on QuantPy YouTube channel. https://github.com/thequantpy ★ ★ Discord Community ★ ★ Join a small niche community of like-minded quants on discord. https://discord.com/invite/aY2Af4CxHP ★ ★ Support our Patreon Community ★ ★ Get access to Jupyter Notebooks that can run in the browser without downloading python. https://www.patreon.com/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. https://www.thetadata.net/ ★ ★ Online Quant Tutorials ★ ★ WEBSITE: https://quantpy.com.au ★ ★ Contact Us ★ ★ EMAIL: [email protected] 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.

Comment