| 1 | package Quant::Framework::VolSurface::Utils; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Quant::Framework::VolSurface::Utils | ||
| 6 | |||
| 7 | =head1 DESCRIPTION | ||
| 8 | |||
| 9 | Some general vol-related utility functions. | ||
| 10 | |||
| 11 | =head1 SYNOPSIS | ||
| 12 | |||
| 13 | my $utils = Quant::Framework::VolSurface::Utils->new; | ||
| 14 | |||
| 15 | =cut | ||
| 16 | |||
| 17 | use Moose; | ||
| 18 | |||
| 19 | use DateTime::TimeZone; | ||
| 20 | use Date::Utility; | ||
| 21 | |||
| 22 | =head2 NY1700_rollover_date_on | ||
| 23 | |||
| 24 | Returns (as a Date::Utility) the NY1700 rollover date for a given Date::Utility. | ||
| 25 | |||
| 26 | =cut | ||
| 27 | |||
| 28 | sub NY1700_rollover_date_on { | ||
| 29 | my ($self, $date) = @_; | ||
| 30 | |||
| 31 | return $date->truncate_to_day->plus_time_interval((17 - $date->timezone_offset('America/New_York')->hours) * 3600); | ||
| 32 | } | ||
| 33 | |||
| 34 | =head2 effective_date_for | ||
| 35 | |||
| 36 | Get the "effective date" for a given Date::Utility (stated in GMT). | ||
| 37 | |||
| 38 | This is the we should consider a volsurface effective for, and rolls over | ||
| 39 | every day at NY1700. If a volsurface is quoted at GMT2300, its effective | ||
| 40 | date is actually the next day. | ||
| 41 | |||
| 42 | This returns a Date::Utility truncated to midnight of the relevant day. | ||
| 43 | |||
| 44 | =cut | ||
| 45 | |||
| 46 | sub effective_date_for { | ||
| 47 | my ($self, $date) = @_; | ||
| 48 | |||
| 49 | return $date->plus_time_interval((7 + $date->timezone_offset('America/New_York')->hours) * 3600)->truncate_to_day; | ||
| 50 | } | ||
| 51 | |||
| 52 | =head2 is_before_rollover | ||
| 53 | |||
| 54 | Returns 1 if given date-time is before roll-over time. | ||
| 55 | |||
| 56 | =cut | ||
| 57 | |||
| 58 | sub is_before_rollover { | ||
| 59 | my ($self, $date) = @_; | ||
| 60 | |||
| 61 | return ($date->is_after($self->NY1700_rollover_date_on($date))) ? 0 : 1; | ||
| 62 | } | ||
| 63 | no Moose; | ||
| 64 | __PACKAGE__->meta->make_immutable; | ||
| 65 | 1; |