Re: AW: joint calendar

Posted by Chak Jack Wong on
URL: http://quantlib.414.s1.nabble.com/joint-calendar-tp2345p2350.html

Hi, Jens, Luigi,
This is great.  If you can tell me the CVS file I need to update when that is in, that
will be fabulous.

There are products that need 4 calendars (EUR, Yen, GBP, $ ).  More than that, I have
never seen.
I have come across a product that is an OR rather than AND.

Jack

Jens Thiel wrote:

> Luigi, Jack,
>
> I just implemented it in C#, see below. I introduced
>
> a) the concept of a main calendar, which is also used for globalization/i18n
> stuff
> b) a Combine enumeration ("||/&& flag")
>
> Default combination is resulting in combined holidays (that is common
> business days). More than three calendars can be combined using
> CombinedCalendar like standard boolean algebra. Not tested yet...
>
> Jens.
>
> /// <summary>
> /// Calendar combining holidays or business days from two other calendars.
> /// </summary>
> [ RcsId("$Id: $") ]
> [ ComVisible(false) ]
> public sealed class CombinedCalendar : CalendarBase
> {
>         /// <summary>
>         /// Holidays / business days combination.
>         /// </summary>
>         /// <remarks>
>         /// Use to combine calendars on common business days or holidays:
>         /// <list type="table">
>         /// <listheader>
>         /// <term>Combination mode</term>
>         /// <description>Description</description>
>         /// </listheader>
>         /// <item>
>         /// <term><c>Holidays</c></term>
>         /// <description>
>         /// The resulting calendar has holidays from both calendars.
>         /// That is, in other words, only common business days.
>         /// </description>
>         /// </item>
>         /// <item>
>         /// <term><c>BusinessDays</c></term>
>         /// <description>
>         /// The resulting calendar has business days from both calendars.
>         /// That is, in other words, only common holidays.
>         /// </description>
>         /// </item>
>         /// </list>
>         /// </remarks>
>         public enum Combine
>         {
>                 /// <summary>Combine holidays of the other calendar.</summary>
>                 Holidays,
>                 /// <summary>Combine business days of the other calendar.</summary>
>                 BusinessDays
>         };
>
>         #region Constructors
>
>         /// <summary>
>         /// Combine a main calendar with holidays from another calendar.
>         /// </summary>
>         /// <param name="mainCalendar">
>         /// The main calendar (also used for globalization settings).</param>
>         /// <param name="otherCalendar">
>         /// The calendar which adds holidays to the main calendar.
>         /// </param>
>         /// <remarks>
>         /// The combined calendars use the <c>Holidays</c> enumeration from <see
> cref="Combine"/>.
>         /// The resulting name can be localized in the resource file.
>         /// </remarks>
>         public CombinedCalendar(IBusinessCalendar mainCalendar, IBusinessCalendar
> otherCalendar)
>                 : this(mainCalendar, otherCalendar,
>                 Strings.Format(null, "CalCombHol", mainCalendar, Combine.Holidays,
> otherCalendar),
>                 Combine.Holidays)
>         {}
>
>         /// <summary>
>         /// Combine a main calendar with holidays from another calendar.
>         /// </summary>
>         /// <param name="mainCalendar">
>         /// The main calendar (also used for globalization settings).</param>
>         /// <param name="otherCalendar">
>         /// The calendar which adds holidays to the main calendar.
>         /// </param>
>         /// <param name="name">
>         /// Name of the combined calendar.
>         /// </param>
>         /// <remarks>
>         /// The combined calendars use the <c>Holidays</c> enumeration from <see
> cref="Combine"/>.
>         /// </remarks>
>         public CombinedCalendar(IBusinessCalendar mainCalendar, IBusinessCalendar
> otherCalendar,
>                 string name)
>                 : this(mainCalendar, otherCalendar, name, Combine.Holidays)
>         {}
>
>         /// <summary>
>         /// Combine a main calendar with another calendar.
>         /// </summary>
>         /// <param name="mainCalendar">
>         /// The main calendar (also used for globalization settings).</param>
>         /// <param name="otherCalendar">
>         /// The calendar which adds holidays to the main calendar.
>         /// </param>
>         /// <param name="name">
>         /// Name of the combined calendar.
>         /// </param>
>         /// <param name="mode">
>         /// The combination mode of the two calendars.
>         /// </param>
>         /// <remarks>
>         /// The <see cref="Combine">combination mode</see> can be used to combine
>         /// calendars on common business days or holidays:
>         /// <list type="table">
>         /// <listheader>
>         /// <term><see cref="Combine"/> enumeration</term>
>         /// <description>Description</description>
>         /// </listheader>
>         /// <item>
>         /// <term><c>Holidays</c></term>
>         /// <description>
>         /// The resulting calendar has holidays from both calendars.
>         /// That is, in other words, only common business days.
>         /// </description>
>         /// </item>
>         /// <item>
>         /// <term><c>BusinessDays</c></term>
>         /// <description>
>         /// The resulting calendar has business days from both calendars.
>         /// That is, in other words, only common holidays.
>         /// </description>
>         /// </item>
>         /// </list>
>         /// </remarks>
>         public CombinedCalendar(IBusinessCalendar mainCalendar, IBusinessCalendar
> otherCalendar,
>                 string name, Combine mode)
>                 : base(name, mainCalendar.Culture, mainCalendar.Calendar)
>         {
>                 if( /* mainCalendar == null || */ otherCalendar == null)
>                         throw new NullReferenceException(
>                                 Strings.Get(GetType(), "CalNullRef") );
>                 this.mainCalendar = mainCalendar;
>                 this.otherCalendar = otherCalendar;
>                 this.combineBusinessDays = (mode == Combine.BusinessDays);
>         }
>
>         #endregion
>
>         private IBusinessCalendar mainCalendar;
>         private IBusinessCalendar otherCalendar;
>         private bool combineBusinessDays;
>
>         /// <summary>
>         /// Returns <c>true</c> iff the date is a business day for the given
> market.
>         /// </summary>
>         /// <param name="date">The <see cref="DateTime"/> to check.</param>
>         /// <returns><c>true</c> iff the date is a business day for the given
> market.</returns>
>         override public bool IsBusinessDay(DateTime date)
>         {
>                 bool m = mainCalendar.IsBusinessDay(date);
>                 bool o = otherCalendar.IsBusinessDay(date);
>                 // at least two of three conditions must be true
>                 return (m&&o) || (m&&combineBusinessDays) || (o&&combineBusinessDays);
>         }
> }
>
> > -----Ursprungliche Nachricht-----
> > Von: [hidden email]
> > [mailto:[hidden email]]Im Auftrag von Luigi
> > Ballabio
> > Gesendet: Montag, 27. Januar 2003 11:39
> > An: [hidden email]
> > Cc: [hidden email]
> > Betreff: Re: [Quantlib-users] joint calendar
> >
> >
> > At 08:35 AM 1/27/03 +0000, Chak Jack Wong wrote:
> > >The behavior in Jens' e-mail is exactly what we need.  This is
> > mainly used
> > >for cross-ccy swap.  for USD and Yen swap on Libor , the holiday
> > is typically
> > >NewYork, London and Tokyo (i.e. union of holiday.), and for
> > quite a lot of
> > >swiss product, we use Zurich/London.   This is rather important
> > (yet pretty
> > >simple)
> >
> > Ok, so the relation is:
> >
> > joint.isBusinessDay(d) <= c1.isBusinessDay(d) && c2.isBusinessDay(d)
> >
> > Does anybody think we might need the same thing but with ||
> > instead of && ?
> >
> > Also, I see that one might need more than two calendars. Is three the
> > maximum anybody saw, or did anybody used more complex stuff?
> >
> >
> > >Is it possible to add this simple class to the 0.3.1 release?
> >
> > Not to 0.3.1, sorry---it is already frozen. I can send you the
> > files (once
> > I have them, of course) if you have problems accessing the CVS version.
> >
> > Later,
> >          Luigi
> >
> >
> >
> > -------------------------------------------------------
> > This SF.NET email is sponsored by:
> > SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
> > http://www.vasoftware.com
> > _______________________________________________
> > Quantlib-users mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/quantlib-users
> >
> >

--
This is not an offer (or solicitation of an offer) to buy/sell the securities/instruments
mentioned or an official confirmation.  Morgan Stanley may deal as principal in or own or
act as market maker for securities/instruments mentioned or may advise the issuers.  This
may refer to a research analyst/research report. Unless indicated, these views are the
author's and may differ from those of Morgan Stanley research or others in the Firm. We do
not represent this is accurate or complete and we may not update this.  Past performance
is not indicative of future returns. For additional information, research reports and
important disclosures, contact me or see https://secure.ms.com.  You should not use email
to request, authorize or effect the purchase or sale of any security or instrument, to
send transfer instructions, or to effect any other transactions.  We cannot guarantee that
any such requests received via email will be processed in a timely manner.  This
communication is solely for the addressee(s) and may contain confidential information.  We
do not waive confidentiality by mistransmission.  Contact me if you do not wish to receive
these communications.  In the UK, this communication is directed in the UK to those
persons who are market counterparties or intermediate customers (as defined in the UK
Financial Services Authority's rules).