public JsonResult ForwardCurveConfidence(string curve, DateTime?date, int forwardSteps, string method, int timeHorizon, double confidence, string otherParams) //such as seasonalities... etc... { DateTime dt = date ?? new DateTime(DateTime.Now.Year - 1, DateTime.Now.Month, DateTime.Now.Day); if (curve != "Natural-Gas-Futures-NYMEX") { throw new ArgumentException("Not valid cuve"); } //data is re-fetched, so nothing big is actually posted... var x = AppData.GasForwards() .OrderBy(ts => ts.Maturity) .ToList(); x = x.Where(t => dt < t.Maturity && t.Maturity <= dt.AddMonths(forwardSteps)) .ToList(); //x = x.Where(t => t.Prices.First().DateTime <= date && date <= t.Prices.Last().DateTime).ToList(); //do covariance on historical data... var data = x.Select(ts => ts.Prices .Select(p => p.Value != null ? (double)p.Value : 0) //0 for now, when interpolation is done... etc.. .ToArray()) .ToArray(); //eliminate nulls if any... var fwdCurve = x .Where(ts => ts.Prices.Count(tsValue => tsValue.DateTime == date) == 1) .Select(ts => (double)ts.Prices.Single(p => p.DateTime == date).Value).ToArray(); var confs = Simulations.curveSimulationsHistoricalConfidence(fwdCurve, data, confidence, 1.0 / 360.0); var res = new { ConfidenceLevels = new double[] { confidence }, //from highest to lowest prediction intervals Confidence = confs }; return(Json(res, JsonRequestBehavior.AllowGet)); }