Esempio n. 1
0
        public static object GetCurveDefinition(
            [ExcelArgument(Name = "currency", Description = "The code of the currency")] string currency,
            [ExcelArgument(Name = "family_reference", Description = "The curve family")] string family,
            [ExcelArgument(Name = "curve_reference", Description = "The curve reference")] string reference)
        {
            if (AddIn.Client.State != System.ServiceModel.CommunicationState.Opened)
            {
                return(Resources.NotConnectedMessage);
            }

            List <CurvePoint> points;

            try
            {
                points = AddIn.Client.GetCurvePoints(currency, family, reference);
            }
            catch (CurveNotFoundException)
            {
                return(Resources.CurveNotFoundMessage);
            }

            object[,] array = new object[points.Count + 1, 5];

            array[0, 0] = "Tenor";
            array[0, 1] = "Rate";
            array[0, 2] = "IsEnabled";
            array[0, 3] = "RateCode";
            array[0, 4] = "Type";

            for (int i = 0; i < points.Count; i++)
            {
                array[i + 1, 0] = points[i].Tenor;
                array[i + 1, 1] = points[i].Rate ?? 0;
                array[i + 1, 2] = points[i].IsEnabled;
                array[i + 1, 3] = points[i].RateCode;
                array[i + 1, 4] = points[i].PointType;
            }

            return(ExcelRangeResizer.TransformToExcelRange(array));
        }
        public static object GetPriceHistory([ExcelArgument(Name = "instrument_id", Description = "The instrument Reference (either Reference or Sicovam)")] object reference,
                                             [ExcelArgument(Name = "start_date", Description = "Start Date")] DateTime startDate,
                                             [ExcelArgument(Name = "end_date", Description = "End Date")] DateTime endDate)
        {
            if (startDate == ExcelStaticData.ExcelMinDate)
            {
                startDate = DateTime.MinValue;
            }

            if (endDate == ExcelStaticData.ExcelMinDate)
            {
                endDate = DateTime.MaxValue;
            }

            if (startDate > endDate)
            {
                return(Resources.StartDateGreaterThanEndDateMessage);
            }

            if (AddIn.Client.State != System.ServiceModel.CommunicationState.Opened)
            {
                return(Resources.NotConnectedMessage);
            }

            List <PriceHistory> prices;

            try
            {
                if (reference is double)
                {
                    prices = AddIn.Client.GetPriceHistory(Convert.ToInt32(reference), startDate, endDate);
                }
                else
                {
                    prices = AddIn.Client.GetPriceHistory((string)reference, startDate, endDate);
                }
            }
            catch (InstrumentNotFoundException)
            {
                return(Resources.InstrumentNotFoundMessage);
            }

            object[,] array = new object[prices.Count + 1, 9];

            array[0, 0] = "Date";
            array[0, 1] = "First";
            array[0, 2] = "High";
            array[0, 3] = "Low";
            array[0, 4] = "Last";
            array[0, 5] = "Theoretical";
            array[0, 6] = "Bid";
            array[0, 7] = "Ask";
            array[0, 8] = "Volume";

            for (int i = 0; i < prices.Count; i++)
            {
                array[i + 1, 0] = prices[i].Date;
                array[i + 1, 1] = prices[i].First ?? 0;
                array[i + 1, 2] = prices[i].High ?? 0;
                array[i + 1, 3] = prices[i].Low ?? 0;
                array[i + 1, 4] = prices[i].Last ?? 0;
                array[i + 1, 5] = prices[i].Theoretical ?? 0;
                array[i + 1, 6] = prices[i].Bid ?? 0;
                array[i + 1, 7] = prices[i].Ask ?? 0;
                array[i + 1, 8] = prices[i].Volume ?? 0;
            }

            return(ExcelRangeResizer.TransformToExcelRange(array));
        }