updateCATickets: Update ticket's angular coefficients.

View source: R/functions.R

updateCATicketsR Documentation

Update ticket's angular coefficients.

Usage

updateCATickets(obj)

Arguments

obj

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) 
{
    tickets <- as.character(read.csv("objTickets.csv")[[1]])
    newObj <- new.env()
    count <- NROW(tickets)
    for (ticket in tickets) {
        tryCatch({
            print(ticket)
            dataRange <- obj[[ticket]][!is.na(obj[[ticket]]$Ticket), 
                ]
            newObj[[ticket]]$Date <- dataRange$Date
            newObj[[ticket]]$CA <- sapply(1:nrow(dataRange), 
                function(x) {
                  ve <- as.data.frame(dataRange[x:(x + 7), ])
                  return(summary(lm(ve$Ticket ~ index(ve$Ticket)))$coefficients[2])
                })
            print(count)
            count <- count - 1
            write.csv(newObj[[ticket]], file = paste("Analises/Tendencias/CAs/", 
                ticket, ".csv", sep = ""), row.names = FALSE)
        }, error = function(e) {
            print(paste("Error:", e))
        })
    }
    return(newObj)
  }

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