本文整理汇总了Python中zipline.data.minute_bars.BcolzMinuteBarWriter.truncate方法的典型用法代码示例。如果您正苦于以下问题:Python BcolzMinuteBarWriter.truncate方法的具体用法?Python BcolzMinuteBarWriter.truncate怎么用?Python BcolzMinuteBarWriter.truncate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zipline.data.minute_bars.BcolzMinuteBarWriter
的用法示例。
在下文中一共展示了BcolzMinuteBarWriter.truncate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BcolzMinuteBarTestCase
# 需要导入模块: from zipline.data.minute_bars import BcolzMinuteBarWriter [as 别名]
# 或者: from zipline.data.minute_bars.BcolzMinuteBarWriter import truncate [as 别名]
#.........这里部分代码省略.........
with self.assertRaises(NoDataOnDate):
self.reader.get_value(
sid,
Timestamp('2015-11-30', tz='UTC'),
'open'
)
with self.assertRaises(NoDataOnDate):
self.reader.get_value(
sid,
Timestamp('2015-11-30 21:01:00', tz='UTC'),
'open'
)
def test_set_sid_attrs(self):
"""Confirm that we can set the attributes of a sid's file correctly.
"""
sid = 1
start_day = Timestamp('2015-11-27', tz='UTC')
end_day = Timestamp('2015-06-02', tz='UTC')
attrs = {
'start_day': start_day.value / int(1e9),
'end_day': end_day.value / int(1e9),
'factor': 100,
}
# Write the attributes
self.writer.set_sid_attrs(sid, **attrs)
# Read the attributes
for k, v in attrs.items():
self.assertEqual(self.reader.get_sid_attr(sid, k), v)
def test_truncate_between_data_points(self):
tds = self.market_opens.index
days = tds[tds.slice_indexer(
start=self.test_calendar_start + 1,
end=self.test_calendar_start + 3
)]
minutes = DatetimeIndex([
self.market_opens[days[0]] + timedelta(minutes=60),
self.market_opens[days[1]] + timedelta(minutes=120),
])
sid = 1
data = DataFrame(
data={
'open': [10.0, 11.0],
'high': [20.0, 21.0],
'low': [30.0, 31.0],
'close': [40.0, 41.0],
'volume': [50.0, 51.0]
},
index=minutes)
self.writer.write_sid(sid, data)
# Truncate to first day with data.
self.writer.truncate(days[0])
# Refresh the reader since truncate update the metadata.
self.reader = BcolzMinuteBarReader(self.dest)
self.assertEqual(self.writer.last_date_in_output_for_sid(sid), days[0])
cal = self.trading_calendar
_, last_close = cal.open_and_close_for_session(days[0])