Ejemplo n.º 1
0
        public JsonResult ForwardCurveSimulations(string curve, DateTime?date, int forwardSteps, string method,
                                                  int timeHorizon, int numberSimulations, 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 sims = Simulations.curveSimulationsHistorical(fwdCurve, data, numberSimulations, 1.0 / 360.0);

            return(Json(sims, JsonRequestBehavior.AllowGet));
        }