本文整理汇总了C#中Queue.Max方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Max方法的具体用法?C# Queue.Max怎么用?C# Queue.Max使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.Max方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateAroon
//Aroon
public static void CalculateAroon(out string key, out string key2, StockPoints data, Dictionary<DateTime, Dictionary<string, double>> indicators, int period, out int offset)
{
key = string.Format("Aroon-UP({0})", period.ToString("00"));
key2 = string.Format("Aroon-Down({0})", period.ToString("00"));
offset = period - 1;
// Aroon-Up = ((period - Days Since period-day High)/period) x 100
double up;
// Aroon-Down = ((period - Days Since period-day Low)/period) x 100
double down;
// day since 25 day high
int high;
// day since 25 day low
int low;
Queue<double> highVals = new Queue<double>();
Queue<double> lowVals = new Queue<double>();
int i = 0;
foreach(StockPoint point in data)
{
highVals.Enqueue(point.High);
lowVals.Enqueue(point.Low);
if(highVals.Count > period)
{
highVals.Dequeue();
lowVals.Dequeue();
}
if (i < period - 1)
{
i++;
}
else
{
high = period - highVals.ToList().IndexOf(highVals.Max());
low = period - highVals.ToList().IndexOf(highVals.Min());
up = ((period - high) / (double)period) * 100;
down = ((period - low) / (double)period) * 100;
AddValue(point.PointDateTime, key, up, indicators);
AddValue(point.PointDateTime, key2, down, indicators);
}
}
}
示例2: CalculateStochasticRSI
// Stochastic RSI
public static void CalculateStochasticRSI(out string key, StockPoints data, Dictionary<DateTime, Dictionary<string, double>> indicators, int period, out int offset, bool leverage = true)
{
key = string.Format("StocRSI({0})", period.ToString("00"));
ExponentialMovingAverage gains = new ExponentialMovingAverage(period);
ExponentialMovingAverage losses = new ExponentialMovingAverage(period);
offset = period * 2;
double rsi;
double stochRSI;
double highestRSI;
double lowestRSI;
Queue<double> rsiQueue = new Queue<double>();
StockPoint previousPoint = data[0];
int i = 0;
foreach (StockPoint point in data.Skip(1))
{
if (previousPoint.Close > point.Close)
{
losses.AddValue(previousPoint.Close - point.Close);
gains.AddValue(0);
}
else if (previousPoint.Close < point.Close)
{
gains.AddValue(point.Close - previousPoint.Close);
losses.AddValue(0);
}
if (i < period - 1)
{
i++;
}
else
{
rsi = 100 - (100 / (1 + (gains.MovingAverage / losses.MovingAverage)));
rsiQueue.Enqueue(rsi);
if (rsiQueue.Count > period)
{
rsiQueue.Dequeue();
}
if (rsiQueue.Count == period)
{
highestRSI = rsiQueue.Max();
lowestRSI = rsiQueue.Min();
stochRSI = (rsi - lowestRSI) / (highestRSI - lowestRSI) * (leverage ? 100 : 1);
AddValue(point.PointDateTime, key, stochRSI, indicators);
}
}
previousPoint = point;
}
}
示例3: QueueExtensions_Max_ReturnsMaxValue
public void QueueExtensions_Max_ReturnsMaxValue()
{
var queue = new Queue<Int32>();
queue.Enqueue(4);
queue.Enqueue(5);
queue.Enqueue(6);
queue.Enqueue(99);
queue.Enqueue(10);
queue.Enqueue(1);
queue.Enqueue(12);
queue.Enqueue(45);
var result = queue.Max();
TheResultingValue(result).ShouldBe(99);
}
示例4: QueueExtensions_Max_ThrowsExceptionIfQueueIsEmpty
public void QueueExtensions_Max_ThrowsExceptionIfQueueIsEmpty()
{
var queue = new Queue<Int32>();
Assert.That(() => queue.Max(),
Throws.TypeOf<InvalidOperationException>());
}
示例5: QueueExtensions_Max_ThrowsExceptionIfQueueIsEmpty
public void QueueExtensions_Max_ThrowsExceptionIfQueueIsEmpty()
{
var queue = new Queue<Int32>();
queue.Max();
}