3. Returns distribution. You are given a variable, sp500_simple_returns
, which contains end-of-month returns to the S&P500
index for the period between 2012 and 2022. Compute the mean and standard deviation of the returns using mean()
and sd
,
and plot its histogram using hist()
.
sp500_simple_returns <- c(0.0028467,0.0070683,0.0504281,0.0110606,0.0359878,0.0180858,0.0207628,-0.0149993,0.0494621,
-0.031298,0.0297495,0.0445958,0.0280495,0.0235628,-0.0355829,0.043117,0.0069322,0.0062008,0.0210303,
0.0190583,-0.0150799,0.0376553,-0.0155139,0.0232015,0.0245336,-0.0041885,-0.0310408,0.0548925,-0.0173961,
0.0085208,0.0104914,-0.0210118,0.019742,-0.0625808,-0.0264428,0.0829831,0.000505,-0.0175302,-0.0507353,
-0.0041284,0.0659911,0.0026994,0.0153295,0.0009061,0.0356098,-0.0012192,-0.0012345,-0.0194256,0.0341744,
0.0182008,0.0178843,0.0371983,-0.0003892,0.0090912,0.0115762,0.0048138,0.0193488,0.0005465,0.0193029,
0.0221882,0.0280826,0.0098316,0.0561787,-0.0389474,-0.0268845,0.0027188,0.0216084,0.0048424,0.0360216,
0.0302632,0.0042943,-0.0694034,0.0178594,-0.091777,0.0786844,0.0297289,0.0179243,0.0393134,-0.0657777,
0.0689302,0.0131282,-0.0180917,0.0171812,0.0204317,0.0340471,0.0285898,-0.0016281,-0.0841105,-0.1251193,
0.1268441,0.0452818,0.0183884,0.0551013,0.0700647,-0.039228,-0.0276658,0.1075457,0.0371214,-0.0111366,
0.0260915,0.0424386,0.0524253,0.0054865,0.022214,0.0227481,0.0289903,-0.0475691,0.0691439,-0.0083337,
0.0436129,-0.0525851,-0.0313605,0.0357732,-0.0879567,0.0000532,-0.08392,0.0911163,-0.0424401)
# Compute the mean of returns.
mean_return <- ___
# Compute the standard deviation of returns.
sd_return <- ___
# Plot histogram of returns.
___
# Compute the mean of returns.
mean_return <- mean(sp500_simple_returns)
# Compute the standard deviation of returns.
sd_return <- sd(sp500_simple_returns)
# Plot histogram of returns.
hist(sp500_simple_returns)
test_error()
test_object("mean_return", incorrect_msg="Did you use the `mean()` function?")
test_object("sd_return", incorrect_msg="Did you use the `sd()` function?")
test_function("hist", incorrect_msg="Did you use the `hist()` function?")
success_msg("Well done! Based on your histogram plot, is the returns distribution similar to a normal distribution?")
mean()
and sd
?