Introduction to Portfolio Risk Management in Python
Dakota Wixom
Quantitative Analyst | QuantCourse.com
Learn how to analyze investment return distributions, build portfolios and reduce risk, and identify key factors which are driving portfolio returns.
What is Risk?
How do you typically measure risk?
$$ Rl = \ln(\frac{P_{t_2}}{P_{t_1}}) $$
or equivalently
$$ Rl = \ln(P_{t_2}) - \ln(P_{t_1}) $$
Load in stock prices data and store it as a pandas DataFrame organized by date:
import pandas as pd
StockPrices = pd.read_csv('StockData.csv', parse_dates=['Date'])
StockPrices = StockPrices.sort_values(by='Date')
StockPrices.set_index('Date', inplace=True)
Calculate daily returns of the adjusted close prices and append the returns as a new column in the DataFrame.
StockPrices["Returns"] = StockPrices["Adj Close"].pct_change()
StockPrices["Returns"].head()
import matplotlib.pyplot as plt
plt.hist(StockPrices["Returns"].dropna(), bins=75, density=False)
plt.show()
Introduction to Portfolio Risk Management in Python