Introduction to Portfolio Risk Management in Python
Dakota Wixom
Quantitative Analyst | QuantCourse.com
Probability distributions have the following moments:
There are many types of distributions. Some are normal and some are non-normal. A random variable with a Gaussian distribution is said to be normally distributed.
Normal Distributions have the following properties:
The Standard Normal is a special case of the Normal Distribution when:
To calculate the average daily return, use the np.mean()
function:
import numpy as np
np.mean(StockPrices["Returns"])
0.0003
To calculate the average annualized return assuming 252 trading days in a year:
import numpy as np
((1+np.mean(StockPrices["Returns"]))**252)-1
0.0785
Standard Deviation (Volatility)
Assume you have pre-loaded stock returns data in the StockData
object. To calculate the periodic standard deviation of returns:
import numpy as np
np.std(StockPrices["Returns"])
0.0256
To calculate variance, simply square the standard deviation:
np.std(StockPrices["Returns"])**2
0.000655
Assume you have pre-loaded stock returns data in the StockData
object. To calculate the annualized volatility of returns:
import numpy as np
np.std(StockPrices["Returns"]) * np.sqrt(252)
0.3071
Introduction to Portfolio Risk Management in Python