Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Parallel Programming in R

Cursus bekijken

Oefeninstructies

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

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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
___(___, ___)
Code bewerken en uitvoeren