Percentile Ranking - R

Asked

Viewed 110 times

1

I need to divide a time series into 20 equally spaced percentiles and create a ranking for that division by classifying implied volatility levels, in this case.

The time series is composed of daily data from 2011 to 2019, and the percentiles will be built in an annual period, so I’m going to look at a value at the moment t and classify it according to 20 percentiles defined from the historical series of 1 year prior to date t and if that value in t is greater than the highest value observed in the previous year, a category 21 would be created to indicate a very high level.

  • 2

    Welcome to Sopt, post in question what you have tried so far and what is your doubt as clearly as possible.

  • Hi, Filipe! I need to find out how to create this percentile ranking in a period of 1 year. I just started using R, so for this part of my dissertation, I have no idea how to start :S

1 answer

0

To create the 20 percentiles equally spaced we can use the function seq(). After that we can use the function quantile() to say the values relative to the percentiles we define.

percentis <- seq(0.05, 1, length.out = 20)
percentis
#>  [1] 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70
#> [15] 0.75 0.80 0.85 0.90 0.95 1.00

set.seed(123)
serie_temporal <- rnorm(1000)
quantile(serie_temporal, percentis)
#>           5%          10%          15%          20%          25% 
#> -1.622584310 -1.267328289 -1.049677448 -0.788690220 -0.628324243 
#>          30%          35%          40%          45%          50% 
#> -0.486452454 -0.348884728 -0.214854912 -0.097388721  0.009209639 
#>          55%          60%          65%          70%          75% 
#>  0.127070557  0.242040647  0.373732181  0.513088142  0.664601867 
#>          80%          85%          90%          95%         100% 
#>  0.841412710  1.019321461  1.254751947  1.676133871  3.241039935

Created on 2019-05-10 by the reprex package (v0.2.1)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.