Percentile

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

shuchang
Posts: 29
Joined: Mon Oct 28, 2013 8:00 pm

Percentile

Postby shuchang » Sat Mar 25, 2017 1:45 am

Dear Gareth, I am using Eviews 9. Is there a way to find which percentile does an observation lie?

For example, I have the daily trading volume of the euro from 1/1/2014 to 31/12/2016. I want to see the trading volume on, eg. 1/8/2016, lies at which percentile among all the observations in the series? How do I find this?

Best,

Chang

EViews Mirza
Posts: 80
Joined: Sat Apr 22, 2017 8:23 pm

Re: Percentile

Postby EViews Mirza » Mon Apr 24, 2017 8:23 pm

Hi Chang,

There are several ways of doing this, but here's one solution.

Code: Select all

wfcreate d(1,5) 1/1/2014 12/31/2016
series trades= @rnorm
series dum = (@date>@dateval("8/1/2016"))
scalar pcntl = @sum(dum)/@obs(trades)
show pcntl


Here's what the code does line by line.

1) Generate a daily workfile from January 1, 2014 to December 31, 2016. (Notice that we are using a 5 day week definition. I'm assuming trades don't happen on the weekends.
2) Generate some random standard Gaussian numbers and call the series "trades".
3) Generate a dummy series that has a 1 whenever the date series is greater than January 8, 2016.
4) Generate a scalar that sums the dummy series, giving us the total number of days that satisfy the condition, and then divides that number by the total number of observations. That is in fact the proportion of your trading days that occur after January 8, 2016.
5) Show the value you just computed.

Now, the above is a general strategy for computing percentiles. However, for what you are seeking, you would have to sort your data first. This can be done by using the function @ranks as follows:

Code: Select all

series ranks = @ranks(trades, "a")
series dum2 = (@date=@dateval("8/1/2016"))*ranks
scalar pcntl2 = @sum(dum2)/@obs(trades)
show pcntl2


Here:

1) You sort your trading data in ascending order.
2) you create a dummy where the date is January 8, 2016 and you multiply that dummy with the series ranks. This will give you a new series with all zeroes except the rank of the trading data on that date.
3) You then compute your percentile.
4) You show your percentile.

Hope that helps.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 14 guests