[R-SIG-Finance] How to calculate trading days

Brian Rowe public_browe at muxspace.com
Sun Nov 7 19:20:57 CET 2010


Noah,

My package fractalrock has a function to calculate trading days:
?getTradingDates.

Here are some examples:

> getTradingDates('2010-11-07', obs=20)
 [1] "2010-10-11" "2010-10-12" "2010-10-13" "2010-10-14" "2010-10-15"
 [6] "2010-10-18" "2010-10-19" "2010-10-20" "2010-10-21" "2010-10-22"
[11] "2010-10-25" "2010-10-26" "2010-10-27" "2010-10-28" "2010-10-29"
[16] "2010-11-01" "2010-11-02" "2010-11-03" "2010-11-04" "2010-11-05"

> getTradingDates('2010-11-07', start='2010-10-07')
 [1] "2010-10-07" "2010-10-08" "2010-10-11" "2010-10-12" "2010-10-13"
 [6] "2010-10-14" "2010-10-15" "2010-10-18" "2010-10-19" "2010-10-20"
[11] "2010-10-21" "2010-10-22" "2010-10-25" "2010-10-26" "2010-10-27"
[16] "2010-10-28" "2010-10-29" "2010-11-01" "2010-11-02" "2010-11-03"
[21] "2010-11-04" "2010-11-05"

You can set the calendar to whatever you want. The default is the NYSE.

HTH,
Brian

> Date: Sat, 06 Nov 2010 18:35:13 -0700
> From: Noah Silverman <noah at smartmediacorp.com>
> To: r-sig-finance at stat.math.ethz.ch
> Subject: [R-SIG-Finance] How to calculate Trading Days
> Message-ID: <4CD60251.2010507 at smartmediacorp.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Hi,
>
> I'm working on some option value pricing models. Starting with the
> GBSvolatility for example.  All of the various formulas require a Time
> parameter (fraction of year) until expiration. Ideally, I want to
> compute it as:
> "trading days until expiration" / 252
>
> Give two days, I can use the difftimeDate to get the number of days
> between them, However I can't seem to find a way to get Trading Days
> (which excludes weekends and holidays.)  I've looked through rseek.org
> and many library's documentation, but can't find a way to do this.
>
> One thought would be to generate a vector of dates between the start and
> end days.  Then test EACH date to see if it was a holiday or weekend.
> This could work, but seems very inefficient.
>
> Does anyone know of a way to calculate Trading Days between two dates???
> (Surely I can't be the only person here who needs this in R.)
>
> Thanks!!!
>
> --
> Noah



More information about the R-SIG-Finance mailing list