private List <IrFactor> GetMarginalAccumulationFactorResult() { var marginalAccumulativeFactor = new List <IrFactor>(); var cirProjections = GetCirProjectionData(); var groups = cirProjections.Select(o => o.cir_group).Distinct().ToList(); int rank = 1; double prevMonthValue = 0.0; groups.Sort(); foreach (var grp in groups) { var month0Record = new IrFactor(); month0Record.EirGroup = grp; month0Record.Rank = rank; month0Record.ProjectionMonth = 0; month0Record.ProjectionValue = 1.0; marginalAccumulativeFactor.Add(month0Record); var _cirProjection = cirProjections.Where(o => o.cir_group == grp).OrderByDescending(p => p.months).ToList(); var maxMonth = _cirProjection.Count + (_cirProjection.Count * 0.5); for (int month = 1; month < maxMonth; month++) { var row = new CIRProjections(); if (_cirProjection.Count > month) { row = _cirProjection[month - 1]; } else { row = _cirProjection.LastOrDefault(); } prevMonthValue = marginalAccumulativeFactor.FirstOrDefault(x => x.EirGroup == row.cir_group && x.ProjectionMonth == month - 1).ProjectionValue; month0Record = new IrFactor(); month0Record.EirGroup = row.cir_group; month0Record.Rank = rank; month0Record.ProjectionMonth = month; month0Record.ProjectionValue = _irFactorWorkings.ComputeProjectionValue(row.value, month, prevMonthValue, FrameworkConstants.CIR, _cirProjection.Count); marginalAccumulativeFactor.Add(month0Record); } rank += 1; } return(marginalAccumulativeFactor); }
private void RunMarginalDiscountJob(List <IrFactor> sub_marginalDiscountFactor) { var itms = new List <IrFactor>(); foreach (var row in sub_marginalDiscountFactor) { var dataRow = new IrFactor(); dataRow.EirGroup = row.EirGroup; dataRow.Rank = row.Rank; dataRow.ProjectionMonth = row.ProjectionMonth; dataRow.ProjectionValue = ComputeCummulativeProjectionValue(marginalDiscountFactor, row.EirGroup, row.ProjectionMonth); itms.Add(dataRow); } lock (cummulativeDiscountFactor) cummulativeDiscountFactor.AddRange(itms); }
public List <IrFactor> ComputeMarginalDiscountFactor() { var marginalDiscountFactor = new List <IrFactor>(); try { var eirProjection = GetEirProjectionData(); var eirProjectionCount = eirProjection.Max(o => o.months); var groups = eirProjection.Select(o => o.eir_group).Distinct(); int rank = 1; double prevMonthValue = 0.0; foreach (var grp in groups) { var month0Record = new IrFactor(); month0Record.EirGroup = grp; month0Record.Rank = rank; month0Record.ProjectionMonth = 0; month0Record.ProjectionValue = 1.0; marginalDiscountFactor.Add(month0Record); var _eirProjection = eirProjection.Where(o => o.eir_group == grp).OrderBy(p => p.months).ToList(); var maxMonth = eirProjectionCount + (eirProjectionCount * 0.5); for (int month = 1; month < maxMonth; month++) { var row = new EIRProjections(); //if (_eirProjection.Count >= month) //{ // row = _eirProjection[month - 1]; //} //else //{ // row = _eirProjection.LastOrDefault(); //} row = _eirProjection.FirstOrDefault(); //******************************************************************** prevMonthValue = marginalDiscountFactor.FirstOrDefault(x => x.EirGroup == row.eir_group && x.ProjectionMonth == month - 1).ProjectionValue; //&& x.ProjectionMonth == row.months).ProjectionValue; month0Record = new IrFactor(); month0Record.EirGroup = row.eir_group; month0Record.Rank = rank; month0Record.ProjectionMonth = month; month0Record.ProjectionValue = ComputeProjectionValue(row.value, month, prevMonthValue, EIR_TYPE, eirProjectionCount); marginalDiscountFactor.Add(month0Record); rank += 1; } } } catch (Exception ex) { Log4Net.Log.Error(ex); var cc = ex; } return(marginalDiscountFactor); }