本文整理汇总了C#中Slice.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# Slice.ContainsKey方法的具体用法?C# Slice.ContainsKey怎么用?C# Slice.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slice
的用法示例。
在下文中一共展示了Slice.ContainsKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnData
public override void OnData(Slice slice)
{
if (!slice.ContainsKey(Securities[_symbol1].Symbol))
{
Console.WriteLine("No " + _symbol1 + " data on " + slice.Time);
return;
}
if (!slice.ContainsKey(Securities[_symbol2].Symbol))
{
Console.WriteLine("No " + _symbol2 + " data on " + slice.Time);
return;
}
if (slice.Time.DayOfYear == _dayOfYear)
return;
else
_dayOfYear = slice.Time.DayOfYear;
var price1 = slice.Bars[_symbol1].Close;
var price2 = slice.Bars[_symbol2].Close;
if (_initialized)
{
var return1 = price1 / _lastPrice1 - 1;
var return2 = price2 / _lastPrice2 - 1;
if (return1 > return2)
{
int shortQuantity = Portfolio.Securities[_symbol1].Holdings.Quantity;
if (shortQuantity > 0)
Order(Securities[_symbol1].Symbol, -shortQuantity);
decimal actualCash = Portfolio.Cash - Portfolio.Securities[_symbol1].Holdings.Quantity * price1;
int longQuantity = Decimal.ToInt32(Math.Floor(actualCash / price2));
if (longQuantity > 0)
Order(Securities[_symbol2].Symbol, longQuantity);
}
else if (return2 > return1)
{
int shortQuantity = Portfolio.Securities[_symbol2].Holdings.Quantity;
if (shortQuantity > 0)
Order(Securities[_symbol2].Symbol, -shortQuantity);
decimal actualCash = Portfolio.Cash - Portfolio.Securities[_symbol1].Holdings.Quantity * price1;
Console.WriteLine("2>1: " + actualCash);
int longQuantity = Decimal.ToInt32(Math.Floor(actualCash / price1));
if (longQuantity > 0)
Order(Securities[_symbol1].Symbol, longQuantity);
}
}
else
_initialized = true;
_lastPrice1 = price1;
_lastPrice2 = price2;
}