private static DateAndDefaultStandardDeviationsViewModel ConvertToViewModel(DateAndStandardDeviations model) { if (model == null) { return(null); } DateAndDefaultStandardDeviationsViewModel viewModel = new DateAndDefaultStandardDeviationsViewModel(); viewModel.DateAndNumberOfDaysUntil = Mapper.Map <DateAndNumberOfDaysUntilViewModel>(model.DateAndNumberOfDaysUntil); int cnt = model.StdDevPrices.Count; double[] stdDevPricesArr = new double[cnt * 2]; if (model.StdDevPrices != null) { for (int i = 0; i < cnt; i++) { StdDevPrices stdDevPrices = model.StdDevPrices[i]; stdDevPricesArr[cnt - i - 1] = stdDevPrices.DownPrice; stdDevPricesArr[cnt + i] = stdDevPrices.UpPrice; } } viewModel.StdDevPrices = stdDevPricesArr.ToList(); return(viewModel); }
private List <DateAndStandardDeviations> GetStandardDeviationsForDates(IBasicPredictionCalculationData data, Dictionary <DateAndNumberOfDaysUntil, Prediction> predictions, IReadOnlyList <double> deviations) { List <DateAndStandardDeviations> stdDevs = new List <DateAndStandardDeviations>(predictions.Count); List <StdDevPrices> sdPrices = new List <StdDevPrices>(); foreach (double dev in deviations) { sdPrices.Add(new StdDevPrices { Deviation = dev, DownPrice = data.LastPrice, UpPrice = data.LastPrice, }); } stdDevs.Add(new DateAndStandardDeviations { DateAndNumberOfDaysUntil = new DateAndNumberOfDaysUntil { FutureDate = _marketWorkTimeService.NowInMarketTimeZone.Date }, StdDevPrices = sdPrices }); foreach (KeyValuePair <DateAndNumberOfDaysUntil, Prediction> kvp in predictions) { DateAndStandardDeviations expAndStdDev = new DateAndStandardDeviations(); expAndStdDev.DateAndNumberOfDaysUntil = kvp.Key; expAndStdDev.StdDevPrices = new List <StdDevPrices>(deviations.Count); foreach (double defaultStdDev in deviations) { StdDevPrices stdDevPrices = kvp.Value.GetStdDevPrices(defaultStdDev); expAndStdDev.StdDevPrices.Add(stdDevPrices); } stdDevs.Add(expAndStdDev); } return(stdDevs); }