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.
This exercise is part of the course
Parallel Programming in R
Exercise 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 thefuture_map()
variant which combines results as columns of a data frame. - Revert to a sequential plan.
Hands-on interactive exercise
Have a go at this exercise by completing this sample 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
___(___)