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
How to calculate Trading Days
6 messages · Brian G. Peterson, Noah Silverman, Jeff Ryan +1 more
On Sat, 06 Nov 2010 18:35:13 -0700, Noah Silverman
<noah at smartmediacorp.com> wrote:
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.)
Each exchange has a different calendar. Most people keep a calendar in a database for each exchange they trade on. This can then be matched to the exchange meta-data for each instrument you trade. Since you seem to be using timeDate, you could take a close look at fCalendar and see if the holiday functions included there will solve your problem. A more efficient method of extracting holidays would be to generate vectors of weekends and holidays and the remove the weekends and holidays vectors from your vector of all days. Regards, - Brian
Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock
That makes perfect sense. However, using the difftimeDate function from fCalendar just gives me a count. Is there another function that will return a vector of days between two dates? Thanks! -N
On 11/7/10 8:50 AM, Brian G. Peterson wrote:
On Sat, 06 Nov 2010 18:35:13 -0700, Noah Silverman <noah at smartmediacorp.com> wrote:
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.)
Each exchange has a different calendar. Most people keep a calendar in a database for each exchange they trade on. This can then be matched to the exchange meta-data for each instrument you trade. Since you seem to be using timeDate, you could take a close look at fCalendar and see if the holiday functions included there will solve your problem. A more efficient method of extracting holidays would be to generate vectors of weekends and holidays and the remove the weekends and holidays vectors from your vector of all days. Regards, - Brian
On Sun, 07 Nov 2010 10:02:29 -0800, Noah Silverman
<noah at smartmediacorp.com> wrote:
That makes perfect sense. However, using the difftimeDate function from fCalendar just gives me a count. Is there another function that will return a vector of days between two dates?
seq.Date() and then use the fCalendar functions to sort out your holidays by financial center. - Brian
On 11/7/10 8:50 AM, Brian G. Peterson wrote:
On Sat, 06 Nov 2010 18:35:13 -0700, Noah Silverman <noah at smartmediacorp.com> wrote:
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.)
Each exchange has a different calendar. Most people keep a calendar in
a
database for each exchange they trade on. This can then be matched to the exchange meta-data for each instrument you trade. Since you seem to be using timeDate, you could take a close look at fCalendar and see if the holiday functions included there will solve
your
problem. A more efficient method of extracting holidays would be to generate vectors of weekends and holidays and the remove the weekends and
holidays
vectors from your vector of all days. Regards, - Brian
_______________________________________________ R-SIG-Finance at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20101108/6bee1869/attachment.pl>
2 days later
Hi Noah, checkout library (timeDate), especially the fns timeSequence, isBizday,holidayNYSE. - Define a calendar for your exchange (use an available one as a template, e.g. holidayNYSE) - define a sequence of days with timeSequence - subindex the sequence with isBizday using your calendar as an argument - count the length of this result Best Dan Am 07.11.2010 19:02, schrieb Noah Silverman:
That makes perfect sense. However, using the difftimeDate function from fCalendar just gives me a count. Is there another function that will return a vector of days between two dates? Thanks! -N On 11/7/10 8:50 AM, Brian G. Peterson wrote:
On Sat, 06 Nov 2010 18:35:13 -0700, Noah Silverman <noah at smartmediacorp.com> wrote:
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.)
Each exchange has a different calendar. Most people keep a calendar in a database for each exchange they trade on. This can then be matched to the exchange meta-data for each instrument you trade. Since you seem to be using timeDate, you could take a close look at fCalendar and see if the holiday functions included there will solve your problem. A more efficient method of extracting holidays would be to generate vectors of weekends and holidays and the remove the weekends and holidays vectors from your vector of all days. Regards, - Brian
_______________________________________________ R-SIG-Finance at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.