R/strategy-2-volume_increase_df_f.R

Defines functions volume_increase_df_f

Documented in volume_increase_df_f

#' Create df that evaluates volume criteria
#'
#' s1_vol: mean volume of most recent 5 days > mean volume of past 6th to 10th days 
#' Dependencies: library0("plyr", "dplyr", "function0")
#' Return df
#' 
#' @importFrom magrittr %>%
#' @param df plot_df
#' @keywords volume criteria df
#' @export
volume_increase_df_f <- function(df = plot_df, lag1=0, lag2=5, n1=5, n2=5){
      
      summarised_df1 <- df %>% 
            dplyr::group_by(code) %>% 
            dplyr::summarise(meanvol5_0 = funlag(last.v = vol, lag = lag1, n = n1, fun = mean), 
                                                  meanvol5_5 = funlag(last.v = vol, lag = lag2, n = n2, fun = mean))
      
      
      summarised_df2 <- summarised_df1 %>% dplyr::mutate(s1_vol = as.numeric(meanvol5_0 > meanvol5_5))
      
      return(summarised_df2)

}
junyitt/tfunction documentation built on May 4, 2019, 4:23 p.m.