Xaye.Fred.Fred.GetSeries C# (CSharp) Méthode

GetSeries() public méthode

Get an economic data series using system defaults. Corresponds to http://api.stlouisfed.org/fred/series
public GetSeries ( string seriesId ) : Series
seriesId string The id for a series.
Résultat Series
        public Series GetSeries(string seriesId)
        {
            var now = CstTime();
            return GetSeries(seriesId, now, now);
        }

Same methods

Fred::GetSeries ( string seriesId, System.DateTime realtimeStart, System.DateTime realtimeEnd ) : Series

Usage Example

Exemple #1
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);

        }