Get startedGet started for free

Reproduce the bootstrap

You work for an online stock brokerage. Your firm is developing an Android app that provides general price ranges for stocks sold by the firm. A bootstrapping function, boot_price(), is available for you to calculate monthly price ranges.

To test the reproducibility of this function in parallel, you have decided to apply this function to every element of a list, ls_micro. Each element of this list is a vector of average daily Microsoft stock prices for a given month.

The parallel package has been loaded for you.

This exercise is part of the course

Parallel Programming in R

View Course

Exercise instructions

  • Set a seed value of 321 for the cl1 cluster to do the first run.
  • Set the same seed value for the cl2 cluster to do the second run.
  • Test if outputs result1 and result2 are the same.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

cl1 <- makeCluster(4)
# Set 321 as the seed value for the first run
___(___, ___)
result1 <- parLapply(cl1, ls_micro, boot_price)
stopCluster(cl1)

cl2 <- makeCluster(4)
# Set the same seed value for the second run
___(___, ___)
result2 <- parLapply(cl2, ls_micro, boot_price)
stopCluster(cl2)

# Test if outputs are the same
___(___, ___)
Edit and Run Code