Ejemplo n.º 1
0
        // idYc - each EntryPoint has reference to YieldCurve settings
        public ResponseEntryPointHistory GetYcHistoricEntryPoints(DateTime settlementDate, YieldCurveDefinition ycDef)
        {
            ResponseEntryPointHistory result = new ResponseEntryPointHistory();

            try
            {
                UserAccounts.FCUser user = (UserAccounts.FCUser)HttpContext.Current.Session["user"];
                if (user == null)
                {
                    result.Error         = new CustomException();
                    result.Error.Message = "Client is not authenticated, will work in Demo read-only mode";
                }
                result = GetEntryPointHistoryList(settlementDate, ycDef.Id);
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }

                result.Error         = new CustomException();
                result.Error.Message = ex.Message + ex.StackTrace;
            }
            return(result);
        }
Ejemplo n.º 2
0
        public string GetEpHistory(string date, string id)
        {
            long idYc = JsonConvert.DeserializeObject <Int32>(id);
            //DateTime settlementDate = JsonConvert.DeserializeObject<DateTime>(date);
            DateTime settlementDate = Convert.ToDateTime(date);

            ResponseEntryPointHistory tmp = GetEntryPointHistoryList(settlementDate, idYc);

            return(JsonConvert.SerializeObject(tmp));
        }
Ejemplo n.º 3
0
        static public string ToChart(ResponseEntryPointHistory eph)
        {
            List <EntryPointHistory> epHistoryList = eph.epHistoryList;

            System.Data.DataTable dt = new System.Data.DataTable();

            dt.Columns.Add("Duration", typeof(int));
            dt.Columns.Add("Rate", typeof(double));
            dt.Columns.Add("Term", typeof(string));
            dt.Columns.Add("Rate%", typeof(string));

            foreach (var i in epHistoryList)
            {
                DateTime tmp           = DateTime.Today;
                string   formattedTerm = string.Empty;

                switch (i.TimeUnit)
                {
                case "Days":
                    tmp           = tmp.AddDays(i.Length);
                    formattedTerm = String.Format("{0}d", i.Length);
                    break;

                case "Weeks":
                    tmp           = tmp.AddDays(7 * i.Length);
                    formattedTerm = String.Format("{0}w", i.Length);
                    break;

                case "Months":
                    tmp           = tmp.AddMonths(i.Length);
                    formattedTerm = String.Format("{0}m", i.Length);
                    break;

                case "Years":
                    tmp           = tmp.AddYears(i.Length);
                    formattedTerm = String.Format("{0}y", i.Length);
                    break;
                }

                //string formattedDuration = String.Format("{0}{1}", i.Length, i.TimeUnit);
                string formattedRate = String.Format("{0:p2}", i.epValue.Value);

                System.Data.DataRow r = dt.NewRow();
                r["Duration"] = i.Duration;
                r["Rate"]     = i.epValue.Value;
                r["Term"]     = formattedTerm;
                r["Rate%"]    = formattedRate;

                dt.Rows.Add(r);
            }

            string jsonStr = JsonConvert.SerializeObject(dt, Formatting.Indented);

            return(jsonStr);
        }
Ejemplo n.º 4
0
        /*
         * public string GetXRates()
         * {
         *      ResponseExchangeRateData tmp = GetXRateDic();
         *      return JsonConvert.SerializeObject(tmp);
         * }
         * ResponseExchangeRateData GetXRateDic()
         * {
         *      ResponseExchangeRateData result = new ResponseExchangeRateData();
         *
         *      try
         *      {
         *              var rates = DataLayer.Repository.GetExchangeRates();
         *
         *              foreach (var r in rates)
         *              {
         *                      if (r != null)
         *                              result.XRateDic[r.Id] = r;
         *              }
         *              DataLayer.Repository.XRateDic = result.XRateDic;
         *      }
         *      catch (Exception ex)
         *      {
         *              while (ex.InnerException != null)
         *                      ex = ex.InnerException;
         *
         *              result.Error = new CustomException();
         *              result.Error.Message = ex.Message + ex.StackTrace;
         *      }
         *
         *      return result;
         * }
         */
        public string GetEpAllHistory(string date)
        {
            //DateTime settlementDate = JsonConvert.DeserializeObject<DateTime>(date);
            DateTime settlementDate = Convert.ToDateTime(date);

            ResponseEntryPointHistory tmp = GetEntryPointHistoryList(settlementDate, null);

            var res = JsonConvert.SerializeObject(tmp);

            return(res);
        }
Ejemplo n.º 5
0
        ResponseEntryPointHistory GetEntryPointHistoryList(DateTime settlementDate, long?idYc)
        {
            ResponseEntryPointHistory result = new ResponseEntryPointHistory();

            try
            {
                result.epHistoryList = DataLayer.Repository.GetYieldCurveEntryPointHistory(idYc, settlementDate);
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }

                result.Error         = new CustomException();
                result.Error.Message = ex.Message + ex.StackTrace;
            }

            return(result);
        }
Ejemplo n.º 6
0
        public Stream GetEpHistoryChart(string date, string id)
        {
            long idYc = JsonConvert.DeserializeObject <Int32>(id);
            //DateTime settlementDate = JsonConvert.DeserializeObject<DateTime>(date);
            DateTime settlementDate = DateTime.ParseExact(date, "dd-MM-yyyy", CultureInfo.InvariantCulture);
            //settlementDate = Convert.ToDateTime(date);


            ResponseEntryPointHistory tmp = GetEntryPointHistoryList(settlementDate, idYc);
            //DataTable gdt = tmp.ToGoogleDataTable();

            string jsonStr = CEntryPointsToJson.ToChart(tmp);

            //System.Data.DataSet dataSet = new System.Data.DataSet("dataSet");
            //dataSet.Tables.Add(dt);
            //dataSet.AcceptChanges();

            WebOperationContext.Current.OutgoingResponse.ContentType =
                "application/json; charset=utf-8";
            return(new MemoryStream(Encoding.UTF8.GetBytes(jsonStr)));
        }
Ejemplo n.º 7
0
        public Stream GetEpHistoryGrid(string date, string id)
        {
            if (date == "-1" && id == "-1")
            {
                WebOperationContext.Current.OutgoingResponse.ContentType =
                    "application/json; charset=utf-8";
                return(new MemoryStream(Encoding.UTF8.GetBytes(CEntryPointsToJson.ToGrid(null))));
            }

            long idYc = JsonConvert.DeserializeObject <Int32>(id);
            //DateTime settlementDate = JsonConvert.DeserializeObject<DateTime>(date);
            DateTime settlementDate = Convert.ToDateTime(date);

            ResponseEntryPointHistory tmp = GetEntryPointHistoryList(settlementDate, idYc);

            string jsonStr = CEntryPointsToJson.ToGrid(tmp);

            WebOperationContext.Current.OutgoingResponse.ContentType =
                "application/json; charset=utf-8";
            return(new MemoryStream(Encoding.UTF8.GetBytes(jsonStr)));
        }
Ejemplo n.º 8
0
        /*
         * "rows": [
         *      {
         *              "id": 3,
         *              "cell": [
         *                      "1d",
         *                      0.87523,
         *                      "Deposit",
         *                      "LIBOR-022"
         *              ]
         *      },
         *      {}
         * ]
         */
        static public string ToGrid(ResponseEntryPointHistory eph)
        {
            if (eph == null)
            {
                return(String.Format("{\"rows\": [{ \"id\":\"\", \"cell\": [\"\", \"\", \"\", \"\"]}]}"));
            }

            List <EntryPointHistory> epHistoryList = eph.epHistoryList;

            /*
             *      "page": "1",
             *      "records": "10",
             *      "total": "2",
             */
            string jsonStr = String.Format("{{\"page\": \"{0}\", \"records\": \"{1}\", \"total\": \"{2}\", \"rows\": [",
                                           1, epHistoryList.Count, epHistoryList.Count);

            int k = 0;

            foreach (var i in epHistoryList)
            {
                DateTime tmp           = DateTime.Today;
                string   formattedTerm = string.Empty;

                switch (i.TimeUnit)
                {
                case "Days":
                    tmp           = tmp.AddDays(i.Length);
                    formattedTerm = String.Format("{0}d", i.Length);
                    break;

                case "Weeks":
                    tmp           = tmp.AddDays(7 * i.Length);
                    formattedTerm = String.Format("{0}w", i.Length);
                    break;

                case "Months":
                    tmp           = tmp.AddMonths(i.Length);
                    formattedTerm = String.Format("{0}m", i.Length);
                    break;

                case "Years":
                    tmp           = tmp.AddYears(i.Length);
                    formattedTerm = String.Format("{0}y", i.Length);
                    break;
                }

                //string formattedDuration = String.Format("{0}{1}", i.Length, i.TimeUnit);
                string formattedRate = String.Format("{0:p2}", i.epValue.Value);

                jsonStr += String.Format("{{\"id\": {0}, \"cell\": [\"{1}\", {2}, \"{3}\", \"{4}\"]}}, ",
                                         k++, formattedTerm, i.epValue.Value, i.Type, i.DataReference);

                //jsonStr += String.Format("{ \"id\": {0}, ", k);
                //jsonStr += String.Format("\"cell\": ");
                //jsonStr += String.Format("[{1}, {2}, {3}, {4}]}, ", formattedTerm, formattedRate, i.Type, i.DataReference);
            }
            jsonStr += "]}";

            //string jsonStr = JsonConvert.SerializeObject(dt, Formatting.Indented);

            return(jsonStr);
        }