R/clean-3-fdf_to_plotdf_f.R

Defines functions fdf_to_plotdf_f

Documented in fdf_to_plotdf_f

#' fdf_to_plotdf_f
#'
#' clean fdf to plot_df
#' Dependencies: library1(c("plyr", "dplyr", "function0"))
#' return data frame
#' @importFrom magrittr %>%
#' @param fdf fdf
#' @keywords clean fdf to plot df
#' @export
#' @examples
#' fdf_to_plotdf_f(fdf)
fdf_to_plotdf_f <- function(fdf, mod = F){
      
      if(mod){
            pdf0 <- fdf %>% dplyr::group_by(code.) %>% dplyr::mutate(firstclose = 1)
      }else{
            pdf0 <- fdf %>% dplyr::group_by(code.) %>% dplyr::mutate(firstclose = last.[1])
      }
      
      plotdf1 <- pdf0 %>% dplyr::mutate(openmod = open/last.*lastmod*firstclose,
                                highmod = high/last.*lastmod*firstclose,
                                lowmod = low/last.*lastmod*firstclose,
                                lastmod = lastmod*firstclose,
                                vwapmod = vwap/last.*lastmod*firstclose,
                                qpe = m.cap./as.numeric(l4q.net.profit)
                                )
  
      
      plotdf2 <- plotdf1 %>% dplyr::select(code = code., stock = stock., date = date, 
                                    open = openmod, 
                                    high = highmod, 
                                    low = lowmod, 
                                    close = lastmod, 
                                    vol = vol.)
      
      plot_df <- as.data.frame(plotdf2)
      
      return(plot_df)
      
}
junyitt/tfunction documentation built on May 4, 2019, 4:23 p.m.