From 09bd2abe2f1621dc24c5646ddd17e0a7e4aa2cf5 Mon Sep 17 00:00:00 2001 From: Richard Frank Date: Sun, 21 Aug 2016 17:16:32 -0400 Subject: [PATCH 1/3] BUG: Fix and test getting all default calendars --- tests/calendars/test_trading_calendar.py | 11 ++++++++++- zipline/utils/calendars/exchange_calendar_bmf.py | 2 +- zipline/utils/calendars/exchange_calendar_lse.py | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/calendars/test_trading_calendar.py b/tests/calendars/test_trading_calendar.py index 2fdbd2b2..0357a645 100644 --- a/tests/calendars/test_trading_calendar.py +++ b/tests/calendars/test_trading_calendar.py @@ -27,6 +27,7 @@ from pandas import read_csv from pandas.tslib import Timedelta from pandas.util.testing import assert_index_equal from pytz import timezone +from toolz import concat from zipline.errors import ( CalendarNameCollision, @@ -38,7 +39,8 @@ from zipline.utils.calendars import( deregister_calendar, get_calendar, ) -from zipline.utils.calendars.calendar_utils import register_calendar_type +from zipline.utils.calendars.calendar_utils import register_calendar_type, \ + _default_calendar_factories from zipline.utils.calendars.trading_calendar import days_at_time, \ TradingCalendar @@ -119,6 +121,13 @@ class CalendarRegistrationTestCase(TestCase): self.assertNotEqual(first_dummy, second_dummy) +class DefaultsTestCase(TestCase): + def test_default_calendars(self): + for name in concat(_default_calendar_factories): + self.assertIsNotNone(get_calendar(name), + "get_calendar(%r) returned None" % name) + + class DaysAtTimeTestCase(TestCase): @parameterized.expand([ # NYSE standard day diff --git a/zipline/utils/calendars/exchange_calendar_bmf.py b/zipline/utils/calendars/exchange_calendar_bmf.py index dccbe948..96548f94 100644 --- a/zipline/utils/calendars/exchange_calendar_bmf.py +++ b/zipline/utils/calendars/exchange_calendar_bmf.py @@ -202,7 +202,7 @@ class BMFExchangeCalendar(TradingCalendar): @property def tz(self): - return timezone("America/Sao_Paolo") + return timezone("America/Sao_Paulo") @property def open_time(self): diff --git a/zipline/utils/calendars/exchange_calendar_lse.py b/zipline/utils/calendars/exchange_calendar_lse.py index d68be030..ca044917 100644 --- a/zipline/utils/calendars/exchange_calendar_lse.py +++ b/zipline/utils/calendars/exchange_calendar_lse.py @@ -27,6 +27,7 @@ MayBank = Holiday( "Early May Bank Holiday", month=5, offset=DateOffset(weekday=MO(1)), + day=1, ) # Spring bank holiday SpringBank = Holiday( From 19c9bc2f41a488763a044b02dfb9ec24830aa9a8 Mon Sep 17 00:00:00 2001 From: Richard Frank Date: Sun, 21 Aug 2016 17:17:42 -0400 Subject: [PATCH 2/3] MAINT: Removed unused holiday definitions --- .../utils/calendars/exchange_calendar_bmf.py | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/zipline/utils/calendars/exchange_calendar_bmf.py b/zipline/utils/calendars/exchange_calendar_bmf.py index 96548f94..2364b75e 100644 --- a/zipline/utils/calendars/exchange_calendar_bmf.py +++ b/zipline/utils/calendars/exchange_calendar_bmf.py @@ -1,6 +1,5 @@ from datetime import time from pandas.tseries.holiday import( - AbstractHolidayCalendar, Holiday, Easter, Day, @@ -132,43 +131,6 @@ AnoNovoSabado = Holiday( ) -class BMFHolidayCalendar(AbstractHolidayCalendar): - """ - Non-trading days for the BM&F. - - See NYSEExchangeCalendar for full description. - """ - rules = [ - ConfUniversal, - AniversarioSaoPaulo, - CarnavalSegunda, - CarnavalTerca, - SextaPaixao, - CorpusChristi, - Tiradentes, - DiaTrabalho, - Constitucionalista, - Independencia, - Aparecida, - Finados, - ProclamacaoRepublica, - ConscienciaNegra, - VesperaNatal, - Natal, - AnoNovo, - AnoNovoSabado, - ] - - -class BMFLateOpenCalendar(AbstractHolidayCalendar): - """ - Regular early close calendar for NYSE - """ - rules = [ - QuartaCinzas, - ] - - class BMFExchangeCalendar(TradingCalendar): """ Exchange calendar for BM&F BOVESPA From cb097a2b803b59766d5c652b040ef6d60ee47692 Mon Sep 17 00:00:00 2001 From: Richard Frank Date: Sun, 21 Aug 2016 17:18:09 -0400 Subject: [PATCH 3/3] DOC: Added licenses to calendar modules --- zipline/utils/calendars/exchange_calendar_bmf.py | 15 +++++++++++++++ zipline/utils/calendars/exchange_calendar_lse.py | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/zipline/utils/calendars/exchange_calendar_bmf.py b/zipline/utils/calendars/exchange_calendar_bmf.py index 2364b75e..74585453 100644 --- a/zipline/utils/calendars/exchange_calendar_bmf.py +++ b/zipline/utils/calendars/exchange_calendar_bmf.py @@ -1,3 +1,18 @@ +# +# Copyright 2016 Quantopian, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from datetime import time from pandas.tseries.holiday import( Holiday, diff --git a/zipline/utils/calendars/exchange_calendar_lse.py b/zipline/utils/calendars/exchange_calendar_lse.py index ca044917..cac6dc57 100644 --- a/zipline/utils/calendars/exchange_calendar_lse.py +++ b/zipline/utils/calendars/exchange_calendar_lse.py @@ -1,3 +1,18 @@ +# +# Copyright 2016 Quantopian, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from datetime import time from pandas.tseries.holiday import( Holiday,