1
00:00:00,000 --> 00:00:05,307
Now, going back to other characteristics,
essentially what I'm, what I'm doing is

2
00:00:05,307 --> 00:00:10,090
I'm mirroring with sample statistics, the
kinds of things we did in probability

3
00:00:10,090 --> 00:00:11,050
theory.
Alright.

4
00:00:11,050 --> 00:00:16,064
So an important thing for us is a quantile
of the distribution.

5
00:00:16,064 --> 00:00:21,906
So, when we did value at risk we found,
you know, if you want to know with five

6
00:00:21,906 --> 00:00:26,162
percent probability, how much money we
could loose, we compute the five percent

7
00:00:26,173 --> 00:00:31,045
quantile of the return distribution.
Now, we have, we, if we have a probability

8
00:00:31,045 --> 00:00:36,039
distribution, we can determine the
quantile from the inverse of the CDF.

9
00:00:36,039 --> 00:00:40,475
But with data, we can also estimate or
compute a sample quantile, right?

10
00:00:40,475 --> 00:00:46,246
And the sample quantile is often called
the empirical quantile or the percentile.

11
00:00:46,246 --> 00:00:51,312
So, for some alpha and 01, we can get the
hundred times alpha percentile that is,

12
00:00:51,312 --> 00:00:55,860
like, the fifth percentile of the data.
The fifth percentile of the data is just

13
00:00:55,860 --> 00:01:02,003
the data points such that or, sorry, the
alpha percentile is the data points such

14
00:01:02,003 --> 00:01:05,387
that alpha percent of the data is less
than that value, okay?

15
00:01:05,387 --> 00:01:10,839
And so essentially, how do you find these
empirical quantiles in this ordered data

16
00:01:10,839 --> 00:01:16,059
from largest to smallest and the five%,
the, the, the fifth percentile is just

17
00:01:16,059 --> 00:01:20,015
that point in the data such that five
percent is to the left, okay?

18
00:01:20,015 --> 00:01:24,540
And, and then, we also have these things
called quartiles, the, you know, the first

19
00:01:24,540 --> 00:01:29,521
quartile is the twenty-fifth percentile,
the second quartile is the median, the

20
00:01:29,521 --> 00:01:33,529
third quartile is the seventy-fifth
percentile and, and so on.

21
00:01:33,529 --> 00:01:38,756
There's something called the interquartile
range which is a measure of the, the, you

22
00:01:38,756 --> 00:01:43,977
know, the bulk of the distribution.
It's just the difference between the third

23
00:01:43,977 --> 00:01:47,719
quartile and the first quartile.
Now, let's look at actual data.

24
00:01:47,719 --> 00:01:52,470
So, if we're looking at the Microsoft
data, there's a function of R called the

25
00:01:52,470 --> 00:01:55,662
quantile.
The quantile function computes the

26
00:01:55,662 --> 00:02:00,546
empirical quantiles of the data.
And if you just use the quantile function

27
00:02:00,546 --> 00:02:04,447
by itself, it gives you the minimum, so
the minimum return is -42%.

28
00:02:04,447 --> 00:02:10,065
It gives you the first quartile, so it's
the twenty-fifth percentile, so -5.3%.

29
00:02:10,065 --> 00:02:15,034
25 percent of the returns are smaller than
this value, okay?

30
00:02:15,034 --> 00:02:21,556
The, this is the median, the, and the
median return is one%, okay?

31
00:02:21,556 --> 00:02:29,495
So, and then, the on the right side of the
distribution so 75 percent of the returns

32
00:02:29,495 --> 00:02:34,082
are less than six percent or 25 percent of
the returns are bigger than six%.

33
00:02:34,084 --> 00:02:39,008
And then, this is the largest return, it's
34%, okay?

34
00:02:39,008 --> 00:02:45,249
Now, for value at risk calculations, we're
often interested in the one percent and

35
00:02:45,249 --> 00:02:51,058
the five percent empirical quantiles.
So, if we look at Microsoft, we use the

36
00:02:51,058 --> 00:02:57,096
quantile function, we say, prod is equal,
you know, we combine 0.01 and 0.05.

37
00:02:57,096 --> 00:03:02,018
Then, we get the one percent quantile and
the five percent quantile.

38
00:03:02,018 --> 00:03:07,030
So here the one percent empirical quantile
is -26%.

39
00:03:07,030 --> 00:03:11,484
So , one percent of the returns are less
than 26 percent and the five percent

40
00:03:11,494 --> 00:03:19,025
empirical quantile is -fourteen percent so
five percent of the returns are smaller

41
00:03:19,025 --> 00:03:24,925
than -fourteen%, okay?
Now again, we can compare, so here are

42
00:03:24,925 --> 00:03:28,427
quantiles.
These are from the actual data, right?

43
00:03:28,427 --> 00:03:32,038
Now, what about quantiles from a normal
distribution?

44
00:03:32,038 --> 00:03:37,619
So, if I take a normal distribution that
has the same mean and standard deviation

45
00:03:37,619 --> 00:03:41,953
as the data, then I get these quantiles.
So, the one percent is, is -24 percent

46
00:03:41,953 --> 00:03:48,098
where as in the data it is -26%.
So, the one percent quantile in the data

47
00:03:48,098 --> 00:03:51,775
is smaller than the one%t normal quantile,
okay?

48
00:03:51,775 --> 00:03:55,524
And if we look at the five percent
quantile, it's kind of interesting that

49
00:03:55,524 --> 00:03:59,714
the normal five percent quantile is
actually bigger than, in the empirical

50
00:03:59,714 --> 00:04:03,037
data, right?
So, that's kind of like saying that data

51
00:04:03,037 --> 00:04:07,331
distribution is kind of squished with fat
tails relative to the normal, okay?

52
00:04:07,331 --> 00:04:12,261
Now, when we're doing value at risk we use
quantiles to do the value at risk

53
00:04:12,261 --> 00:04:15,839
calculations.
So, we can do value at risk with the

54
00:04:15,839 --> 00:04:21,536
empirical quantiles, or we can do value at
risk from the normal quantiles that use

55
00:04:21,536 --> 00:04:24,996
the mean and standard deviation from the
actual data.

56
00:04:24,996 --> 00:04:31,960
Okay, so, those are two different types of
assumptions for doing for doing VAR.

57
00:04:31,960 --> 00:04:38,035
Now, if we look at the S and P 500, we can
do the same comparison.

58
00:04:38,035 --> 00:04:44,840
So, the empirical quantiles for the S and
P 500 data, the one percent quantiles

59
00:04:44,840 --> 00:04:48,093
minus eleven percent and the five percent
quantiles minus 7.5%.

60
00:04:48,093 --> 00:04:52,086
Now, it's interesting to compare this to
Microsoft.

61
00:04:52,086 --> 00:04:58,089
So, with the S and P 500 with say, one
percent probability, you could lose eleven

62
00:04:58,089 --> 00:05:00,346
percent or more.
But with Microsoft, with one percent

63
00:05:00,353 --> 00:05:03,086
probability, you could lose 26 percent or
more, right?

64
00:05:03,086 --> 00:05:09,026
So, that's almost three times as much as
what you can lose in the S and P 500.

65
00:05:09,026 --> 00:05:14,087
So again, if we think about risk as being
the probability of loss, then there's a

66
00:05:14,087 --> 00:05:20,075
higher probability of loss associated with
Microsoft than there is with the S and P

67
00:05:20,075 --> 00:05:26,005
500.
Okay, so okay, so here is the empirical

68
00:05:26,005 --> 00:05:29,539
quantiles.
And R functions there are lot of functions

69
00:05:29,539 --> 00:05:33,526
you can sort data, you can take the
minimum and the maximum, you can compute

70
00:05:33,526 --> 00:05:37,801
range which is the difference between the
minimum and the max, compute your

71
00:05:37,801 --> 00:05:41,072
quantiles, the median, you can compute
interquartile ranges.

72
00:05:41,072 --> 00:05:45,148
So, you have all these, you know, nice
functions you know, that, you can work

73
00:05:45,148 --> 00:05:49,075
with, the homework assignment, you know,
takes you through many things.

74
00:05:49,292 --> 00:05:54,024
I want to make a comment about value at
risk using empirical quantiles.

75
00:05:54,024 --> 00:05:59,037
So, there's something known in, in the
finance literature as historical value at

76
00:05:59,037 --> 00:06:01,068
risk.
When you, when you hear the term

77
00:06:01,068 --> 00:06:06,043
historical value at risk, you're computing
value at risk using the empirical

78
00:06:06,043 --> 00:06:11,031
quantiles, not the quantiles from a normal
distribution or something like that,

79
00:06:11,031 --> 00:06:14,081
you're just using the empirical quantiles
from the data.

80
00:06:14,081 --> 00:06:19,675
So, what is actually being computed?
So, we have our simple returns and the

81
00:06:19,675 --> 00:06:26,073
historical value at risk is your initial
investment times the empirical quantile of

82
00:06:26,073 --> 00:06:30,370
your simple returns, you know, at the
alpha level, okay?

83
00:06:30,370 --> 00:06:35,626
So, this is just the, the data point that
we use from the quantile function, okay?

84
00:06:35,626 --> 00:06:39,950
And, and so, this, this could be an
estimate of, of our loss, okay?

85
00:06:39,950 --> 00:06:44,572
If we have continuously compounded
returns, remember the value at risk then

86
00:06:44,572 --> 00:06:49,324
would be e to the continuously compounded
quantile -one times your initial

87
00:06:49,324 --> 00:06:52,856
investment.
So, this would be your value at risk with

88
00:06:53,061 --> 00:06:57,764
continuously compounded data.
And the key thing is, again, we're using

89
00:06:57,764 --> 00:07:02,423
the, just the empirical quantile, we're
not using the quantile from, say, a normal

90
00:07:02,423 --> 00:07:12,029
distribution, alright?
Now so, here's the histogram that gives us

91
00:07:12,029 --> 00:07:16,050
the general shape of the distribution.
Now, what about shape characteristics?

92
00:07:16,050 --> 00:07:20,034
If we want to know the sensor, then we
compute the sample average.

93
00:07:20,034 --> 00:07:25,655
The sample average is a, is a measure of
the center of the distribution and that's

94
00:07:25,655 --> 00:07:29,030
just an equally-weighted average of the
data points, okay?

95
00:07:29,030 --> 00:07:34,045
If we want to know the spread about the
average for the histogram, we compute the

96
00:07:34,045 --> 00:07:38,007
sample variance.
The sample variance, we take one over the

97
00:07:38,007 --> 00:07:43,035
sample size minus one, and then we sum all
of the observations, we subtract the mean

98
00:07:43,035 --> 00:07:46,082
value, we square it.
So this is, this is called the sample

99
00:07:46,082 --> 00:07:49,196
average.
Notice we divide by t - one and not t,

100
00:07:49,196 --> 00:07:52,082
okay?
We'll come back to this a little bit later

101
00:07:52,082 --> 00:07:55,293
on.
The reason for dividing by t - one is to

102
00:07:55,293 --> 00:07:59,006
make the estimates slightly, a little bit
better.

103
00:07:59,006 --> 00:08:03,077
We, we have what's called an unbiased
estimate of spread when you divide by t

104
00:08:03,077 --> 00:08:06,055
minus one.
The sample standard deviation is the

105
00:08:06,055 --> 00:08:10,875
square root of the sample variance.
Again, that's the an estimate of the

106
00:08:10,875 --> 00:08:13,881
spread about the average in the same units
as the data.

107
00:08:14,083 --> 00:08:19,020
One of the things I want to point out
about notation you know, the sample

108
00:08:19,020 --> 00:08:23,071
average is often denoted as x bar, and
sometime as just mu hat.

109
00:08:23,071 --> 00:08:28,380
So, the Greek letter represents the
probably, the expected value of a random

110
00:08:28,380 --> 00:08:33,458
variable, and when you put a hat on top of
it, that means we're estimating that

111
00:08:33,458 --> 00:08:37,038
expected value.
And here, we're estimating the expected

112
00:08:37,038 --> 00:08:42,045
value using the sample average.
This is known as the plug in principle in

113
00:08:42,045 --> 00:08:45,098
Statistics.
So, we plug in a sample statistic for a

114
00:08:45,098 --> 00:08:50,087
population expectation.
And for sample variance, we often, you

115
00:08:50,087 --> 00:08:55,890
often see little s ^two for sample
variance and sometimes we also call it

116
00:08:55,890 --> 00:08:59,419
sigma hat squared.
So, again that's just terminology.

117
00:08:59,419 --> 00:09:03,146
And then, similarly, we can compute a
sample skewness.

118
00:09:03,146 --> 00:09:07,999
Sample skewness, we take the average of
the observations minus the mean cube

119
00:09:07,999 --> 00:09:12,718
divided by the standard deviation cube and
again, we divide by t - one to make this

120
00:09:12,718 --> 00:09:16,412
an unbiased estimate.
And then, sample kurtosis, this is

121
00:09:16,412 --> 00:09:21,112
measuring the thickness in the tails.
We sum up the observations, we subtract

122
00:09:21,112 --> 00:09:26,146
the mean, we raise it to the power of
four, we divide by the standard deviation

123
00:09:26,146 --> 00:09:29,481
to a fourth.
Okay, that's the estimated kurtosis and

124
00:09:29,669 --> 00:09:33,181
estimated axis kurtosis would be this
kurtosis -three, okay.

125
00:09:33,181 --> 00:09:38,544
And again we, axis kurtosis gives us a
measure of tail thickness relative to a

126
00:09:38,544 --> 00:09:42,867
normal distribution, okay?
So, we have sample statistics that give us

127
00:09:42,867 --> 00:09:46,301
the shape characteristics of the
histograms.

128
00:09:46,301 --> 00:09:53,611
So, in R, we have set of functions.
So, the mean function computes the sample

129
00:09:53,611 --> 00:09:56,445
mean.
The bar function can be the variance, SD

130
00:09:56,445 --> 00:10:00,764
compute standard deviation.
Core R actually doesn't have functions for

131
00:10:00,764 --> 00:10:04,058
skewness and kurtosis.
So, I like to use the skewness and

132
00:10:04,058 --> 00:10:07,373
kurtosis functions from the performance
analytics package.

133
00:10:07,373 --> 00:10:11,636
This performance analytics package in
general, is a very nice collection of

134
00:10:11,636 --> 00:10:16,390
functions that are useful in Finance.
They are very nice charting functions and

135
00:10:16,390 --> 00:10:20,726
they have a number of utility functions
that are, that are quite useful.

136
00:10:20,726 --> 00:10:25,233
In our, in our labs we are going to be
using the performance analytics functions

137
00:10:25,392 --> 00:10:28,212
quite a lot.
So, you should become familiar with, with

138
00:10:28,212 --> 00:10:31,268
this package, okay?
Now, one of the things I wanted to say

139
00:10:31,268 --> 00:10:36,714
about R and I'll come back to this here
when you calculate, when you use the mean

140
00:10:36,714 --> 00:10:42,959
function, you only work on either a vector
of data or one column of data at a time.

141
00:10:42,959 --> 00:10:48,380
If you have many return series, say, in a
matrix, often, very often you want to

142
00:10:48,380 --> 00:10:53,728
compute the mean for each column, alright?
The mean function doesn't work column

143
00:10:53,728 --> 00:10:56,885
wise.
And so, in R, when you want to apply a

144
00:10:56,885 --> 00:11:01,472
function to the columns of data, there's a
function called apply.

145
00:11:01,472 --> 00:11:06,166
And, and so this, the apply function
essentially implement a loop.

146
00:11:06,166 --> 00:11:11,079
You loop over the columns and then you
apply the function to the column itself.

147
00:11:11,079 --> 00:11:16,077
I'll illustrate how this works.
These apply functions are very, very, very

148
00:11:16,077 --> 00:11:21,412
useful particularly, say, if you have a
thousand assets and you want to compute

149
00:11:21,412 --> 00:11:27,163
the means for each of the thousand assets,
you can do it in one command by, by using

150
00:11:27,163 --> 00:11:30,008
the apply function.
Alright.

151
00:11:30,008 --> 00:11:34,378
So, let's look at some of the sample
statistics.

152
00:11:34,378 --> 00:11:37,730
So, for the mean return for Microsoft is
0.006.

153
00:11:37,730 --> 00:11:43,640
So, this is the monthly mean and it's
about it's a little less, a little less

154
00:11:43,640 --> 00:11:48,831
than one percent per month, okay.
The variance is 0.01, now that's in

155
00:11:48,831 --> 00:11:52,737
squared returns, the standard deviation is
in returns.

156
00:11:52,737 --> 00:11:56,576
The typical spread about the average is
ten%, okay?

157
00:11:56,576 --> 00:12:01,983
Remember, this is a monthly return.
So remember mean plus and minus the

158
00:12:01,983 --> 00:12:07,570
standard deviation for bell-shaped data
gives you roughly two-thirds of the

159
00:12:07,570 --> 00:12:11,084
observations.
So, two-thirds of the observations on

160
00:12:11,084 --> 00:12:14,074
Microsoft are between -ten percent and
ten%, okay?

161
00:12:14,074 --> 00:12:18,061
So, losing ten percent in a month is, is
quite a lot actually.

162
00:12:18,270 --> 00:12:23,073
The sample skewness is negative.
So in the picture, we saw a long left tail

163
00:12:23,073 --> 00:12:28,043
and when you use the skewness function for
Microsoft, you do get a negative skewness

164
00:12:28,043 --> 00:12:31,085
number.
And the kurtosis function, actually gives

165
00:12:31,085 --> 00:12:35,097
you axis kurtosis.
So don't, don't be fooled by this.

166
00:12:35,097 --> 00:12:42,130
The fact that it's kurtosis, when you look
at the help and performance analytics, you

167
00:12:42,130 --> 00:12:46,998
find that what's actually been computed as
sample kurtosis -three.

168
00:12:47,002 --> 00:12:51,015
So, axis kurtosis is 1.8 so the actual
kurtosis is 4.8.

169
00:12:51,015 --> 00:12:56,023
So, the Microsoft data have fatter tails
than the normal distribution.

170
00:12:56,023 --> 00:13:00,981
So, we're seeing a mean return of, you
know, 0.6 percent per month, a standard

171
00:13:00,981 --> 00:13:06,659
deviation of ten percent per month, a
negative skewness, and an axis kurtosis,

172
00:13:06,659 --> 00:13:13,017
okay?
Now, suppose we had a matrix of data that

173
00:13:13,017 --> 00:13:19,002
contains, the first column contains the
data from Microsoft and the second column

174
00:13:19,002 --> 00:13:24,095
contains the date for the S and P 500.
And I want to compute the means of each of

175
00:13:24,095 --> 00:13:29,093
the columns of this, this matrix.
This is where we use the apply function.

176
00:13:29,093 --> 00:13:35,078
So you, say, apply your data matrix and
then this parameter two means apply to the

177
00:13:35,078 --> 00:13:39,033
columns.
If this parameter was one then you would

178
00:13:39,033 --> 00:13:43,615
apply the function to the rows, okay?
So, this means apply to the columns and

179
00:13:43,615 --> 00:13:46,851
what are you applying?
You're applying the mean function.

180
00:13:46,851 --> 00:13:50,345
And so, what do you get?
You get the mean for the first column, the

181
00:13:50,345 --> 00:13:55,160
mean for the second column, okay?
So here, we can compare Microsoft and the

182
00:13:55,160 --> 00:13:58,865
S and P 500.
The average return for Microsoft is 0.6%.

183
00:13:58,865 --> 00:14:02,088
The average return for the S and P 500 is
0.3%.

184
00:14:02,088 --> 00:14:08,043
So, on average, we get about twice as much
per month on Microsoft than we do for the

185
00:14:08,043 --> 00:14:12,010
S and P 500, okay?
Now, what about the standard deviations?

186
00:14:12,010 --> 00:14:16,091
So, the standard deviation for Microsoft
is ten%, actually it's, it's about

187
00:14:16,091 --> 00:14:21,078
eleven%, and the standard deviation for
the S and P 500 is only four%, right?

188
00:14:21,078 --> 00:14:27,915
So here, the spread about the average for
Microsoft is, is about 2-1/2 times bigger

189
00:14:27,915 --> 00:14:31,956
than that for the S and P 500.
Notice that the mean for Microsoft is

190
00:14:31,956 --> 00:14:36,533
higher than the mean for the S and P 500,
and the standard deviation for Microsoft

191
00:14:36,533 --> 00:14:39,926
is bigger than the standard deviation for
the S and P 500.

192
00:14:39,926 --> 00:14:44,588
So, we're seeing assets that have higher
volatility, has, has a higher mean, the

193
00:14:44,588 --> 00:14:48,013
asset with a lower volatility has a lower
mean, okay?

194
00:14:48,013 --> 00:14:52,082
If you were using daily data instead of
monthly data, data, we would get a better

195
00:14:52,082 --> 00:14:56,050
analysis of the tail.
And in general, the answer is yes, because

196
00:14:56,050 --> 00:15:01,032
we have more daily data than monthly data.
And so, we have more information in the

197
00:15:01,032 --> 00:15:04,028
tail with daily data than we do with
monthly data.

198
00:15:04,028 --> 00:15:06,329
Okay.
So and then we have the skewness for

199
00:15:06,329 --> 00:15:11,544
Microsoft, S and P 500, both have negative
skewness, and the skewness for S and P 500

200
00:15:11,544 --> 00:15:15,099
is quite a bit bigger, is a bigger
negative number than for Microsoft.

201
00:15:15,099 --> 00:15:21,066
And the axis kurtosis is bigger for
Microsoft than it is for the S and P 500.

202
00:15:21,066 --> 00:15:24,031
So, again, just some comparisons.
