GetSeriesObservations() public méthode

Get the observations or data values for an economic data series. Corresponds to http://api.stlouisfed.org/fred/series/observations
public GetSeriesObservations ( string seriesId, System.DateTime observationStart, System.DateTime observationEnd, System.DateTime realtimeStart, System.DateTime realtimeEnd, IEnumerable vintageDates, int limit = 100000, int offset, SortOrder order = SortOrder.Ascending, Transformation transformation = Transformation.None, Frequency frequency = Frequency.None, AggregationMethod method = AggregationMethod.Average, OutputType outputType = OutputType.RealTime ) : IEnumerable
seriesId string The id for a series.
observationStart System.DateTime The start of the observation period.
observationEnd System.DateTime The end of the observation period.
realtimeStart System.DateTime The start of the real-time period.
realtimeEnd System.DateTime The end of the real-time period.
vintageDates IEnumerable A comma separated string of YYYY-MM-DD formatted dates in history (e.g. 2000-01-01,2005-02-24). /// Vintage dates are used to download data as it existed on these specified dates in history. Vintage dates can be /// specified instead of a real-time period using realtime_start and realtime_end. /// /// Sometimes it may be useful to enter a vintage date that is not a date when the data values were revised. /// For instance you may want to know the latest available revisions on 2001-09-11 (World Trade Center and /// Pentagon attacks) or as of a Federal Open Market Committee (FOMC) meeting date. Entering a vintage date is /// also useful to compare series on different releases with different release dates.
limit int The maximum number of results to return. An integer between 1 and 100000, optional, default: 100000
offset int non-negative integer, optional, default: 0
order SortOrder Sort results is ascending or descending observation_date order.
transformation Transformation Type of data value transformation.
frequency Frequency An optional parameter that indicates a lower frequency to aggregate values to. /// The FRED frequency aggregation feature converts higher frequency data series into lower frequency data series /// (e.g. converts a monthly data series into an annual data series). In FRED, the highest frequency data is daily, /// and the lowest frequency data is annual. There are 3 aggregation methods available- average, sum, and end of period.
method AggregationMethod A key that indicates the aggregation method used for frequency aggregation.
outputType OutputType Output type: /// 1. Observations by Real-Time Period /// 2. Observations by Vintage Date, All Observations /// 3. Observations by Vintage Date, New and Revised Observations Only /// 4. Observations, Initial Release Only ///
Résultat IEnumerable
Exemple #1
0
        internal Series(Fred fred) : base(fred)
        {
            _categories = new Lazy <IEnumerable <Category> >(() => UseRealtimeFields
                ? Fred.GetSeriesCategories(Id, RealtimeStart, RealtimeEnd)
                : Fred.GetSeriesCategories(Id));

            _release = new Lazy <Release>(() => UseRealtimeFields
                ? Fred.GetSeriesRelease(Id, RealtimeStart, RealtimeEnd)
                : Fred.GetSeriesRelease(Id));

            _data = new Lazy <List <Observation> >(
                () =>
            {
                const int limit = 100000;
                var data        = UseRealtimeFields
                        ? (List <Observation>)
                                  Fred.GetSeriesObservations(Id, ObservationStart, ObservationEnd, RealtimeStart,
                                                             RealtimeEnd, Enumerable.Empty <DateTime>())
                        : (List <Observation>)
                                  Fred.GetSeriesObservations(Id, ObservationStart, ObservationEnd);

                var count = data.Count;
                var call  = 1;
                while (count == limit)
                {
                    var start = UseRealtimeFields ? RealtimeStart : Fred.CstTime();
                    var end   = UseRealtimeFields ? RealtimeEnd : Fred.CstTime();
                    var more  =
                        (List <Observation>)
                        Fred.GetSeriesObservations(Id, ObservationStart, ObservationEnd, start,
                                                   end, Enumerable.Empty <DateTime>(), limit,
                                                   call * limit);
                    data.AddRange(more);
                    count = more.Count;
                    call++;
                }
                return(data);
            });
        }
Exemple #2
0
        static void Main(string[] args)
        {

            var fred = new Fred("661c0a90e914477da5a7518293de5f8e");

            int startYear;
            int endYear;
            int startMonth;
            int endMonth;

            int deflateYear = 0;

            var data = new Dictionary<string, IList<Observation>>
            {
            };

            //get year of rGDP dollars
            //if (data.ContainsKey("rGDP"))
            {

                //var series = data["rGDP"];

                var series = fred.GetSeries("GDPC1");
                var units = series.Units;
                //Console.WriteLine("Units: ");
                //Console.WriteLine(units);

                //string resultString = Regex.Match(units, @"\d+").Value;
                deflateYear = extractNumber(series.Units);

                Console.WriteLine("deflate year: {0}", deflateYear.ToString());

            }

            string entry;
            WriteLine("Pushing ENTER accepts default values");
            Write("Enter start year [2005]: ");
            entry = ReadLine();
            if (entry == "")
            {
                entry = "2005";
            }
            startYear = Convert.ToInt32(entry);

            WriteLine("Enter end year [2015] ");
            Write("years must cover rGDP real year to deinflate: ");
            entry = ReadLine();
            if (entry == "")
            {
                entry = "2015";
            }
            endYear = Convert.ToInt32(entry);

            Write("Enter start month, ex. Jan = 1 or Oct = [10]: ");
            entry = ReadLine();
            if (entry == "")
            {
                entry = "10";
            }
            startMonth = Convert.ToInt32(entry);

            Write("Enter end month, ex. Jan = 1 or Oct = [10]: ");
            entry = ReadLine();
            if (entry == "")
            {
                entry = "10";
            }
            endMonth = Convert.ToInt32(entry);

            DateTime startDate = new DateTime(startYear, startMonth, 1);
            DateTime endDate = new DateTime(endYear, endMonth, DateTime.DaysInMonth(endYear, endMonth));

            //can't use # in GetSeriesObservations.  Ignores the dates.

            //my names
            string[] dataNames = new string[] { "rGDP", "pSaveRate", "fedFundRate", "empPopRatio", "consConfIndex", "consPriceIndex", "housingSeries" };

            //online series names
            string[] obsNames = new string[] { "GDPC1", "PSAVERT", "DFF", "EMRATIO", "UMCSENT", "CP0000USM086NEST", "SPCS20RSA" };

            int dataCounter = 0;

            //create lists as FredAPI objects
            foreach (var instance in dataNames)
            {
                if (dataNames[dataCounter] == "rGDP")
                {
                    data.Add(dataNames[dataCounter], fred.GetSeriesObservations(obsNames[dataCounter], startDate, endDate).ToList());
                }
                else
                {
                    data.Add(dataNames[dataCounter], fred.GetSeriesObservations(obsNames[dataCounter], startDate, endDate, frequency: Frequency.Monthly).ToList());
                }

                dataCounter++;
            };

            //MinMaxDates(ref data);

            //convert data to sortedList (the DateTime becomes key of the SortedList), the string is the Key of the Dictionary.
            var sortedDataList = new Dictionary<string, SortedList<DateTime, double?>> { };

            dataCounter = 0;

            foreach (var obData in data)
            {
                var list = obData.Value;
                sortedDataList.Add(dataNames[dataCounter], new SortedList<DateTime, double?>(list.ToDictionary(x => x.Date, x => x.Value)));
                dataCounter++;
            }

            //print data before changes
            //PrintData(sortedDataList); - will crash now because of gaps in rGDP

            //insert records (into rGDP)
            //ideally might want to have this second.
            FillInGaps(ref sortedDataList);

            //identify minmax dates, and trim list, if ran before FillInGaps, rGDP doesn't populate up till HighestDate2
            MinMaxDates(ref sortedDataList);

            PrintData(sortedDataList);
            PrintDataToFile(sortedDataList, "preConversion");

            //deInflate

            deInflate(ref sortedDataList, deflateYear);

            PrintData(sortedDataList);

            PrintDataToFile(sortedDataList, "postConversion");

            parseData(sortedDataList, args);

        }