Introduction to Econometrics: Exercises


1. Computing log returns. You are given a vector of simple returns for the the S&P500: sp500_simple_returns.

You can convert a simple return into a log return by adding 1 and computing the natural log: log(1+simple_return). You can use the log() function to compute the natural logarithm.


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) # Add 1 to the simple returns. sp500_simple_returns <- ___ + ___ # Compute the natural logarithm. sp500_log_returns <- ___ # Plot the histogram. hist(sp500_log_returns) # Add 1 to the simple returns. sp500_simple_returns <- sp500_simple_returns + 1 # Compute the natural logarithm. sp500_log_returns <- log(sp500_simple_returns) # Plot the histogram. hist(sp500_log_returns) test_error() test_function("log", incorrect_msg="Did you use `log()` to compute the natural logarithm?") success_msg("Well done! Remember to add 1 to simple returns before computing the natural logarithm.")
Did you use the log() function to compute the natural logarithm?

Previous Exercise Next Exercise