public ForecastResult ForecastInvestment(decimal lumpSum, decimal monthlyInvestment, int timeInMonths, decimal targetValue, RiskLevel riskLevel) { var annualGrowth = GetAnnualGrowthFigures(riskLevel); var result = new ForecastResult(); var time = DateTime.Today; var narrowBounds = new BoundedValue <decimal>(lumpSum, lumpSum); var wideBounds = new BoundedValue <decimal>(lumpSum, lumpSum); for (var i = 0; i < timeInMonths; i++) { var currentInvestment = lumpSum + (i * monthlyInvestment); var point = new ForecastPoint( time.AddMonths(i), currentInvestment, narrowBounds, wideBounds, targetValue); narrowBounds = CalculateGrowth(narrowBounds, annualGrowth.NarrowBoundsPercentage, monthlyInvestment); wideBounds = CalculateGrowth(wideBounds, annualGrowth.WideBoundsPercentage, monthlyInvestment); result.DataPoints.Add(point); } return(result); }
public ActionResult Index(string date, string modelId) { if (modelId == null) { modelId = Constants.ModelDangerAboveTreelineV1NW; } DateTime dateOfForecast = DateTime.UtcNow; if (date != null) { dateOfForecast = DateTime.ParseExact(date, "yyyyMMdd", null); } var forecastPoints = repository.ForecastPoints; //Check that we have a forecast for that date, if now get the most recent one before that var dateResult = forecastPoints.Where(p => p.PartitionKey == ForecastPoint.GeneratePartitionKey(dateOfForecast, modelId) && p.RegionName != "Unknown").Select(p => p.Date); DateTime dateToQuery = dateOfForecast; //didn't exist for that date & model combination; find the next most recent date if (dateResult.ToList().Count() == 0) { var dateResult2 = repository.ForecastDates.Select(p => p.RowKey).ToList().OrderByDescending(d => d).First(); dateToQuery = DateTime.ParseExact(dateResult2, "yyyyMMdd", null); } var result = forecastPoints.Where(p => p.PartitionKey == ForecastPoint.GeneratePartitionKey(dateToQuery, modelId) && p.RegionName != "Unknown").ToList(); if (result.Count > 0) { return(View(new ForecastViewModel(new Forecast(result)))); } else { return(RedirectToAction("Index", "Home")); } }
public void SaveForecastPoint(ForecastPoint point) { var op = TableOperation.InsertOrMerge(point); context.Table.Execute(op); }