Mean, Median, Variance and Standard Deviation
Quantitative finance is deeply rooted in statistics. Mean, median, variance and standard deviation are the most fundamental concepts to bear in mind. The calculation is easily done by Python.
📝Mean
The mean, often referred to as the average, is a fundamental statistical measure. It is calculated by summing up all the values in a data set and then dividing by the number of values. For example, if we have a data set {2, 4, 6, 8, 10}, the sum of these values is 2 + 4 + 6 + 8 + 10 = 30. There are 5 values, so the mean is 30 / 5 = 6.
📌The mean provides a measure of the central tendency of the data. It gives an overall idea of where the data is centered, but it is easily affected by extreme values (outliers).
📝Median
The median is another measure of central tendency. To find the median, we first need to arrange the data set in ascending or descending order.
If the number of values in the data set is odd, the median is the middle value. For example, in a data set {3, 5, 7, 9, 11}, n = 5 (odd), and the median is 7.
If n is even, the median is the average of the two middle values. For example, in a data set {2, 4, 6, 8}, n = 4 (even). The two middle values are 4 and 6, and the median is (4 + 6) / 2 = 5.
📌The median is less sensitive to outliers compared to the mean. It represents the value that separates the data set into two equal halves.
📝Variance
Variance is a statistical measure that quantifies the dispersion or spread of a set of data points. It provides valuable information about how much the individual data values deviate from the mean (average) of the data set.
There are data set A = {1, 3, 5} and data set B = {1, 1, 9}.
The mean of data set A is (1 + 3 + 5) / 3 = 3. The variance of data set A is ((1 - 3)^2 + (3 - 3)^2 + (5-3)^ 2) / (3 - 1) = 2.
The mean of data set B is (1 + 1 + 9) / 3 = 11 / 3. The variance of data set B is ((1 - 11 / 3)^2 + (1 - 11 / 3)^2 + (9 - 11 / 3)^2) / (3 - 1) = 32 / 3, approximately 10.67.
Data set B has a much larger variance than data set A, showing that its data points are more dispersed from the mean.
📌In finance, variance is used to measure the risk associated with an investment. A portfolio with a higher variance of returns is considered more risky because the returns are more spread out and less predictable.
📝Standard Deviation
The standard deviation measures the amount of variation or dispersion in a set of data. A low standard deviation indicates that the data points tend to be close to the mean, while a high standard deviation indicates that the data points are spread out over a wider range.
The standard deviation is the square root of the variance. They are used in very similar way. So why do we need them both at the same time?
📌Variance is expressed in squared units of the original data. For example, if the data represents lengths measured in centimeters, the variance will be in square centimeters. It is a bit less intuitive to interpret patterns shown in a data set.
📌Standard deviation, however, is in the same unit as the original data. It provides a more straightforward measure of how much the data points differ from the mean. For instance, if the data is about the scores of students in a test (ranging from 0 - 100), the standard deviation will also be in the score units, say 10 points, which gives a more direct demonstration of how much the scores vary around the average score.
💻Try it out in Python
I have a data set with 465 entries. It has two columns: date and value. I use numpy (referred to as ‘np’ in my code) to calculate the mean, median, variance and standard deviation of the data set. Those are simple and direct commands in Python. The results are shown in the last picture.
Hope you know a bit more about statistics and Python after reading this. Please feel free to leave a comment to share your thoughts.
































































































