Beispiel #1
0
        static void download_us_bond_yields(string URL, Bachlor_EssayEntities db)
        {
            //connect to quandl
            WebClient streamUrl = new WebClient();

            streamUrl.BaseAddress = URL;
            string       URI    = URL;
            Stream       d      = streamUrl.OpenRead(URI);
            StreamReader reader = new StreamReader(d);

            while (reader.Peek() > 0)
            {
                //download the split the returned string
                string s = reader.ReadLine();

                string[] data = s.Split(',');
                US_Yield g    = new US_Yield();
                double   c;
                //make sure you arent getting headers, if its a number push to database
                bool can = double.TryParse(data[1], out c);
                if (!can)
                {
                    continue;
                }
                g.Date_of_Bond = Convert.ToDateTime(data[0]);
                if (!String.IsNullOrEmpty(data[1]))
                {
                    g.one_mo = Convert.ToDouble(data[1]);
                }
                if (!String.IsNullOrEmpty(data[2]))
                {
                    g.three_mo = Convert.ToDouble(data[2]);
                }
                if (!String.IsNullOrEmpty(data[3]))
                {
                    g.six_mo = Convert.ToDouble(data[3]);
                }
                if (!String.IsNullOrEmpty(data[4]))
                {
                    g.one_yr = Convert.ToDouble(data[4]);
                }
                if (!String.IsNullOrEmpty(data[5]))
                {
                    g.two_yr = Convert.ToDouble(data[5]);
                }
                if (!String.IsNullOrEmpty(data[6]))
                {
                    g.three_yr = Convert.ToDouble(data[6]);
                }
                if (!String.IsNullOrEmpty(data[7]))
                {
                    g.five_yr = Convert.ToDouble(data[7]);
                }
                if (!String.IsNullOrEmpty(data[8]))
                {
                    g.seven_yr = Convert.ToDouble(data[8]);
                }
                if (!String.IsNullOrEmpty(data[9]))
                {
                    g.ten_yr = Convert.ToDouble(data[9]);
                }
                if (!String.IsNullOrEmpty(data[10]))
                {
                    g.twenty_yr = Convert.ToDouble(data[10]);
                }
                if (!String.IsNullOrEmpty(data[11]))
                {
                    g.thirty_yr = Convert.ToDouble(data[11]);
                }
                db.US_Yield.Add(g);
            }
            d.Close();
            reader.Close();
            db.SaveChanges();
            Console.WriteLine("Us Bond Yields Done");
        }
 static void download_us_bond_yields(string URL, Bachlor_EssayEntities db)
 {
     WebClient streamUrl = new WebClient();
     streamUrl.BaseAddress = URL;
     string URI = URL;
     Stream d = streamUrl.OpenRead(URI);
     StreamReader reader = new StreamReader(d);
     while (reader.Peek() > 0)
     {
         string s = reader.ReadLine();
         Console.WriteLine(s);
         Console.WriteLine();
         string[] data= s.Split(',');
         US_Yield g = new US_Yield();
         double c;
         bool can = double.TryParse(data[1], out c);
         if (!can)
         {
             continue;
         }
         g.Date_ = data[0];
         if(!String.IsNullOrEmpty(data[1]))
             g.one_mo = Convert.ToDouble(data[1]);
         if (!String.IsNullOrEmpty(data[2]))
             g.three_mo = Convert.ToDouble(data[2]);
         if (!String.IsNullOrEmpty(data[3]))
             g.six_mo = Convert.ToDouble(data[3]);
         if (!String.IsNullOrEmpty(data[4]))
             g.one_yr = Convert.ToDouble(data[4]);
         if (!String.IsNullOrEmpty(data[5]))
             g.two_yr = Convert.ToDouble(data[5]);
         if (!String.IsNullOrEmpty(data[6]))
             g.three_yr = Convert.ToDouble(data[6]);
         if (!String.IsNullOrEmpty(data[7]))
             g.five_yr = Convert.ToDouble(data[7]);
         if (!String.IsNullOrEmpty(data[8]))
             g.seven_yr = Convert.ToDouble(data[8]);
         if (!String.IsNullOrEmpty(data[9]))
             g.ten_yr = Convert.ToDouble(data[9]);
         if (!String.IsNullOrEmpty(data[10]))
             g.twenty_yr = Convert.ToDouble(data[10]);
         if (!String.IsNullOrEmpty(data[11]))
             g.thirty_yr = Convert.ToDouble(data[11]);
         db.US_Yield.Add(g);
     }
     db.SaveChanges();
     d.Close();
     reader.Close();
 }