Closed willnicolle closed 2 years ago
SOLVED - using the below code to import the outputs of the F3FF model and restructure them for the stats tests.
temp = list.files(pattern="*csv") #create list of csvs is relevant file
imp_funct2 <- function(x) { c(data <- read.csv(x, header = TRUE), data3 <- list(observed = zoo::zoo(data[,3], data[,2]),#list columns as zoo object - NOTE: Position of columns depends on your data predicted = zoo::zoo(data[,1], data[,2]), #ditto abnormal = zoo::zoo(data[,4], data[,2]), #ditto estimation_start = as.Date('2019-03-07'), #set manually estimation_end = as.Date('2019-06-12'), #set manually estimation_length = 100), #set manually class(data3) <- "returns", #define class as 'returns' return(data3)) }
securities_returns = lapply(temp, imp_funct2) #apply function to returns csvs
CARs <- car_rank_test( securities_returns, car_start = as.Date('2019-06-13'), car_end = as.Date('2019-06-27'), percentage = 90 )
Hi!,
Thanks for getting back to my email. As requested, I'm replying with my issue on here.
I have coded up a FamaFrench model on Python which is working, and I'd like to use the results in R and apply statistical tests to them from estudy2. I understand I need to create an object similar to that returned by the apply_market_model() function (ie, a list object with at least dates, normal, abnormal and predicted returns).
My question is this: How can I import the results into R (e.g. from a csv) and reformat them so that they are suitable to be passed to the parametric and non-parametric statistical tests?
I've attached some sample data (random) in the format I can export the CSVs in.
EDIT: I've got to the point where I can import all the relevant CSVs into R and reformat them as per the picture below, but the parametric/nonparametric test throws this error: _Error in if (list_of_returns[[i]]$estimation_end >= eventstart) { : argument is of length zero --> I guess I need to reformat the data so the function knows how to deal with it. Any help greatly appreciated!
Thanks, Will
ISIN3.csv ISIN2.csv ISIN1.csv
Screenshot of my object that is trying to mimic the S3 object returned by apply_market_model