[bug #37616] holidays result incorrect when New Year's Day falls on Saturday

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[bug #37616] holidays result incorrect when New Year's Day falls on Saturday

Mike Miller-5
Follow-up Comment #2, bug #37616 (project octave):

I used the wrong OF address, fixed now.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?37616>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev
Reply | Threaded
Open this post in threaded view
|

Re: [bug #37616] holidays result incorrect when New Year's Day falls on Saturday

Carnë Draug-2
On 25 October 2012 14:42, Jordi Gutiérrez Hermoso
<[hidden email]> wrote:
> Follow-up Comment #2, bug #37616 (project octave):
>
>   <http://savannah.gnu.org/bugs/?37616>

Hi Randy

Your patch may fix that problem but needs to be fixed in some other
way as it causes the other tests to fail (just run test holidays to
see what I mean). Could you please find some other way to fix it?
Also, could you please submit Octave Forge related bugs to
https://sourceforge.net/p/octave/bugs/

Thanks,
Carnë

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev
Reply | Threaded
Open this post in threaded view
|

Re: [bug #37616] holidays result incorrect when New Year's Day falls on Saturday

littlemanrkc
Hi Carnë,

After more careful inspection, it appears that when New Years Day falls on a Saturday, the holiday is not observed at all. The holidays function does not check that, so modifying line 41 will fix that (and also allow holidays to pass its test). So please disregard the previous code change suggestion, and consider the following instead.

from holidays.m:
------------------------------------------
  ## New Year's Day
  tmphol = datenum (yrs, 1, 1);
  hol = [hol; tmphol(weekday(tmphol(:)) ~= 7)(:)];
------------------------------------------
I modified the last line from
  hol = [hol; tmphol(:)];

Thanks for the link. I will submit octave-forge bugs there in the future. Should I open up a new thread there for this bug, or is that unnecessary?

-Randy Chamberlin

----- Original Message -----
From: Carnë Draug <[hidden email]>
To: Randy <[hidden email]>
Cc: Octave Forge <[hidden email]>
Sent: Thursday, October 25, 2012 10:56 PM
Subject: Re: [OctDev] [bug #37616] holidays result incorrect when New Year's Day falls on Saturday

On 25 October 2012 14:42, Jordi Gutiérrez Hermoso
<[hidden email]> wrote:
> Follow-up Comment #2, bug #37616 (project octave):
>
>   <http://savannah.gnu.org/bugs/?37616>

Hi Randy

Your patch may fix that problem but needs to be fixed in some other
way as it causes the other tests to fail (just run test holidays to
see what I mean). Could you please find some other way to fix it?
Also, could you please submit Octave Forge related bugs to
https://sourceforge.net/p/octave/bugs/

Thanks,
Carnë


------------------------------------------------------------------------------
The Windows 8 Center - In partnership with Sourceforge
Your idea - your app - 30 days.
Get started!
http://windows8center.sourceforge.net/
what-html-developers-need-to-know-about-coding-windows-8-metro-style-apps/
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev
Reply | Threaded
Open this post in threaded view
|

Re: [bug #37616] holidays result incorrect when New Year's Day falls on Saturday

Carnë Draug-2
On 26 October 2012 15:24,  <[hidden email]> wrote:

> Hi Carnë,
>
> After more careful inspection, it appears that when New Years Day falls on a Saturday, the holiday is not observed at all. The holidays function does not check that, so modifying line 41 will fix that (and also allow holidays to pass its test). So please disregard the previous code change suggestion, and consider the following instead.
>
> from holidays.m:
> ------------------------------------------
>   ## New Year's Day
>   tmphol = datenum (yrs, 1, 1);
>   hol = [hol; tmphol(weekday(tmphol(:)) ~= 7)(:)];
> ------------------------------------------
> I modified the last line from
>   hol = [hol; tmphol(:)];
>
> Thanks for the link. I will submit octave-forge bugs there in the future. Should I open up a new thread there for this bug, or is that unnecessary?
>
> -Randy Chamberlin

Hi Randy

not necessary this time. I have commited your changes see
https://sourceforge.net/p/octave/code/11368

Thank you,
Carnë

------------------------------------------------------------------------------
WINDOWS 8 is here.
Millions of people.  Your app in 30 days.
Visit The Windows 8 Center at Sourceforge for all your go to resources.
http://windows8center.sourceforge.net/
join-generation-app-and-make-money-coding-fast/
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev
Reply | Threaded
Open this post in threaded view
|

Re: [bug #37616] holidays result incorrect when New Year's Day falls on Saturday

Carnë Draug-2
On 27 October 2012 14:46, Carnë Draug <[hidden email]> wrote:

> On 26 October 2012 15:24,  <[hidden email]> wrote:
>> Hi Carnë,
>>
>> After more careful inspection, it appears that when New Years Day falls on a Saturday, the holiday is not observed at all. The holidays function does not check that, so modifying line 41 will fix that (and also allow holidays to pass its test). So please disregard the previous code change suggestion, and consider the following instead.
>>
>> from holidays.m:
>> ------------------------------------------
>>   ## New Year's Day
>>   tmphol = datenum (yrs, 1, 1);
>>   hol = [hol; tmphol(weekday(tmphol(:)) ~= 7)(:)];
>> ------------------------------------------
>> I modified the last line from
>>   hol = [hol; tmphol(:)];
>>
>> Thanks for the link. I will submit octave-forge bugs there in the future. Should I open up a new thread there for this bug, or is that unnecessary?
>>
>> -Randy Chamberlin
>
> Hi Randy
>
> not necessary this time. I have commited your changes see
> https://sourceforge.net/p/octave/code/11368

I was taking a closer look at the function and noticed the block near
the end that is meant to adjust for sundays and saturdays.

  wd = weekday (hol);
  if any (wd == 1)
    hol(wd == 1) = hol(wd == 1) + 1;
  endif
  if any (wd == 7)
    hol(wd == 7) = hol(wd == 7) - 1;
  endif

I believe that a better fix should go in here.

Carnë

------------------------------------------------------------------------------
WINDOWS 8 is here.
Millions of people.  Your app in 30 days.
Visit The Windows 8 Center at Sourceforge for all your go to resources.
http://windows8center.sourceforge.net/
join-generation-app-and-make-money-coding-fast/
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev
Reply | Threaded
Open this post in threaded view
|

Re: [bug #37616] holidays result incorrect when New Year's Day falls on Saturday

littlemanrkc

From: Carnë Draug <[hidden email]>
To: [hidden email]
Cc: Octave Forge <[hidden email]>
Sent: Saturday, October 27, 2012 8:50 AM
Subject: Re: [OctDev] [bug #37616] holidays result incorrect when New Year's Day falls on Saturday

On 27 October 2012 14:46, Carnë Draug <carandraug+[hidden email]> wrote:

> On 26 October 2012 15:24,  <[hidden email]> wrote:
>> Hi Carnë,
>>
>> After more careful inspection, it appears that when New Years Day falls on a Saturday, the holiday is not observed at all. The holidays function does not check that, so modifying line 41 will fix that (and also allow holidays to pass its test). So please disregard the previous code change suggestion, and consider the following instead.
>>
>> from holidays.m:
>> ------------------------------------------
>>  ## New Year's Day
>>  tmphol = datenum (yrs, 1, 1);
>>  hol = [hol; tmphol(weekday(tmphol(:)) ~= 7)(:)];
>> ------------------------------------------
>> I modified the last line from
>>  hol = [hol; tmphol(:)];
>>
>> Thanks for the link. I will submit octave-forge bugs there in the future. Should I open up a new thread there for this bug, or is that unnecessary?
>>
>> -Randy Chamberlin
>
> Hi Randy
>
> not necessary this time. I have commited your changes see
> https://sourceforge.net/p/octave/code/11368

I was taking a closer look at the function and noticed the block near
the end that is meant to adjust for sundays and saturdays.

  wd = weekday (hol);
  if any (wd == 1)
    hol(wd == 1) = hol(wd == 1) + 1;
  endif
  if any (wd == 7)
    hol(wd == 7) = hol(wd == 7) - 1;
  endif

I believe that a better fix should go in here.

Carnë
----------------------

Hi Carne,

I think the problem is that according to NYSE rules, holidays are not allowed to span across a calendar year.

From the NYSE rules at http://nyserules.nyse.com/nysetools/PlatformViewer.asp?SelectedNode=chp_1_3&manual=/nyse/rules/nyse-rules/
 
"The Exchange Board has also determined that, when any holiday observed by the Exchange falls on a Saturday, the Exchange will not be open for business on the preceding Friday and when any holiday observed by the Exchange falls on a Sunday, the Exchange will not be open for business on the succeeding Monday, unless unusual business conditions exist, such as the ending of a monthly or the yearly accounting period."

So in general, Saturday holidays should be shifted to the previous Friday, and Sunday holidays to the next Monday, except when it crosses a calendar year. So I think the original logic (pre my patch) is correct, with the exception that it does not attempt to account for the case where New Years Day falls on a Saturday and crosses a yearly accounting period. In that case, the NYSE rules say it should be ignored, but the original logic alone doesn't do that. If you check the link posted in the help file for holidays (http://www.chronos-st.org/NYSE_Observed_Holidays-1885-Present.html), you can see that Saturday, Jan 1, 2005 was not observed. Since New Years Day is the only holiday that can cross "yearly account periods", the check is only required for that one holiday, and so I would argue the previous fix (line 41) is best for minimizing processor time. If you think it would be easier to read by putting a change in the weekday pruning block, I believe the following, added at line 77 would also do it:
 
## Delete any New Years Day holidays that cross calendar years
  hol(day(hol) == 31 & month(hol) == 12) = [];

This must be added after the adjustment for Saturday..


-Randy Chamberlin

------------------------------------------------------------------------------
WINDOWS 8 is here.
Millions of people.  Your app in 30 days.
Visit The Windows 8 Center at Sourceforge for all your go to resources.
http://windows8center.sourceforge.net/
join-generation-app-and-make-money-coding-fast/
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev
Reply | Threaded
Open this post in threaded view
|

Re: [bug #37616] holidays result incorrect when New Year's Day falls on Saturday

Carnë Draug-2
On 27 October 2012 16:26,  <[hidden email]> wrote:

> On 27 October 2012 14:46, Carnë Draug <[hidden email]> wrote:
>> On 26 October 2012 15:24,  <[hidden email]> wrote:
>>> Hi Carnë,
>>>
>>> After more careful inspection, it appears that when New Years Day falls
>>> on a Saturday, the holiday is not observed at all. The holidays function
>>> does not check that, so modifying line 41 will fix that (and also allow
>>> holidays to pass its test). So please disregard the previous code change
>>> suggestion, and consider the following instead.
>>>
>>> from holidays.m:
>>> ------------------------------------------
>>>  ## New Year's Day
>>>  tmphol = datenum (yrs, 1, 1);
>>>  hol = [hol; tmphol(weekday(tmphol(:)) ~= 7)(:)];
>>> ------------------------------------------
>>> I modified the last line from
>>>  hol = [hol; tmphol(:)];
>>>
>>> Thanks for the link. I will submit octave-forge bugs there in the future.
>>> Should I open up a new thread there for this bug, or is that unnecessary?
>>>
>>> -Randy Chamberlin
>>
>> Hi Randy
>>
>> not necessary this time. I have commited your changes see
>> https://sourceforge.net/p/octave/code/11368
>
> I was taking a closer look at the function and noticed the block near
> the end that is meant to adjust for sundays and saturdays.
>
>   wd = weekday (hol);
>   if any (wd == 1)
>     hol(wd == 1) = hol(wd == 1) + 1;
>   endif
>   if any (wd == 7)
>     hol(wd == 7) = hol(wd == 7) - 1;
>   endif
>
> I believe that a better fix should go in here.
>
> Carnë
> ----------------------
>
> Hi Carne,
>
> I think the problem is that according to NYSE rules, holidays are not
> allowed to span across a calendar year.
>
> From the NYSE rules at
> http://nyserules.nyse.com/nysetools/PlatformViewer.asp?SelectedNode=chp_1_3&manual=/nyse/rules/nyse-rules/
>
> "The Exchange Board has also determined that, when any holiday observed by
> the Exchange falls on a Saturday, the Exchange will not be open for business
> on the preceding Friday and when any holiday observed by the Exchange falls
> on a Sunday, the Exchange will not be open for business on the succeeding
> Monday, unless unusual business conditions exist, such as the ending of a
> monthly or the yearly accounting period."
>
> So in general, Saturday holidays should be shifted to the previous Friday,
> and Sunday holidays to the next Monday, except when it crosses a calendar
> year. So I think the original logic (pre my patch) is correct, with the
> exception that it does not attempt to account for the case where New Years
> Day falls on a Saturday and crosses a yearly accounting period. In that
> case, the NYSE rules say it should be ignored, but the original logic alone
> doesn't do that. If you check the link posted in the help file for holidays
> (http://www.chronos-st.org/NYSE_Observed_Holidays-1885-Present.html), you
> can see that Saturday, Jan 1, 2005 was not observed. Since New Years Day is
> the only holiday that can cross "yearly account periods", the check is only
> required for that one holiday, and so I would argue the previous fix (line
> 41) is best for minimizing processor time. If you think it would be easier
> to read by putting a change in the weekday pruning block, I believe the
> following, added at line 77 would also do it:
>
> ## Delete any New Years Day holidays that cross calendar years
>   hol(day(hol) == 31 & month(hol) == 12) = [];
>
> This must be added after the adjustment for Saturday..
>
> -Randy Chamberlin

Hi Randy

I think I prefer your previous fix. Anyway, for matlab compatibility,
I have added a bunch of extra "holidays" due to closing for special
occasions. This means hardcoding all dates between 1885 and 2050. The
previous code (with your fix), is used for dates outside that range. I
have also simplified the original code by removing temporary variables
(Octave can directly index output of functions).

See https://sourceforge.net/p/octave/code/11371/tree/trunk/octave-forge/main/financial/inst/holidays.m
and please give it a try.

Carnë

------------------------------------------------------------------------------
WINDOWS 8 is here.
Millions of people.  Your app in 30 days.
Visit The Windows 8 Center at Sourceforge for all your go to resources.
http://windows8center.sourceforge.net/
join-generation-app-and-make-money-coding-fast/
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev