Decimal CalculateMovingAverage(DateTime day, int numDays)
{
int quantity = 0;
Decimal total = 0.0M;
DateTime firstDay = GetDateXPeriodsAgo(day, numDays);
foreach (StockInfo data in _stockData)
{
if (data.Date >= firstDay && data.Date <= day)
{
total += data.ClosingPrice;
quantity++;
}
}
return total / quantity;
}
No comments:
Post a Comment