Column operations with trading volumes
The number of shares traded (sold or bought) in a given time period is the volume. You work for a stock brokerage as a Business Analyst. A matrix of daily changes in volume, mat_stocks, is available for you. Each column contains the change in volume for a stock from the previous day. You want to find out whether the traded volume for these stocks increases consistently for a given period.
The function calculate_runs() is available for you. This function takes two arguments: 1) the daily changes in volume, 2) a single-value of the period (number of days) for which to calculate the run.
You need to apply calculate_runs() to every column of mat_stocks in parallel, specifying five days as the period. The parallel package has been loaded for you.
Este ejercicio forma parte del curso
Parallel Programming in R
Instrucciones del ejercicio
- Export
n_daysto the cluster. - Apply
calculate_runsto each column of matrixmat_stocks. - Specify the value for the
periodargument withn_days.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
n_days <- 5
cl <- makeCluster(4)
# Export n_days to cluster
clusterExport(cl, "___", envir = environment())
# Apply calculate_runs to each column of mat_stocks
volume_runs <- ___(___, ___, ___,
# Specify value for period argument
___ = ___)
stopCluster(cl)
print(paste0("Number of ", n_days, "-day increasing runs: ", sum(volume_runs)))