Python Tutorial : Mean, Variance, and Normal Distributions
Key Takeaways
This video tutorial covers the concepts of mean, variance, and normal distributions in Python, specifically in the context of financial risk management and portfolio analysis, using libraries such as NumPy.
Full Transcript
since financial risk can simply be thought of as a measure of uncertainty of future returns it is good practice to examine the natural distribution of returns in order to better understand the risk of investments probability distributions have common properties known as moments which can be analyzed and compared to other distributions the first moment is the mean or mu which is essentially the average outcome of a random sample of the distribution the second moment is the variance which is simply the standard deviation or Sigma squared this is a measure of the variability in outcomes the third and fourth moments are less commonly used the third moment skewness is a measure of the tilt of a distribution while the fourth moment kurtosis is an important measure of the thickness of the tails of a distribution we'll get to those later there are many different types of common distributions you might be familiar with the Gaussian normal distribution if you've taken statistics class before the standard normal distribution is a special case of the normal distribution when Sigma equals 1 and mu equals 0 all normal distributions tend to have a skewness near 0 and a kurtosis near 3 financial returns on the other hand tend to have positive skewness and a kurtosis higher than 3 this means financial returns tend to have a higher probability of both outliers and of positive returns than a normal distribution we'll talk more about kurtosis and skewness and later here we compare the daily returns of IBM stock with a sample from the normal distribution with the same mean and standard deviation there are statistical tests for normality such as Shapiro Wilk and jock Berra but a high kurtosis or large skewness is a simple indicator of non normal returns you can use Python to estimate the moments of a return distribution to calculate the average daily return of an asset or mu assuming you have already calculated daily returns simply use numb PI's mean function to compute the average now if you want to analyze that number you'll first need to add 1 to the decimal before raising the quantity to the power of 252 which is the typical number of trading days in a year for example a daily return of just 0.03 percent works out to an annualized return of seven point eight five percent when it is compounded every day for 250 two trading days in a row the second moment of the distribution is variance which is this square of the standard deviation or volatility volatility is one of the most important concepts for risk management in finance some traders simply refer to it as volve for short the fundamental takeaway is simple an investment with higher volatility is viewed as a higher risk investment volatility is just another measure of the dispersion of returns just like variance you can easily calculate the standard deviation returns using the STD function if the returns are daily returns then this function will output the daily standard deviation in order to calculate the variance simply square the standard deviation it's very important to understand that volatility scales with the square root of time to properly scale the daily volatility of an asset simply multiply the volatility by the square root of the number of trading days in the year this is easy to accomplish using numpy by simply multiplying the standard deviation of daily returns by the square root of 252 time to put this into practice
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/introduction-to-portfolio-risk-management-in-python at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
Since financial risk can simply be thought of as a measure of uncertainty of future returns, it is good practice to examine the natural distribution of returns in order to better understand the risk of investments.
Probability distributions have common properties, known as moments, which can be analyzed and compared to other distributions.
The first moment is the mean, or mu, which is essentially the average outcome of a random sample of the distribution.
The second moment is the variance, which is simply the standard deviation, or sigma, squared. This is a measure of the variability in outcomes.
The third and fourth moments are less commonly used. The third moment, skewness, is a measure of the "tilt" of a distribution, while the fourth moment, kurtosis, is an important measure of the thickness of the tails of a distribution. We'll get to those later.
There are many different types of common distributions. You might be familiar with the Gaussian normal distribution if you've taken a statistics class before.
The standard normal distribution is a special case of the normal distribution when sigma = 1 and mu = 0.
All normal distributions tend to have a skewness near 0 and a kurtosis near 3.
Financial returns, on the other hand, tend to have positive skewness and a kurtosis higher than 3. This means financial returns tend to have a higher probability of both outliers and of positive returns than a normal distribution. We'll talk more about kurtosis and skewness later.
Here we compare the daily returns of IBM stock with a sample from the normal distribution with the same mean and standard deviation.
There are statistical tests for normality(such as Shapiro-Wilk, Jarque-Bera, but a high kurtosis or large skewness is a si
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from DataCamp · DataCamp · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SQL Server Tutorial: Date manipulation
DataCamp
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
R Tutorial: Adding aesthetics to represent a variable
DataCamp
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
Python Tutorial: Preparation for modeling
DataCamp
Python Tutorial: Machine Learning modeling steps
DataCamp
R Tutorial: The prior model
DataCamp
R Tutorial: Data & the likelihood
DataCamp
R Tutorial: The posterior model
DataCamp
R Tutorial: An Introduction to plotly
DataCamp
R Tutorial: Plotting a single variable
DataCamp
R Tutorial: Bivariate graphics
DataCamp
Python Tutorial: Customer Segmentation in Python
DataCamp
Python Tutorial: Time cohorts
DataCamp
Python Tutorial: Calculate cohort metrics
DataCamp
Python Tutorial: Cohort analysis visualization
DataCamp
R Tutorial: Building Dashboards with flexdashboard
DataCamp
R Tutorial: Anatomy of a flexdashboard
DataCamp
R Tutorial: Layout basics
DataCamp
R Tutorial: Advanced layouts
DataCamp
Python Tutorial: Time Series Analysis in Python
DataCamp
Python Tutorial: Correlation of Two Time Series
DataCamp
Python Tutorial: Simple Linear Regressions
DataCamp
Python Tutorial: Autocorrelation
DataCamp
R Tutorial: The gapminder dataset
DataCamp
R Tutorial: The filter verb
DataCamp
R Tutorial: The arrange verb
DataCamp
R Tutorial: The mutate verb
DataCamp
R Tutorial: What is cluster analysis?
DataCamp
R Tutorial: Distance between two observations
DataCamp
R Tutorial: The importance of scale
DataCamp
R Tutorial: Measuring distance for categorical data
DataCamp
Python Tutorial: Plotting multiple graphs
DataCamp
Python Tutorial: Customizing axes
DataCamp
Python Tutorial: Legends, annotations, & styles
DataCamp
Python Tutorial: Introduction to iterators
DataCamp
Python Tutorial: Playing with iterators
DataCamp
Python Tutorial: Using iterators to load large files into memory
DataCamp
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
SQL Tutorial: Tables: At the core of every database
DataCamp
SQL Tutorial: Update your database as the structure changes
DataCamp
Python Tutorial: Classification-Tree Learning
DataCamp
Python Tutorial: Decision-Tree for Classification
DataCamp
Python Tutorial: Decision-Tree for Regression
DataCamp
Python Tutorial: Census Subject Tables
DataCamp
Python Tutorial: Census Geography
DataCamp
Python Tutorial: Using the Census API
DataCamp
R Tutorial: A/B Testing in R
DataCamp
R Tutorial: Baseline Conversion Rates
DataCamp
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
R Tutorial: Introduction to qualitative data
DataCamp
R Tutorial: Understanding your qualitative variables
DataCamp
R Tutorial: Making Better Plots
DataCamp
SQL Tutorial: OLTP and OLAP
DataCamp
SQL Tutorial: Storing data
DataCamp
SQL Tutorial: Database design
DataCamp
Python Tutorial: Introduction to spaCy
DataCamp
Python Tutorial: Statistical Models
DataCamp
Python Tutorial: Rule-based Matching
DataCamp
More on: ML Maths Basics
View skill →Related AI Lessons
🎓
Tutor Explanation
DeepCamp AI