mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-11 11:16:15 +08:00
STY: Flake8
This commit is contained in:
@@ -800,9 +800,10 @@ class BcolzMinuteBarTestCase(TestCase):
|
||||
start_minute_loc = \
|
||||
default_nyse_schedule.all_execution_minutes.get_loc(minutes[0])
|
||||
minute_locs = [
|
||||
default_nyse_schedule.all_execution_minutes.get_loc(minute) \
|
||||
default_nyse_schedule.all_execution_minutes.get_loc(minute)
|
||||
- start_minute_loc
|
||||
for minute in minutes]
|
||||
for minute in minutes
|
||||
]
|
||||
|
||||
for i, col in enumerate(columns):
|
||||
for j, sid in enumerate(sids):
|
||||
|
||||
+136
-137
@@ -122,180 +122,179 @@ class NYSECalendarTestCase(ExchangeCalendarTestBase, TestCase):
|
||||
calendar_class = NYSEExchangeCalendar
|
||||
|
||||
def test_newyears(self):
|
||||
"""
|
||||
Check whether tradingcalendar contains certain dates.
|
||||
"""
|
||||
# January 2012
|
||||
# Su Mo Tu We Th Fr Sa
|
||||
# 1 2 3 4 5 6 7
|
||||
# 8 9 10 11 12 13 14
|
||||
# 15 16 17 18 19 20 21
|
||||
# 22 23 24 25 26 27 28
|
||||
# 29 30 31
|
||||
"""
|
||||
Check whether tradingcalendar contains certain dates.
|
||||
"""
|
||||
# January 2012
|
||||
# Su Mo Tu We Th Fr Sa
|
||||
# 1 2 3 4 5 6 7
|
||||
# 8 9 10 11 12 13 14
|
||||
# 15 16 17 18 19 20 21
|
||||
# 22 23 24 25 26 27 28
|
||||
# 29 30 31
|
||||
|
||||
start_dt = Timestamp('1/1/12', tz='UTC')
|
||||
end_dt = Timestamp('12/31/13', tz='UTC')
|
||||
trading_days = self.calendar.trading_days(start=start_dt,
|
||||
end=end_dt)
|
||||
start_dt = Timestamp('1/1/12', tz='UTC')
|
||||
end_dt = Timestamp('12/31/13', tz='UTC')
|
||||
trading_days = self.calendar.trading_days(start=start_dt, end=end_dt)
|
||||
|
||||
day_after_new_years_sunday = datetime(
|
||||
2012, 1, 2, tzinfo=pytz.utc)
|
||||
day_after_new_years_sunday = datetime(
|
||||
2012, 1, 2, tzinfo=pytz.utc)
|
||||
|
||||
self.assertNotIn(day_after_new_years_sunday,
|
||||
trading_days.index,
|
||||
"""
|
||||
self.assertNotIn(day_after_new_years_sunday,
|
||||
trading_days.index,
|
||||
"""
|
||||
If NYE falls on a weekend, {0} the Monday after is a holiday.
|
||||
""".strip().format(day_after_new_years_sunday)
|
||||
)
|
||||
)
|
||||
|
||||
first_trading_day_after_new_years_sunday = datetime(
|
||||
2012, 1, 3, tzinfo=pytz.utc)
|
||||
first_trading_day_after_new_years_sunday = datetime(
|
||||
2012, 1, 3, tzinfo=pytz.utc)
|
||||
|
||||
self.assertIn(first_trading_day_after_new_years_sunday,
|
||||
trading_days.index,
|
||||
"""
|
||||
self.assertIn(first_trading_day_after_new_years_sunday,
|
||||
trading_days.index,
|
||||
"""
|
||||
If NYE falls on a weekend, {0} the Tuesday after is the first trading day.
|
||||
""".strip().format(first_trading_day_after_new_years_sunday)
|
||||
)
|
||||
)
|
||||
|
||||
# January 2013
|
||||
# Su Mo Tu We Th Fr Sa
|
||||
# 1 2 3 4 5
|
||||
# 6 7 8 9 10 11 12
|
||||
# 13 14 15 16 17 18 19
|
||||
# 20 21 22 23 24 25 26
|
||||
# 27 28 29 30 31
|
||||
# January 2013
|
||||
# Su Mo Tu We Th Fr Sa
|
||||
# 1 2 3 4 5
|
||||
# 6 7 8 9 10 11 12
|
||||
# 13 14 15 16 17 18 19
|
||||
# 20 21 22 23 24 25 26
|
||||
# 27 28 29 30 31
|
||||
|
||||
new_years_day = datetime(
|
||||
2013, 1, 1, tzinfo=pytz.utc)
|
||||
new_years_day = datetime(
|
||||
2013, 1, 1, tzinfo=pytz.utc)
|
||||
|
||||
self.assertNotIn(new_years_day,
|
||||
trading_days.index,
|
||||
"""
|
||||
self.assertNotIn(new_years_day,
|
||||
trading_days.index,
|
||||
"""
|
||||
If NYE falls during the week, e.g. {0}, it is a holiday.
|
||||
""".strip().format(new_years_day)
|
||||
)
|
||||
)
|
||||
|
||||
first_trading_day_after_new_years = datetime(
|
||||
2013, 1, 2, tzinfo=pytz.utc)
|
||||
first_trading_day_after_new_years = datetime(
|
||||
2013, 1, 2, tzinfo=pytz.utc)
|
||||
|
||||
self.assertIn(first_trading_day_after_new_years,
|
||||
trading_days.index,
|
||||
"""
|
||||
self.assertIn(first_trading_day_after_new_years,
|
||||
trading_days.index,
|
||||
"""
|
||||
If the day after NYE falls during the week, {0} \
|
||||
is the first trading day.
|
||||
""".strip().format(first_trading_day_after_new_years)
|
||||
)
|
||||
)
|
||||
|
||||
def test_thanksgiving(self):
|
||||
"""
|
||||
Check tradingcalendar Thanksgiving dates.
|
||||
"""
|
||||
# November 2005
|
||||
# Su Mo Tu We Th Fr Sa
|
||||
# 1 2 3 4 5
|
||||
# 6 7 8 9 10 11 12
|
||||
# 13 14 15 16 17 18 19
|
||||
# 20 21 22 23 24 25 26
|
||||
# 27 28 29 30
|
||||
"""
|
||||
Check tradingcalendar Thanksgiving dates.
|
||||
"""
|
||||
# November 2005
|
||||
# Su Mo Tu We Th Fr Sa
|
||||
# 1 2 3 4 5
|
||||
# 6 7 8 9 10 11 12
|
||||
# 13 14 15 16 17 18 19
|
||||
# 20 21 22 23 24 25 26
|
||||
# 27 28 29 30
|
||||
|
||||
start_dt = Timestamp('1/1/05', tz='UTC')
|
||||
end_dt = Timestamp('12/31/12', tz='UTC')
|
||||
trading_days = self.calendar.trading_days(start=start_dt,
|
||||
end=end_dt)
|
||||
start_dt = Timestamp('1/1/05', tz='UTC')
|
||||
end_dt = Timestamp('12/31/12', tz='UTC')
|
||||
trading_days = self.calendar.trading_days(start=start_dt,
|
||||
end=end_dt)
|
||||
|
||||
thanksgiving_with_four_weeks = datetime(
|
||||
2005, 11, 24, tzinfo=pytz.utc)
|
||||
thanksgiving_with_four_weeks = datetime(
|
||||
2005, 11, 24, tzinfo=pytz.utc)
|
||||
|
||||
self.assertNotIn(thanksgiving_with_four_weeks,
|
||||
trading_days.index,
|
||||
"""
|
||||
self.assertNotIn(thanksgiving_with_four_weeks,
|
||||
trading_days.index,
|
||||
"""
|
||||
If Nov has 4 Thursdays, {0} Thanksgiving is the last Thursady.
|
||||
""".strip().format(thanksgiving_with_four_weeks)
|
||||
)
|
||||
)
|
||||
|
||||
# November 2006
|
||||
# Su Mo Tu We Th Fr Sa
|
||||
# 1 2 3 4
|
||||
# 5 6 7 8 9 10 11
|
||||
# 12 13 14 15 16 17 18
|
||||
# 19 20 21 22 23 24 25
|
||||
# 26 27 28 29 30
|
||||
thanksgiving_with_five_weeks = datetime(
|
||||
2006, 11, 23, tzinfo=pytz.utc)
|
||||
# November 2006
|
||||
# Su Mo Tu We Th Fr Sa
|
||||
# 1 2 3 4
|
||||
# 5 6 7 8 9 10 11
|
||||
# 12 13 14 15 16 17 18
|
||||
# 19 20 21 22 23 24 25
|
||||
# 26 27 28 29 30
|
||||
thanksgiving_with_five_weeks = datetime(
|
||||
2006, 11, 23, tzinfo=pytz.utc)
|
||||
|
||||
self.assertNotIn(thanksgiving_with_five_weeks,
|
||||
trading_days.index,
|
||||
"""
|
||||
self.assertNotIn(thanksgiving_with_five_weeks,
|
||||
trading_days.index,
|
||||
"""
|
||||
If Nov has 5 Thursdays, {0} Thanksgiving is not the last week.
|
||||
""".strip().format(thanksgiving_with_five_weeks)
|
||||
)
|
||||
)
|
||||
|
||||
first_trading_day_after_new_years_sunday = datetime(
|
||||
2012, 1, 3, tzinfo=pytz.utc)
|
||||
first_trading_day_after_new_years_sunday = datetime(
|
||||
2012, 1, 3, tzinfo=pytz.utc)
|
||||
|
||||
self.assertIn(first_trading_day_after_new_years_sunday,
|
||||
trading_days.index,
|
||||
"""
|
||||
self.assertIn(first_trading_day_after_new_years_sunday,
|
||||
trading_days.index,
|
||||
"""
|
||||
If NYE falls on a weekend, {0} the Tuesday after is the first trading day.
|
||||
""".strip().format(first_trading_day_after_new_years_sunday)
|
||||
)
|
||||
)
|
||||
|
||||
def test_day_after_thanksgiving(self):
|
||||
# November 2012
|
||||
# Su Mo Tu We Th Fr Sa
|
||||
# 1 2 3
|
||||
# 4 5 6 7 8 9 10
|
||||
# 11 12 13 14 15 16 17
|
||||
# 18 19 20 21 22 23 24
|
||||
# 25 26 27 28 29 30
|
||||
fourth_friday_open = Timestamp('11/23/2012 11:00AM', tz='EST')
|
||||
fourth_friday = Timestamp('11/23/2012 3:00PM', tz='EST')
|
||||
self.assertTrue(self.calendar.is_open_on_minute(fourth_friday_open))
|
||||
self.assertFalse(self.calendar.is_open_on_minute(fourth_friday))
|
||||
# November 2012
|
||||
# Su Mo Tu We Th Fr Sa
|
||||
# 1 2 3
|
||||
# 4 5 6 7 8 9 10
|
||||
# 11 12 13 14 15 16 17
|
||||
# 18 19 20 21 22 23 24
|
||||
# 25 26 27 28 29 30
|
||||
fourth_friday_open = Timestamp('11/23/2012 11:00AM', tz='EST')
|
||||
fourth_friday = Timestamp('11/23/2012 3:00PM', tz='EST')
|
||||
self.assertTrue(self.calendar.is_open_on_minute(fourth_friday_open))
|
||||
self.assertFalse(self.calendar.is_open_on_minute(fourth_friday))
|
||||
|
||||
# November 2013
|
||||
# Su Mo Tu We Th Fr Sa
|
||||
# 1 2
|
||||
# 3 4 5 6 7 8 9
|
||||
# 10 11 12 13 14 15 16
|
||||
# 17 18 19 20 21 22 23
|
||||
# 24 25 26 27 28 29 30
|
||||
fifth_friday_open = Timestamp('11/29/2013 11:00AM', tz='EST')
|
||||
fifth_friday = Timestamp('11/29/2013 3:00PM', tz='EST')
|
||||
self.assertTrue(self.calendar.is_open_on_minute(fifth_friday_open))
|
||||
self.assertFalse(self.calendar.is_open_on_minute(fifth_friday))
|
||||
# November 2013
|
||||
# Su Mo Tu We Th Fr Sa
|
||||
# 1 2
|
||||
# 3 4 5 6 7 8 9
|
||||
# 10 11 12 13 14 15 16
|
||||
# 17 18 19 20 21 22 23
|
||||
# 24 25 26 27 28 29 30
|
||||
fifth_friday_open = Timestamp('11/29/2013 11:00AM', tz='EST')
|
||||
fifth_friday = Timestamp('11/29/2013 3:00PM', tz='EST')
|
||||
self.assertTrue(self.calendar.is_open_on_minute(fifth_friday_open))
|
||||
self.assertFalse(self.calendar.is_open_on_minute(fifth_friday))
|
||||
|
||||
def test_early_close_independence_day_thursday(self):
|
||||
"""
|
||||
Until 2013, the market closed early the Friday after an
|
||||
Independence Day on Thursday. Since then, the early close is on
|
||||
Wednesday.
|
||||
"""
|
||||
# July 2002
|
||||
# Su Mo Tu We Th Fr Sa
|
||||
# 1 2 3 4 5 6
|
||||
# 7 8 9 10 11 12 13
|
||||
# 14 15 16 17 18 19 20
|
||||
# 21 22 23 24 25 26 27
|
||||
# 28 29 30 31
|
||||
wednesday_before = Timestamp('7/3/2002 3:00PM', tz='EST')
|
||||
friday_after_open = Timestamp('7/5/2002 11:00AM', tz='EST')
|
||||
friday_after = Timestamp('7/5/2002 3:00PM', tz='EST')
|
||||
self.assertTrue(self.calendar.is_open_on_minute(wednesday_before))
|
||||
self.assertTrue(self.calendar.is_open_on_minute(friday_after_open))
|
||||
self.assertFalse(self.calendar.is_open_on_minute(friday_after))
|
||||
"""
|
||||
Until 2013, the market closed early the Friday after an
|
||||
Independence Day on Thursday. Since then, the early close is on
|
||||
Wednesday.
|
||||
"""
|
||||
# July 2002
|
||||
# Su Mo Tu We Th Fr Sa
|
||||
# 1 2 3 4 5 6
|
||||
# 7 8 9 10 11 12 13
|
||||
# 14 15 16 17 18 19 20
|
||||
# 21 22 23 24 25 26 27
|
||||
# 28 29 30 31
|
||||
wednesday_before = Timestamp('7/3/2002 3:00PM', tz='EST')
|
||||
friday_after_open = Timestamp('7/5/2002 11:00AM', tz='EST')
|
||||
friday_after = Timestamp('7/5/2002 3:00PM', tz='EST')
|
||||
self.assertTrue(self.calendar.is_open_on_minute(wednesday_before))
|
||||
self.assertTrue(self.calendar.is_open_on_minute(friday_after_open))
|
||||
self.assertFalse(self.calendar.is_open_on_minute(friday_after))
|
||||
|
||||
# July 2013
|
||||
# Su Mo Tu We Th Fr Sa
|
||||
# 1 2 3 4 5 6
|
||||
# 7 8 9 10 11 12 13
|
||||
# 14 15 16 17 18 19 20
|
||||
# 21 22 23 24 25 26 27
|
||||
# 28 29 30 31
|
||||
wednesday_before = Timestamp('7/3/2013 3:00PM', tz='EST')
|
||||
friday_after_open = Timestamp('7/5/2013 11:00AM', tz='EST')
|
||||
friday_after = Timestamp('7/5/2013 3:00PM', tz='EST')
|
||||
self.assertFalse(self.calendar.is_open_on_minute(wednesday_before))
|
||||
self.assertTrue(self.calendar.is_open_on_minute(friday_after_open))
|
||||
self.assertTrue(self.calendar.is_open_on_minute(friday_after))
|
||||
# July 2013
|
||||
# Su Mo Tu We Th Fr Sa
|
||||
# 1 2 3 4 5 6
|
||||
# 7 8 9 10 11 12 13
|
||||
# 14 15 16 17 18 19 20
|
||||
# 21 22 23 24 25 26 27
|
||||
# 28 29 30 31
|
||||
wednesday_before = Timestamp('7/3/2013 3:00PM', tz='EST')
|
||||
friday_after_open = Timestamp('7/5/2013 11:00AM', tz='EST')
|
||||
friday_after = Timestamp('7/5/2013 3:00PM', tz='EST')
|
||||
self.assertFalse(self.calendar.is_open_on_minute(wednesday_before))
|
||||
self.assertTrue(self.calendar.is_open_on_minute(friday_after_open))
|
||||
self.assertTrue(self.calendar.is_open_on_minute(friday_after))
|
||||
|
||||
@@ -680,9 +680,9 @@ class MinuteEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
# since asset2 and asset3 both started trading on 1/5/2015, let's do
|
||||
# some history windows that are completely before that
|
||||
minutes = default_nyse_schedule.execution_minutes_for_day(
|
||||
default_nyse_schedule.previous_execution_day(
|
||||
pd.Timestamp('2015-01-05', tz='UTC')
|
||||
)
|
||||
default_nyse_schedule.previous_execution_day(pd.Timestamp(
|
||||
'2015-01-05', tz='UTC'
|
||||
))
|
||||
)[0:60]
|
||||
|
||||
for idx, minute in enumerate(minutes):
|
||||
@@ -1108,9 +1108,9 @@ class MinuteEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
|
||||
asset1_minutes = \
|
||||
default_nyse_schedule.execution_minutes_for_days_in_range(
|
||||
start=self.ASSET1.start_date,
|
||||
end=self.ASSET1.end_date
|
||||
)
|
||||
start=self.ASSET1.start_date,
|
||||
end=self.ASSET1.end_date
|
||||
)
|
||||
|
||||
asset1_idx = asset1_minutes.searchsorted(
|
||||
default_nyse_schedule.start_and_end(day)[0]
|
||||
@@ -1645,7 +1645,9 @@ class DailyEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
# trading_start is 2/3/2014
|
||||
# get a history window that starts before that, and ends after that
|
||||
|
||||
second_day = default_nyse_schedule.next_execution_day(self.TRADING_START_DT)
|
||||
second_day = default_nyse_schedule.next_execution_day(
|
||||
self.TRADING_START_DT
|
||||
)
|
||||
|
||||
exp_msg = (
|
||||
'History window extends before 2014-01-03. To use this history '
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import datetime
|
||||
from functools import partial
|
||||
from inspect import isabstract
|
||||
import random
|
||||
from unittest import TestCase
|
||||
@@ -240,7 +239,6 @@ class RuleTestCase(TestCase):
|
||||
cls.after_open = AfterOpen(hours=1, minutes=5)
|
||||
cls.class_ = None # Mark that this is the base class.
|
||||
|
||||
|
||||
def test_completeness(self):
|
||||
"""
|
||||
Tests that all rules are being tested.
|
||||
|
||||
Reference in New Issue
Block a user