CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Parallel Programming in R

Afficher le cours

Instructions

  • 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.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Plan a multisession of four workers
___(___, ___)

df_stocks %>% 
# Split the data by Company
  ___(___) %>% 
# Apply mean_dist() using the correct future_map() variant
  ___(___)

# Revert to sequential plan
___(___)
Modifier et exécuter le code