0

I have a list consisting of 200+ observations of 200+ stock returns. I would like to divide it into three sublists according to skewness.

List 1 would include all observations of stocks, which have skewness lower than 30% quantile, List 2 would include stocks with skewness higher than 30% quantile but lower than 70% quantile and List 3 would include the rest.

So far I have computed skewness for the return of each stock, excuding the first column, which stands for date, but I dont know how to further proceed.

skew<-apply(returns[, -1], 2, skewness)

Here is the MWE

 dput(head(returns[,1:6]))
structure(list(Date = structure(c(10991, 11020, 11051, 11081, 
11112, 11142), class = "Date"), ASHTEAD.GROUP = c(-46.83, -14.55, 
-1.81999999999999, -12.27, 17.73, -10.46), BARRATT.DEVELOPMENTS = c(-57.05, 
4.91999999999999, 21.64, 15.41, -17.05, 16.07), BRITISH.LAND = c(-40.18, 
8.70000000000005, 10.98, 39.56, 12.64, -39.98), AVIVA = c(-127, 
3.5, 144.5, -50.5, 95, 78), DIAGEO = c(-55, 6.5, 89, -6, 22.5, 
46)), row.names = c(NA, 6L), class = "data.frame")
Julia
  • 241
  • 1
  • 8

1 Answers1

1

Something like this should work:

library(tidyverse)
library(e1071)
returns %>%
   tidyr::gather(stock, value, ASHTEAD.GROUP:DIAGEO) %>%
   group_by(stock) %>%
   mutate(skew = abs(skewness(value)) * 100) %>%
   ungroup() %>%
   mutate(skew_cat = cut(skew, c(0, 30, 70, 100))) %>%
   split(.$skew_cat)

Try to create a reproducible example.

mharinga
  • 1,708
  • 10
  • 23
  • It shows an error message ```Error in UseMethod("mutate_") : no applicable method for 'mutate_' applied to an object of class "c('double', 'numeric')"``` – Julia Mar 04 '20 at 14:42
  • You should include a MWE. I am not able to reproduce your error message. See: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – mharinga Mar 04 '20 at 14:56
  • I included it now – Julia Mar 05 '20 at 06:32