PyQuant News 🐍
PyQuant News 🐍

@pyquantnews

14 Tweets 2 reads Dec 07, 2023
There is $664,000,000,000 invested in factor strategies.
Factors can help you manage risk and amplify returns.
I spent 3 years figuring it out.
Now you can do it in 10 minutes.
Here’s how in Python.
By reading this thread, you’ll be able to:
• Download historic factor data
• Compute the sensitivities to the factors
• Figure out the risk contribution of the factors
But first…
A quick primer on factor investing:
• Used to target specific return drivers
• Helps manage risk outside diversification
• Important for active managers that get paid for performance
You can use the famous Fama-French 3-factor model for free.
Here’s how.
First, import the libraries.
You can use `pandas_datareader` to download the factor data and `yfinance` to download stock price data.
Use `statsmodels` for modeling.
`SMB` is “small minus big” representing the size factor.
`HML` is “high minus low” representing the style factor.
This also downloads a third factor, `Rm-Rf`, which is the portfolio excess return.
I only use `SMB` and `HML` for this analysis.
Next, you will compute the active return of the portfolio.
The active return is the portfolio return minus the benchmark return.
Run a regression with the active returns as the variable dependent on the factors.
Fitting the model gives you the two coefficients that determine the sensitivities of the portfolio’s active returns to the factors.
The sensitivities are estimates so it’s important to see how they evolve through time.
The dashed lines are confidence intervals around the beta estimates.
Marginal Contribution To Risk (MCTR) measures the incremental risk each additional factor introduces to your portfolio.
I use active risk instead to compute the Marginal Contribution To Active Risk.
To figure out the factor’s MCTAR, multiply the factor sensitivity by the covariance between the two factors.
Then divide by the standard deviation of the active returns, squared.
MCTAR tells you how much risk you take on by being exposed to each factor given the other factors you’re already exposed to.
The unexplained risk contribution is the exposure you have to other factors outside of the two you analyzed.
Factor analysis helps you:
• Identify latent risks
• Attribute risk to sectors
• Hedge unwanted risks
It's a critical tool for quantitative portfolio management.
Now you can do it too!
If you want real Python code for algo trading and market analytics, you might consider The PyQuant Newsletter:
• Real code
• No jargon
• 5 minutes to read
Join 22,000+ subscribers who are taking action with Python.
pyquantnews.com

Loading suggestions...