D
DoctorWhoKnew
Guest
I want to merge a DateType instance and a decimal instance into a Moving Average instance.
I created a poco file for a type MovingAverage
public class MovingAverage
{
private IEnumerable<DateTime> stockDates;
private IEnumerable<decimal> stockClosing;
private DateTime movingAverageDate;
private decimal simpleMovingAverage;
public MovingAverage(IEnumerable<DateTime> stockDates, IEnumerable<decimal> stockClosing)
{
this.stockDates = stockDates;
this.stockClosing = stockClosing;
}
public MovingAverage(DateTime movingAverageDate, decimal simpleMovingAverage)
{
this.movingAverageDate = movingAverageDate;
this.simpleMovingAverage = simpleMovingAverage;
}
DateTime Date { get; set; }
decimal Close { get; set; }
}
This is my failed attempt to merge a Datetime and decimal into a MovingAverage object:
private static IEnumerable<MovingAverage> SimpleMovingAverage(
IEnumerable<IexTradingStock> queue, int period)
{
// Create a copy of the queue, using the ToArray method and the
// constructor that accepts an IEnumerable<T>.
Queue<IexTradingStock> queueCopy = new Queue<IexTradingStock>(queue.ToArray());
Queue<IexTradingStock> sample = new Queue<IexTradingStock>(period);
IexTradingStock iexTradingStock;
Queue<MovingAverage> movingAverages;
DateTime MovingAverageDate;
MovingAverage movingAverage;
decimal MovingAverageSum = 0;
// Make the source copy queue a factor of the period
int RemoveRemainder = queueCopy.Count % period;
// dequeue RemoveRemainder to make queue copy factor of ten
for (int index = 0; index < RemoveRemainder; index++)
{
queueCopy.Dequeue();
Console.WriteLine($"new remainder is is {queueCopy.Count % period}");
}
// calculate the first SMA
for (int i = 0; i < period; i++)
{
iexTradingStock = queueCopy.Dequeue();
//if the date is the end period date, save it
if (i==(period-1))
{
MovingAverageDate = iexTradingStock.Date;
}
// add the previous moving average closing to the
// previous moving average closing
MovingAverageSum = +iexTradingStock.Close;
}
// find the simple moving average
decimal SimpleMovingAverage = MovingAverageSum/period;
// put the first SMA and date into the moving averages queue
MovingAverage mA = new MovingAverage(MovingAverageDate, SimpleMovingAverage); ---> error-MovingAverageDate is not defined
movingAverages.Enqueue(mA);
Continue reading...
I created a poco file for a type MovingAverage
public class MovingAverage
{
private IEnumerable<DateTime> stockDates;
private IEnumerable<decimal> stockClosing;
private DateTime movingAverageDate;
private decimal simpleMovingAverage;
public MovingAverage(IEnumerable<DateTime> stockDates, IEnumerable<decimal> stockClosing)
{
this.stockDates = stockDates;
this.stockClosing = stockClosing;
}
public MovingAverage(DateTime movingAverageDate, decimal simpleMovingAverage)
{
this.movingAverageDate = movingAverageDate;
this.simpleMovingAverage = simpleMovingAverage;
}
DateTime Date { get; set; }
decimal Close { get; set; }
}
This is my failed attempt to merge a Datetime and decimal into a MovingAverage object:
private static IEnumerable<MovingAverage> SimpleMovingAverage(
IEnumerable<IexTradingStock> queue, int period)
{
// Create a copy of the queue, using the ToArray method and the
// constructor that accepts an IEnumerable<T>.
Queue<IexTradingStock> queueCopy = new Queue<IexTradingStock>(queue.ToArray());
Queue<IexTradingStock> sample = new Queue<IexTradingStock>(period);
IexTradingStock iexTradingStock;
Queue<MovingAverage> movingAverages;
DateTime MovingAverageDate;
MovingAverage movingAverage;
decimal MovingAverageSum = 0;
// Make the source copy queue a factor of the period
int RemoveRemainder = queueCopy.Count % period;
// dequeue RemoveRemainder to make queue copy factor of ten
for (int index = 0; index < RemoveRemainder; index++)
{
queueCopy.Dequeue();
Console.WriteLine($"new remainder is is {queueCopy.Count % period}");
}
// calculate the first SMA
for (int i = 0; i < period; i++)
{
iexTradingStock = queueCopy.Dequeue();
//if the date is the end period date, save it
if (i==(period-1))
{
MovingAverageDate = iexTradingStock.Date;
}
// add the previous moving average closing to the
// previous moving average closing
MovingAverageSum = +iexTradingStock.Close;
}
// find the simple moving average
decimal SimpleMovingAverage = MovingAverageSum/period;
// put the first SMA and date into the moving averages queue
MovingAverage mA = new MovingAverage(MovingAverageDate, SimpleMovingAverage); ---> error-MovingAverageDate is not defined
movingAverages.Enqueue(mA);
Continue reading...