http://forums.eviews.com/viewtopic.php?f=3&t=474
Here are some examples of date arithmetic in irregular workfiles.
Again, I'll assume that we are working in a daily workfile, although this time I'm assuming some days may not be included in the workfile (typically because of holidays).
I'll start with some simple examples, then tackle a quite difficult example.
First, we can easily calculate the number of days between this observation and the previous observation in the workfile:
Code: Select all
show @date-@date(-1)Code: Select all
show @datefloor(@date, "m")<>@datefloor(@date(-1), "m")Code: Select all
show @day=@minsby(@day,@datefloor(@date(-1), "m")) Code: Select all
show @datefloor(@date, "m")<>@datefloor(@date(+1), "m")Code: Select all
show @day=@maxsby(@day,@datefloor(@date(-1), "m"))Another calculation that can be useful is the number of observations in the workfile within the month containing this observation:
Code: Select all
show @sumsby(1, @datefloor(@date, "m"))Code: Select all
show @obsid-@minsby(@obsid, @datefloor(@date,"m"))Code: Select all
show @maxsby(@obsid, @datefloor(@date,"m"))-@obsidNow, to deal with a fairly difficult example, let's say that we needed to calculate the number of trading days remaining before the next option expiration date, where options expire on the third Friday of every month which can be a holiday.
The first step is to calculate the weekday number of the first day of the current month:
Code: Select all
show @datepart(@datefloor(@date,"m"),"w")Code: Select all
show (8-@mod(@datepart(@datefloor(@date,"m"),"w")+2,7))Code: Select all
show (8-@mod(@datepart(@datefloor(@date,"m"),"w")+2,7))+14Code: Select all
series lastday = (@day<=(8-@mod(@datepart(@datefloor(@date,"m"),"w")+2,7))+14 and @day(+1)> (8-@mod(@datepart(@datefloor(@date,"m"),"w")+2,7))+14)Finally, we can calculate the number of observations remaining in the workfile before the next option expiration day:
Code: Select all
show @maxsby(@obsid,@cumsum(lastday))-@obsid