I have an empty 2D array called stockGains which I am trying to append with values of gains (the value of nextPrice/currentPrice) but I cannot seem to find an appropriate operator or method in C# to be able to append to my 2D array and complete my loop? Currently, I have incorrectly used .Add to give an example. The 2D array stockGains should be dynamically sized.
double[,] stockGains = {};
foreach (double currentPrice in pricesMonth1AsList){
// divide the nextPrice by currentPrice
double gains = ((currentPrice+1)/currentPrice);
// append the result to stockGains
stockGains.Add(gains);
// do this on repeat for every day of the month until the end of pricesMonth1Aslist
}
I have stored historical price data to be iterated over as a List<double> called pricesMonth1AsList which has each currentPrice stored as doubles sequentially from day 1 to day 30 (you can consider the index position of the list to be (day of the month - 1). nextPrice is the value of price the day after (which i have represented as currentPrice+1 in index position) example of the sample data is here:
20.35, 30.5, 40.2, 50 represents Day 1 [0], Day 2 [1], Day 3 [2], Day 4 [3]
etc
For example the first gain to be calculated would be 30.5/20.35 and then this value is to be stored as the first value in index 0 of the 2D array, the second value would be 40.2/20.35, the third would be 50/20.35 also stored in index 0 of stockGains until the last day of the month. Then repeats the process again but from day 2 onwards i.e 40.2/30.5, 50/30.5 etc gains will be stored in index 1 of stockGains.
The end goal is to find the single maximum gains value in the 2D array at the end.