I need to calculate the VaR stock returns shaft. From this post: Using the rollapply function to calculate VaR using R , I understand that columns having complete missing cases will throw an error. But since the start date and end date of the stock return for different firms are different, it creates missing values when the data is converted from long to wide format. Evaluation can be performed using only rows without missing values, but this leads to serious data loss. So, is there a way to do the calculation with columns that have complete missing values, and for missing columns, getting the output "NA". This is what I did:
library(PerformanceAnalytics) data(managers) VaR(managers, p=.95, method="modified")
It does the required calculation, but when I tried it using the first 60 rows with the “HAM6” column completely missing
managers2<-managers[1:60,] VaR(managers2, p=.95, method="modified")
I get the following error:
Error in dimnames(cd) <- list(as.character(index(x)), colnames(x)) : 'dimnames' applied to non-array
I understand that the error was caused by the missing “HAM6” column, but is there a way to save the missing columns and get the “NA” output for “HAM6” instead of deleting the “HAM6” column? I tried most of all the methods available for handling missing values, but did not find a suitable solution. Any help is greatly appreciated.
source share