In: Statistics and Probability
X1 is a binomial random variable with n = 100 and p = 0.8, while X2 is a binomial random variable with n = 100 and p = 0.2. The variables are independent. The profit measure is given by P = X1 / X2. Run N = 10 simulations of X1 and X2 to simulate the distribution of P, and then find both the variance and the semi-variance.
Given X1 and X2 are binomial random variable with n1 = 100, p1 = 0.8 and n2 = 100, p2 = 0.2 respectively.
Using R to simulate the distribution of P = X1/X2.
Creating variables in R as follows:
n1 = 100; p1 = 0.8
n2 = 100; p2 = 0.2
Simulating 10 values of both X1 and X2 using rbinom() function:
x1 <- rbinom(10, 100, 0.8) ; x1
[1] 78 84 78 81 80 74 80 84 73 79
x2 <- rbinom(10, 100, 0.2) ; x2
[1] 16 13 19 15 17 19 20 17 27 16
Calculating values of P:
P = x1/x2 ; P
[1] 4.875000 6.461538 4.105263 5.400000 4.705882 3.894737
4.000000
[8] 4.941176 2.703704 4.937500
Calculating variance of P using var() function:
var(P)
[1] 1.01339
Now to calculate semi-variance we use the formula:
Where:
n = the total number of observations below the mean
rt = the observed value (observations below mean)
Average = the mean of the dataset
First we calculate the mean using mean() function in R:
mean(P)
[1] 4.60248
Then we calculate rt as follows:
rt = P[P < mean(P)] ; rt
[1] 4.105263 3.894737 4.000000 2.703704
Calculating n (the total number of observations below the mean):
n = length(rt) ; n
[1] 4
Finally calculating semivariance:
semi_var = sum((mean(P) - rt)^2)/n
semi_var
[1] 1.179115
(The R code is in bold)