Introduction to Portfolio Risk Management in Python
Dakota Wixom
Quantitative Analyst | QuantCourse.com
The Sharpe ratio is a measure of risk-adjusted return.
To calculate the 1966 version of the Sharpe ratio:
$$ S = \frac{ R_a - r_f }{\sigma_a} $$
Any point on the efficient frontier is an optimum portfolio.
These two common points are called Markowitz Portfolios:
How do you choose the best portfolio?
Assuming a DataFrame df
of random portfolios with Volatility
and Returns
columns:
numstocks = 5
risk_free = 0
df["Sharpe"] = (df["Returns"] - risk_free) / df["Volatility"]
MSR = df.sort_values(by=['Sharpe'], ascending=False)
MSR_weights = MSR.iloc[0, 0:numstocks]
np.array(MSR_weights)
array([0.15, 0.35, 0.10, 0.15, 0.25])
Even though a Max Sharpe Ratio portfolio might sound nice, in practice, returns are extremely difficult to predict.
Assuming a DataFrame df
of random portfolios with Volatility
and Returns
columns:
numstocks = 5
GMV = df.sort_values(by=['Volatility'], ascending=True)
GMV_weights = GMV.iloc[0, 0:numstocks]
np.array(GMV_weights)
array([0.25, 0.15, 0.35, 0.15, 0.10])
Introduction to Portfolio Risk Management in Python