1. Learn
  2. /
  3. Courses
  4. /
  5. Parallel Programming in R

Exercise

Grouped bootstrap of stock prices

You work for as a Statistical Analyst for a stock broker. You have received one month's data of daily stock prices from the New York Stock Exchange website. The data is in the following format:

    Company   Price
1    Google 2863.00
2 Microsoft  335.46
3   Netflix  591.61
4  Facebook  346.91
...

Your boss wants to see the distribution for each company in it's own column so that he can plot it easily in Microsoft Excel.

The data is already loaded in your workspace, df_stocks. You have also written a function, mean_dist(), to do the bootstrapping. mean_dist() accepts a data frame of one company and outputs a vector. You need to run this calculation in parallel. The furrr package has been loaded for you.

Instructions

100 XP
  • Plan a multisession of four workers.
  • Split the data frame by unique values in the column Company.
  • Apply mean_dist() to split data frames using the future_map() variant which combines results as columns of a data frame.
  • Revert to a sequential plan.