NAME
Quant::Framework::TradingCalendar
DESCRIPTION
This module is responsible about everything related to time-based status of an exchange (whether exchange is open/closed, has holiday, is partially open, ...) Plus all related helper modules (trading days between two days where exchange is open, trading breaks, DST effect, open/close time, ...). One important feature of this module is that it is designed for READING information not writing.
USAGE
my $calendar = Quant::Framework::TradingCalendar->new({
symbol => 'LSE',
chronicle_reader => $chronicle_r,
});
ATTRIBUTES
symbol
The standard symbol used to reference this exchange
underlying_config
UnderlyingConfig used for query on weighting of an underlying. Not required if this modules is not used for that purpose.
locale
localization language (default is 'en')
chronicle_reader
Used to work with Chronicle storage data (Holidays and Partial trading data)
for_date
for_date is to for historical search of holiday information
holidays
The hashref mapping of the days_since_epoch of all the holidays to their descriptions or weights. If the weight is non-zero, the exchange still trades on that day.
pseudo_holidays
These are holidays defined by us. During this period, market is still open but less volatile.
trading_days
An exchange's trading day category. The list is enumerated in the exchanges_trading_days_aliases.yml file.
trading_days_list
List the trading day index which defined on exchanges_trading_days_aliases.yml
trading_timezone
The timezone in which the exchange conducts business.
This should be a string which will allow the standard DateTime modules to find the proper information.
BUILDARGS
Internal method to pre-process construction arguments
METHODS
new($symbol)
Returns object for given exchange. Accepts single parameter - exchange symbol.
simple_weight_on
Returns the weight assigned to the day of a given Date::Utility object. Return 0 if the exchange does not trade on this day and 1 if there is no pseudo-holiday.
has_holiday_on
Returns true if the exchange has a holiday on the day of a given Date::Utility object.
trades_on
Returns true if trading is done on the day of a given Date::Utility.
trade_date_after
Returns a Date::Utility for the date on which trading is open after the given Date::Utility
trading_date_for
The date on which trading is considered to be taking place even if it is not the same as the GMT date.
Returns a Date object representing midnight GMT of the trading date.
Note that this does not handle trading dates are offset forward beyond the next day (24h). It will need additional work if these are found to exist.
calendar_days_to_trade_date_after
Returns the number of calendar days between a given Date::Utility and the next day on which trading is open.
trade_date_before
Returns a Date::Utility representing the trading day before a given Date::Utility
If given the additional arg 'lookback', will look back X number of trading days, rather than just one.
trading_days_between
Returns the number of trading days _between_ two given dates.
$exchange->trading_days_between(Date::Utility->new('4-May-10'),Date::Utility->new('5-May-10'));
holiday_days_between
Returns the number of holidays _between_ two given dates.
$exchange->trading_days_between(Date::Utility->new('4-May-10'),Date::Utility->new('5-May-10'));
OPEN/CLOSED QUESTIONS ETC.
Quant::Framework::TradingCalendar can be questioned about various things related to opening/closing. The following shows all these questions via code examples:
is_open
if ($self->is_open)
is_open_at
if ($self->is_open_at($epoch))
will_open
if ($self->will_open)
will_open_after
if ($self->will_open_after($epoch))
seconds_since_open_at
my $seconds = $self->seconds_since_open_at($epoch);
seconds_since_close_at
my $seconds = $self->seconds_since_close_at($epoch);
OPENING TIMES
The following methods tell us when the exchange opens/closes on a given date.
opening_on
Returns the opening time (Date::Utility) of the exchange for a given Date::Utility.
my $opening_epoch = $exchange->opening_on(Date::Utility->new('25-Dec-10')); # returns undef (given Xmas is a holiday)
closing_on
Similar to opening_on.
my $closing_epoch = $exchange->closing_on(Date::Utility->new('25-Dec-10')); # returns undef (given Xmas is a holiday)
standard_closing_on
This is used to fetch regular non dst closing time for an exchange.
settlement_on
Similar to opening_on.
my $settlement_epoch = $exchange->settlement_on(Date::Utility->new('25-Dec-10')); # returns undef (given Xmas is a holiday)
trading_breaks
Defines the breaktime for this exchange.
is_in_trading_break
Given an epoch returns true if exchange in in break time
closes_early_on
Returns true if the exchange closes early on the given date.
opens_late_on
Returns true if the exchange opens late on the given date.
trades_normal_hours_on
Boolean which indicates if the exchange is trading in its normal hours on a given Date::Utility
regularly_adjusts_trading_hours_on
Does this Exchange always shift from regular trading hours on Dates "like" the provided Date?
is_in_dst_at
Is this exchange trading on daylight savings times for the given epoch?
seconds_of_trading_between_epochs
Get total number of seconds of trading time between two epochs accounting for breaks.
is_affected_by_dst
Tells whether the exchange's opening times change due to daylight savings at some point in the year.
closed_for_the_day
Syntatic sugar to easily identify if the exchange is closed(already closed for the day or holiday or weekend). We are not expecting any more activity in this exchange for today.
last_trading_period
Returns the last_trading_period as { begin => ..., end => ... }
regular_trading_day_after
a trading day that has no late open or early close
trading_period
Given an epoch returns the period of trading of the exchange in that day
weighted_days_in_period
Returns the sum of the weights we apply to each day in the requested period.
weight_on
Returns the weight for a given day (given as a Date::Utility object). Returns our closed weight for days when the market is closed.
closed_weight
Weights assigned for days when the markets are closed, based on empirical study and industry standards.