本文整理汇总了C#中QuantConnect.Data.BaseData.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# BaseData.GetEnumerator方法的具体用法?C# BaseData.GetEnumerator怎么用?C# BaseData.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QuantConnect.Data.BaseData
的用法示例。
在下文中一共展示了BaseData.GetEnumerator方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FillForwardHoursAtEndOfDayByHalfHour
public void FillForwardHoursAtEndOfDayByHalfHour()
{
var dataResolution = Time.OneHour;
var reference = new DateTime(2015, 6, 25, 14, 0, 0);
var data = new BaseData[]
{
// thurs 6/25
new TradeBar{Value = 0, Time = reference, Period = dataResolution},
// fri 6/26
new TradeBar{Value = 1, Time = reference.Date.AddDays(1), Period = dataResolution},
}.ToList();
var enumerator = data.GetEnumerator();
var exchange = new EquityExchange();
bool isExtendedMarketHours = false;
var ffResolution = TimeSpan.FromMinutes(30);
var fillForwardEnumerator = new FillForwardEnumerator(enumerator, exchange, ffResolution, isExtendedMarketHours, data.Last().EndTime, dataResolution);
// 3:00
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddHours(1), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
// 3:30
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddHours(1.5), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
// 4:00
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddHours(2), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
// 12:00am
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(data.Last().EndTime, fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(1, fillForwardEnumerator.Current.Value);
Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
Assert.IsFalse(fillForwardEnumerator.MoveNext());
}
示例2: FillsForwardDailyMissingDays
public void FillsForwardDailyMissingDays()
{
var dataResolution = Time.OneDay;
var reference = new DateTime(2015, 6, 25);
var data = new BaseData[]
{
// thurs 6/25
new TradeBar{Value = 0, Time = reference, Period = Time.OneDay},
// fri 6/26
new TradeBar{Value = 1, Time = reference.AddDays(5), Period = Time.OneDay},
}.ToList();
var enumerator = data.GetEnumerator();
var exchange = new EquityExchange();
bool isExtendedMarketHours = false;
var fillForwardEnumerator = new FillForwardEnumerator(enumerator, exchange, TimeSpan.FromDays(1), isExtendedMarketHours, data.Last().EndTime.AddDays(1), dataResolution);
// 6/25
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddDays(1), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
Assert.IsTrue(((TradeBar)fillForwardEnumerator.Current).Period == dataResolution);
// 6/26
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddDays(2), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
Assert.IsTrue(((TradeBar)fillForwardEnumerator.Current).Period == dataResolution);
// 6/29
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddDays(5), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
Assert.IsTrue(((TradeBar)fillForwardEnumerator.Current).Period == dataResolution);
// 6/30
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddDays(6), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(1, fillForwardEnumerator.Current.Value);
Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
Assert.IsTrue(((TradeBar)fillForwardEnumerator.Current).Period == dataResolution);
// 7/1
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddDays(7), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(1, fillForwardEnumerator.Current.Value);
Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
Assert.IsTrue(((TradeBar)fillForwardEnumerator.Current).Period == dataResolution);
Assert.IsFalse(fillForwardEnumerator.MoveNext());
}
示例3: SkipsAfterMarketData
public void SkipsAfterMarketData()
{
var dataResolution = Time.OneHour;
var reference = new DateTime(2015, 6, 25, 14, 0, 0);
var end = reference.Date.AddDays(1).AddHours(10);
var data = new BaseData[]
{
new TradeBar
{
Time = reference,
Value = 0,
Period = dataResolution
},
new TradeBar
{
Time = reference.AddHours(3),
Value = 1,
Period = dataResolution
},
new TradeBar
{
Time = reference.Date.AddDays(1).AddHours(10) - dataResolution,
Value = 2,
Period = dataResolution
}
}.ToList();
var enumerator = data.GetEnumerator();
var exchange = new EquityExchange();
bool isExtendedMarketHours = false;
var fillForwardEnumerator = new FillForwardEnumerator(enumerator, exchange, TimeSpan.FromHours(1), isExtendedMarketHours, end, dataResolution);
// 3:00
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddHours(1), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);
// 4:00 (ff)
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddHours(2), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);
// 6:00 - this is raw data, the FF enumerator doesn't try to perform filtering per se, just filtering on when to FF
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddHours(4), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(1, fillForwardEnumerator.Current.Value);
Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);
// 10:00
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(end, fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(2, fillForwardEnumerator.Current.Value);
Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);
Assert.IsFalse(fillForwardEnumerator.MoveNext());
}
示例4: FillsForwardMissingDaysOnFillForwardResolutionOfAnHour
public void FillsForwardMissingDaysOnFillForwardResolutionOfAnHour()
{
var dataResolution = Time.OneDay;
var reference = new DateTime(2015, 6, 23);
var data = new BaseData[]
{
// tues 6/23
new TradeBar{Value = 0, Time = reference, Period = dataResolution},
// wed 7/1
new TradeBar{Value = 1, Time = reference.AddDays(8), Period = dataResolution},
}.ToList();
var enumerator = data.GetEnumerator();
var exchange = new EquityExchange();
bool isExtendedMarketHours = false;
var ffResolution = TimeSpan.FromHours(1);
var fillForwardEnumerator = new FillForwardEnumerator(enumerator, exchange, ffResolution, isExtendedMarketHours, data.Last().EndTime, dataResolution);
int dailyBars = 0;
int hourlyBars = 0;
while (fillForwardEnumerator.MoveNext())
{
Console.WriteLine(fillForwardEnumerator.Current.EndTime);
if (fillForwardEnumerator.Current.Time.TimeOfDay == TimeSpan.Zero)
{
dailyBars++;
}
else
{
hourlyBars++;
}
}
// we expect 7 daily bars here, beginning tues, wed, thurs, fri, mon, tues, wed
Assert.AreEqual(7, dailyBars);
// we expect 6 days worth of ff hourly bars at 7 bars a day
Assert.AreEqual(42, hourlyBars);
}
示例5: FillsForwardHourlyOnMinutesBeginningOfDay
public void FillsForwardHourlyOnMinutesBeginningOfDay()
{
var dataResolution = Time.OneHour;
var reference = new DateTime(2015, 6, 25);
var data = new BaseData[]
{
// thurs 6/25
new TradeBar{Value = 0, Time = reference, Period = dataResolution},
// fri 6/26
new TradeBar{Value = 1, Time = reference.Date.AddHours(9), Period = dataResolution},
}.ToList();
var enumerator = data.GetEnumerator();
var exchange = new EquityExchange();
bool isExtendedMarketHours = false;
var ffResolution = TimeSpan.FromMinutes(15);
var fillForwardEnumerator = new FillForwardEnumerator(enumerator, exchange, ffResolution, isExtendedMarketHours, data.Last().EndTime, dataResolution);
// 12:00
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddHours(1), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
// 9:45 (ff)
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddHours(9.75), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
// 10:00
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddHours(10), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(1, fillForwardEnumerator.Current.Value);
Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
Assert.IsFalse(fillForwardEnumerator.MoveNext());
}
示例6: FillsForwardDailyOnHoursInMarketHours
public void FillsForwardDailyOnHoursInMarketHours()
{
var dataResolution = Time.OneDay;
var reference = new DateTime(2015, 6, 25);
var data = new BaseData[]
{
// thurs 6/25
new TradeBar{Value = 0, Time = reference, Period = Time.OneDay},
// fri 6/26
new TradeBar{Value = 1, Time = reference.AddDays(1), Period = Time.OneDay},
}.ToList();
var enumerator = data.GetEnumerator();
var exchange = new EquityExchange();
bool isExtendedMarketHours = false;
var fillForwardEnumerator = new FillForwardEnumerator(enumerator, exchange, TimeSpan.FromHours(1), isExtendedMarketHours, data.Last().EndTime, dataResolution);
// 12:00am
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddDays(1), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);
// 10:00 (ff)
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddDays(1).AddHours(10), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);
// 11:00 (ff)
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddDays(1).AddHours(11), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);
// 12:00pm (ff)
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddDays(1).AddHours(12), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);
// 1:00 (ff)
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddDays(1).AddHours(13), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);
// 2:00 (ff)
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddDays(1).AddHours(14), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);
// 3:00 (ff)
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddDays(1).AddHours(15), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);
// 4:00 (ff)
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddDays(1).AddHours(16), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);
// 12:00am
Assert.IsTrue(fillForwardEnumerator.MoveNext());
Assert.AreEqual(reference.AddDays(2), fillForwardEnumerator.Current.EndTime);
Assert.AreEqual(1, fillForwardEnumerator.Current.Value);
Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);
Assert.IsFalse(fillForwardEnumerator.MoveNext());
}