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.