mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-06 05:14:38 +08:00
Merge pull request #1234 from quantopian/variable-minute-blocks
Add test to cover new minute block logic
This commit is contained in:
@@ -373,6 +373,47 @@ class BcolzMinuteBarTestCase(TestCase):
|
||||
volume_price = self.reader.get_value(sid, second_minute, 'volume')
|
||||
self.assertEquals(10.0, volume_price)
|
||||
|
||||
def test_append_on_new_day(self):
|
||||
sid = 1
|
||||
|
||||
ohlcv = {
|
||||
'open': [2.0],
|
||||
'high': [3.0],
|
||||
'low': [1.0],
|
||||
'close': [2.0],
|
||||
'volume': [10.0]
|
||||
}
|
||||
|
||||
first_minute = self.market_opens[TEST_CALENDAR_START]
|
||||
data = DataFrame(
|
||||
data=ohlcv,
|
||||
index=[first_minute])
|
||||
self.writer.write_sid(sid, data)
|
||||
|
||||
next_day_minute = first_minute + Timedelta(days=1)
|
||||
new_data = DataFrame(
|
||||
data=ohlcv,
|
||||
index=[next_day_minute])
|
||||
self.writer.write_sid(sid, new_data)
|
||||
|
||||
second_minute = first_minute + Timedelta(minutes=1)
|
||||
|
||||
# The second minute should have been padded with zeros
|
||||
for col in ('open', 'high', 'low', 'close'):
|
||||
assert_almost_equal(
|
||||
nan, self.reader.get_value(sid, second_minute, col)
|
||||
)
|
||||
self.assertEqual(
|
||||
0, self.reader.get_value(sid, second_minute, 'volume')
|
||||
)
|
||||
|
||||
# The first day should contain US_EQUITIES_MINUTES_PER_DAY rows.
|
||||
# The second day should contain a single row.
|
||||
self.assertEqual(
|
||||
len(self.writer._ensure_ctable(sid)),
|
||||
US_EQUITIES_MINUTES_PER_DAY + 1,
|
||||
)
|
||||
|
||||
def test_write_multiple_sids(self):
|
||||
"""
|
||||
Test writing multiple sids.
|
||||
|
||||
@@ -408,9 +408,10 @@ class BcolzMinuteBarWriter(object):
|
||||
"""
|
||||
Fill sid container with empty data through the specified date.
|
||||
|
||||
e.g. if the date is two days after the last date in the sid's existing
|
||||
output, 2 x `minute_per_day` worth of zeros will be added to the
|
||||
output.
|
||||
If the last recorded trade is not at the close, then that day will be
|
||||
padded with zeros until its close. Any day after that (up to and
|
||||
including the specified date) will be padded with `minute_per_day`
|
||||
worth of zeros
|
||||
|
||||
Parameters:
|
||||
-----------
|
||||
@@ -490,7 +491,7 @@ class BcolzMinuteBarWriter(object):
|
||||
If there is no bcolz ctable yet created for the sid, create it.
|
||||
If the length of the bcolz ctable is not exactly to the date before
|
||||
the first day provided, fill the ctable with 0s up to that date.
|
||||
Writes in blocks of the size of the days times minutes per day.
|
||||
|
||||
Parameters:
|
||||
-----------
|
||||
sid : int
|
||||
@@ -523,7 +524,7 @@ class BcolzMinuteBarWriter(object):
|
||||
If there is no bcolz ctable yet created for the sid, create it.
|
||||
If the length of the bcolz ctable is not exactly to the date before
|
||||
the first day provided, fill the ctable with 0s up to that date.
|
||||
Writes in blocks of the size of the days times minutes per day.
|
||||
|
||||
Parameters:
|
||||
-----------
|
||||
sid : int
|
||||
|
||||
Reference in New Issue
Block a user