getPotencialGainBySector: Get potential profit gain by sector.

View source: R/functions.R

getPotencialGainBySectorR Documentation

Get potential profit gain by sector.

Usage

getPotencialGainBySector(obj, regr)

Arguments

obj
regr

Examples

##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (obj, regr) 
{
    sectors <- getSectors(regr)
    newObj <- new.env()
    df <- data.frame()
    for (sector in sectors) {
        tickets <- getTicketsBySetor(sector, regr)
        tickets <- tickets[!is.na(tickets)]
        if (!is.na(tickets[1])) {
            year <- obj[[as.character(tickets[1])]]$year
            gain <- (1:nrow(obj[[as.character(tickets[1])]])) * 
                0
            for (ticket in tickets) {
                ds <- obj[[ticket]]
                if (!is.null(ds)) {
                  for (idx in 1:nrow(ds)) {
                    gain <- gain + ds$gain
                  }
                }
            }
        }
        df <- rbind(df, data.frame(year, (gain/NROW(tickets)), 
            sector))
        newObj[[sector]] <- df
    }
    names(df) <- c("year", "gain", "sector")
    return(df)
  }

danielfhenrique789/profitmaximization documentation built on April 5, 2025, 4:05 p.m.