I recognize this may not need to be refactored. I am simply beginning to try to employ refactoring and I failed at my attempt to do so with this line of code. I attempted to use extract method in VS2013. Alas. I use the right hand side of this line in eleven other instances.
Balance = Enumerable.Repeat(0.0, MonthsToRun).ToList();
Balance
is a double
, MonthsToRun
is an int
.
Per request:
for (int i = 0, chunksCnt = Chunks.Count; i < chunksCnt; i++)
{
if (Chunks[i].BeginDate < BeginDate) BeginDate = Chunks[i].BeginDate;
MonthsToRun = Math.Max(MonthsToRun, Utils.MonthDifference(BeginDate, Chunks[i].BeginDate) + Chunks[i].Balance.Count);
}
Balance = Enumerable.Repeat(0.0, MonthsToRun).ToList();
Default = Enumerable.Repeat(0.0, MonthsToRun).ToList();
Loss = Enumerable.Repeat(0.0, MonthsToRun).ToList();
Prepay = Enumerable.Repeat(0.0, MonthsToRun).ToList();
Principal = Enumerable.Repeat(0.0, MonthsToRun).ToList();
Interest = Enumerable.Repeat(0.0, MonthsToRun).ToList();
for (int i = 0, chunksCnt = Chunks.Count; i < chunksCnt; i++)
{
offset = Utils.MonthDifference(BeginDate, Chunks[i].BeginDate);
for (int j = offset, balanceCnt = Chunks[i].Balance.Count; j < (balanceCnt + offset); j++)
{
Balance[j] += Chunks[i].Balance[j - offset];
Default[j] += Chunks[i].Default[j - offset];
Loss[j] += Chunks[i].Loss[j - offset];
Prepay[j] += Chunks[i].Prepay[j - offset];
Principal[j] += Chunks[i].Principal[j - offset];
Interest[j] += Chunks[i].Interest[j - offset];
}
if (Settings.runBacktesting)
{
foreach (KeyValuePair<Tuple<int, int, DateTime>, double> item in Chunks[i].TransProbChunk)
{
Utils.upsertDict(TransProbAgg, item.Key, item.Value);
//Create From Status - Month Totals Dictionary to create transition rates
Tuple<int, DateTime> key = new Tuple<int, DateTime>(item.Key.Item1, item.Key.Item3);
Utils.upsertDict(fromMonthTotals, key, item.Value);
}
}
}