Quantitative Risk Management in Python
Quantitative Risk Management in Python
Quantitative Risk Management in Python
Q U A N T I TAT I V E R I S K M A N A G E M E N T I N P Y T H O N
Specializing in:
asset pricing
Uncertainty:
Future outcomes are unknown
Stocks
Bonds
Stock options
DataFrame prices
.pct_change() method
prices = pandas.read_csv("portfolio.csv")
returns = prices.pct_change()
weights = (weight_1, weight_2, ...)
portfolio_returns = returns.dot(weights)
covariance = returns.cov()*252
print(covariance)
covariance = returns.cov()*252
print(covariance)
covariance = returns.cov()*252
print(covariance)
windowed = portfolio_returns.rolling(30)
volatility = windowed.std()*np.sqrt(252)
volatility.plot()
.set ylabel("Standard Deviation...")
Jamsheed Shorish
Computational Economist
Risk factors
Volatility: measure of dispersion of returns
around expected value
Firm/sector characteristics
Firm size (market capitalization)
Book-to-market ratio
Sector shocks
Avalanche of delinquencies/default
destroyed collateral value
import statsmodels.api as sm
regression = sm.OLS(returns, delinquencies).fit()
print(regression.summary())
Jamsheed Shorish
Computational Economist
The risk-return trade-off
Risk factors: sources of uncertainty a ecting return
Investor risk appetite: de nes one quanti ed relationship between risk and return
Constrained Line Algorithm ( CLA ) class: generates the entire e cient frontier
Requires covariance matrix of returns
expected_returns = mean_historical_return(prices)
efficient_cov = CovarianceShrinkage(prices).ledoit_wolf()
cla = CLA(expected_returns, efficient_cov)
minimum_variance = cla.min_volatility()
(ret, vol, weights) = cla.efficient_frontier()