コード例 #1
0
ファイル: Forecast.cs プロジェクト: lulzzz/WindApp2015
        //method which loads the details of previously calibrated ARIMA/ARCH/GARCH models into modellist
        private void loadmodels(int position)
        {
            string interim1 = Fnames[position].Replace(".xlsx", "");
            string interim2 = Tab[position].Replace("$", "");
            string interim3 = Flocations[position].Replace(fnames[position], interim1 + interim2 + "Models.csv");

            if (!File.Exists(interim3))
            {
                return;
            }
            StreamReader sr = new StreamReader(interim3);
            string       line;

            sr.ReadLine();
            Modellist.Clear();
            while ((line = sr.ReadLine()) != null)
            {
                bool          subtractmean = false;
                char[]        delimiters   = new char[] { '\t', ' ' };
                string[]      details      = line.Split(delimiters);
                string        Transform    = details[0];
                double        Shape        = double.Parse(details[1]);
                double        Scale        = double.Parse(details[2]);
                string        Model        = details[3];
                int           P            = int.Parse(details[4]);
                int           Q            = int.Parse(details[5]);
                int           D            = int.Parse(details[6]);
                double        A            = double.Parse(details[7]);
                double        SS           = double.Parse(details[8]);
                double        Variance     = double.Parse(details[9]);
                List <double> Parameters   = new List <double>();
                for (int i = 0; i < P + Q; i++)
                {
                    Parameters.Add(double.Parse(details[10 + i]));
                }
                int           archQ          = int.Parse(details[10 + P + Q]);
                int           archP          = int.Parse(details[11 + P + Q]);
                double        archAIC        = double.Parse(details[12 + P + Q]);
                List <double> archParameters = new List <double>();
                if (archQ == 0)
                {
                    archParameters.Add(0);
                }
                else
                {
                    //if we have an ARCH(Q) model then there are Q+1 parameters
                    for (int i = 0; i < archP + (archQ + 1); i++)
                    {
                        archParameters.Add(double.Parse(details[13 + P + Q + i]));
                    }
                }
                subtractmean = bool.Parse(details[13 + P + Q + archP + (archQ + 1)]);
                Modellist.Add(new model(Model, P, Q, D, A, 0, Parameters, new List <double> {
                    0.0
                }, Variance, new List <double> {
                    0.0
                }, SS, Transform, Shape, Scale, archQ, archP, archParameters, archAIC, subtractmean));
            }
        }
コード例 #2
0
ファイル: ARCH.cs プロジェクト: lulzzz/WindApp2015
        //on selecting one of the values from the listbox, this method is called.
        //It a)populates the Tseries list b)calls the loadmodels() method c) calls the populatedatagridview() method
        private void ARCHlb_SelectedValueChanged(object sender, EventArgs e)
        {
            System.Windows.Forms.Cursor old = this.Cursor;
            this.Cursor = Cursors.AppStarting;

            Tseries.Clear();

            int position = ARCHlb.SelectedIndex;

            if (position == -1)
            {
                this.Cursor = old;
                return;
            }
            string curItem  = Tab[position];
            string df       = Flocations[position];
            string f        = ";Extended Properties=\"Excel 12.0;HDR=NO\"";
            string c        = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + df + f;
            string interim1 = Fnames[position].Replace(".xlsx", "");
            string interim2 = Tab[position].Replace("$", "");
            string interim3 = Flocations[position].Replace(fnames[position], interim1 + interim2 + ".csv");
            int    counter  = 0;
            string line1;
            string line2;
            string line3;
            double t      = 0;
            double tscale = 0;

            try
            {
                StreamReader sr = new StreamReader(interim3);
                while (counter < 1)
                {
                    line1 = sr.ReadLine();
                    line2 = sr.ReadLine();
                    line3 = sr.ReadLine();
                    bool tf      = Double.TryParse(line2, out t);
                    bool tfscale = Double.TryParse(line3, out tscale);
                    if (line1 == "Iterative")
                    {
                        this.Type           = "Iterative";
                        this.Transform      = t;
                        this.Transformscale = 0;
                    }
                    if (line1 == "Weibull")
                    {
                        this.Type           = "Weibull";
                        this.Transform      = t;
                        this.Transformscale = tscale;
                    }

                    counter++;
                }
            }
            catch
            {
            }
            DataSet          data      = new DataSet();
            OleDbConnection  con       = new OleDbConnection(c);
            DataTable        dataTable = new DataTable();
            string           query     = string.Format("SELECT * FROM [{0}]", curItem);
            OleDbDataAdapter adapter   = new OleDbDataAdapter(query, con);

            try
            {
                con.Open();
                adapter.Fill(dataTable);
                data.Tables.Add(dataTable);
                int m = 0, n = 0;
                m      = data.Tables[0].Rows.Count;
                n      = dataTable.Columns.Count;
                this.R = m;
                this.C = n;
                int q = 0, r = 0;
                try
                {
                    for (q = 0; q < m; q++)
                    {
                        for (r = 0; r < n; r++)
                        {
                            double d = (double)data.Tables[0].Rows[q].ItemArray[r];
                            Tseries.Add(d);
                        }
                    }
                }
                catch (Exception x)
                {
                    MessageBox.Show("No data in the underlying tab. Error:" + x.Message);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show("The listbox selection did not work. Error: " + ex.Message);
            }
            finally
            {
                con.Close();
                Modellist.Clear();
                this.loadmodels(position);
                if (Modellist.Count() == 0)
                {
                    hide();
                    string            message = "No ARIMA models relating to this data set have been found.\nPlease go back to ARIMA section, run the models and save output.";
                    string            caption = "ARIMA Models";
                    MessageBoxButtons buttons = MessageBoxButtons.OK;
                    DialogResult      result;
                    result = MessageBox.Show(message, caption, buttons);
                }
                else
                {
                    populatedatagridview();
                    this.P = new Statistics(Tseries);
                }
                this.Cursor = old;
            }
        }