本文整理汇总了Python中pyalgotrade.dataseries.aligned.datetime_aligned函数的典型用法代码示例。如果您正苦于以下问题:Python datetime_aligned函数的具体用法?Python datetime_aligned怎么用?Python datetime_aligned使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了datetime_aligned函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: multipleDatetimeAligned
def multipleDatetimeAligned(self, feed):
# in case of multiple dataseries, add multiple datatime aligned function
ds = dict()
ds[self.__instrumentList[0]] = feed[self.__instrumentList[0]].getAdjCloseDataSeries()
for i in range(1,len(self.__instrumentList)) :
ds[self.__instrumentList[0]], ds[self.__instrumentList[i]] = \
aligned.datetime_aligned(ds[self.__instrumentList[0]], feed[self.__instrumentList[i]].getAdjCloseDataSeries())
for i in range(1,len(self.__instrumentList)) :
ds[self.__instrumentList[0]], ds[self.__instrumentList[i]] = \
aligned.datetime_aligned(ds[self.__instrumentList[0]], ds[self.__instrumentList[i]])
return ds
示例2: testIncremental_Recursive
def testIncremental_Recursive(self):
size = 20
ds1 = dataseries.SequenceDataSeries()
ds2 = dataseries.SequenceDataSeries()
ads1, ads2 = aligned.datetime_aligned(ds1, ds2)
# Align the aligned dataseries again with respect to each other.
ads1, ads2 = aligned.datetime_aligned(ads1, ads2)
now = datetime.datetime.now()
for i in range(size):
ds1.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
ds2.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
self.assertEqual(len(ads1), len(ads2))
self.assertEqual(ads1[:], ads2[:])
self.assertEqual(ads1.getDateTimes()[:], ads2.getDateTimes()[:])
示例3: __init__
def __init__(self, ds1, ds2, windowSize):
# We're going to use datetime aligned versions of the dataseries.
self.__ds1, self.__ds2 = aligned.datetime_aligned(ds1, ds2)
self.__windowSize = windowSize
self.__hedgeRatio = None
self.__spread = None
self.__spreadMean = None
self.__spreadStd = None
self.__zScore = None
示例4: testFullyAligned_Recursive
def testFullyAligned_Recursive(self):
size = 20
ds1 = dataseries.SequenceDataSeries()
ds2 = dataseries.SequenceDataSeries()
ads1, ads2 = aligned.datetime_aligned(ds1, ds2)
# Align the aligned dataseries again with respect to each other.
ads1, ads2 = aligned.datetime_aligned(ads1, ads2)
now = datetime.datetime.now()
for i in range(size):
ds1.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
ds2.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
self.assertEqual(len(ds1), len(ds2))
for ads in [ads1, ads2]:
self.assertEqual(len(ads), size)
for i in range(size):
self.assertEqual(ads.getValueAbsolute(i), i)
self.assertEqual(ads.getDateTimes()[i], now + datetime.timedelta(seconds=i))
示例5: testNotAligned_Recursive
def testNotAligned_Recursive(self):
size = 20
ds1 = dataseries.SequenceDataSeries()
ds2 = dataseries.SequenceDataSeries()
ads1, ads2 = aligned.datetime_aligned(ds1, ds2)
# Align the aligned dataseries again with respect to each other.
ads1, ads2 = aligned.datetime_aligned(ads1, ads2)
now = datetime.datetime.now()
for i in range(size):
if i % 2 == 0:
ds1.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
else:
ds2.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
self.assertEqual(len(ds1), len(ds2))
for ads in [ads1, ads2]:
self.assertEqual(ads.getLength(), 0)
self.assertEqual(ads.getFirstValidPos(), 0)
self.assertEqual(ads.getValueAbsolute(0), None)
self.assertEqual(ads.getDateTimes(), [])
示例6: testIncremental
def testIncremental(self):
size = 20
ds1 = dataseries.SequenceDataSeries()
ds2 = dataseries.SequenceDataSeries()
ads1, ads2 = aligned.datetime_aligned(ds1, ds2)
now = datetime.datetime.now()
for i in range(size):
ds1.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
ds2.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
self.assertEqual(ads1.getLength(), ads2.getLength())
self.assertEqual(ads1[:], ads2[:])
self.assertEqual(ads1.getDateTimes()[:], ads2.getDateTimes()[:])
示例7: testBoundedSources
def testBoundedSources(self):
ds1 = dataseries.SequenceDataSeries(1)
ds2 = dataseries.SequenceDataSeries(1)
ads1, ads2 = aligned.datetime_aligned(ds1, ds2)
now = datetime.datetime.now()
ds1.appendWithDateTime(now + datetime.timedelta(seconds=1), 1)
ds1.appendWithDateTime(now + datetime.timedelta(seconds=2), 2)
ds1.appendWithDateTime(now + datetime.timedelta(seconds=3), 3)
ds2.appendWithDateTime(now + datetime.timedelta(seconds=2), 2)
ds2.appendWithDateTime(now + datetime.timedelta(seconds=3), 3)
ds2.appendWithDateTime(now + datetime.timedelta(seconds=4), 4)
self.assertEqual(ads1[:], [2, 3])
self.assertEqual(ads2[:], [2, 3])
示例8: testBounded
def testBounded(self):
ds1 = dataseries.SequenceDataSeries()
ds2 = dataseries.SequenceDataSeries()
ads1, ads2 = aligned.datetime_aligned(ds1, ds2, 1)
now = datetime.datetime.now()
ds1.appendWithDateTime(now + datetime.timedelta(seconds=1), 1)
ds1.appendWithDateTime(now + datetime.timedelta(seconds=2), 2)
ds1.appendWithDateTime(now + datetime.timedelta(seconds=3), 3)
ds2.appendWithDateTime(now + datetime.timedelta(seconds=2), 2)
ds2.appendWithDateTime(now + datetime.timedelta(seconds=3), 3)
ds2.appendWithDateTime(now + datetime.timedelta(seconds=4), 4)
self.assertEqual(ads1.getValues(), [3])
self.assertEqual(ads2.getValues(), [3])
示例9: testPartiallyAligned_Recursive
def testPartiallyAligned_Recursive(self):
size = 20
commonDateTimes = []
ds1 = dataseries.SequenceDataSeries()
ds2 = dataseries.SequenceDataSeries()
ads1, ads2 = aligned.datetime_aligned(ds1, ds2)
# Align the aligned dataseries again with respect to each other.
ads1, ads2 = aligned.datetime_aligned(ads1, ads2)
now = datetime.datetime.now()
for i in range(size):
if i % 3 == 0:
commonDateTimes.append(now + datetime.timedelta(seconds=i))
ds1.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
ds2.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
elif i % 2 == 0:
ds1.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
else:
ds2.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
self.assertEqual(len(ads1), len(ads2))
self.assertEqual(ads1[:], ads2[:])
self.assertEqual(ads1.getDateTimes(), commonDateTimes)
self.assertEqual(ads2.getDateTimes(), commonDateTimes)
示例10: testNotAligned
def testNotAligned(self):
size = 20
ds1 = dataseries.SequenceDataSeries()
ds2 = dataseries.SequenceDataSeries()
ads1, ads2 = aligned.datetime_aligned(ds1, ds2)
now = datetime.datetime.now()
for i in range(size):
if i % 2 == 0:
ds1.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
else:
ds2.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
self.assertEqual(len(ds1), len(ds2))
for ads in [ads1, ads2]:
self.assertEqual(len(ads), 0)
self.assertEqual(ads.getValueAbsolute(0), None)
self.assertEqual(ads.getDateTimes(), [])
示例11: testFullyAligned
def testFullyAligned(self):
size = 20
ds1 = dataseries.SequenceDataSeries()
ds2 = dataseries.SequenceDataSeries()
ads1, ads2 = aligned.datetime_aligned(ds1, ds2)
now = datetime.datetime.now()
for i in range(size):
ds1.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
ds2.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
self.assertEqual(len(ds1), len(ds2))
for ads in [ads1, ads2]:
self.assertEqual(ads.getLength(), size)
self.assertEqual(ads.getFirstValidPos(), 0)
for i in range(size):
self.assertEqual(ads.getValueAbsolute(i), i)
self.assertEqual(ads.getDateTimes()[i], now + datetime.timedelta(seconds=i))
示例12: testPartiallyAligned
def testPartiallyAligned(self):
size = 20
commonDateTimes = []
ds1 = dataseries.SequenceDataSeries()
ds2 = dataseries.SequenceDataSeries()
ads1, ads2 = aligned.datetime_aligned(ds1, ds2)
now = datetime.datetime.now()
for i in range(size):
if i % 3 == 0:
commonDateTimes.append(now + datetime.timedelta(seconds=i))
ds1.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
ds2.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
elif i % 2 == 0:
ds1.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
else:
ds2.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
self.assertEqual(ads1.getLength(), ads2.getLength())
self.assertEqual(ads1[:], ads2[:])
self.assertEqual(ads1.getDateTimes(), commonDateTimes)
self.assertEqual(ads2.getDateTimes(), commonDateTimes)