Esempio n. 1
0
 //this method hides buttons, plots etc.
 private void hide()
 {
     ARCHdgv.Hide();
     ARCHmodels.Hide();
     ARCHmodelsdgv.Hide();
     ARCHwhitenoise.Hide();
     ARCHarimadgv.Hide();
     ARCHarchdgv.Hide();
     ARCHsavebt.Hide();
     ARCHarimalbl.Hide();
     label1.Hide();
     label2.Hide();
     label3.Hide();
 }
Esempio n. 2
0
        //if the user clicks on one of the ARCH/GARCH models in the Fitted ARCH/GARCH models datagridview, this method is called
        //it will display the parameters from the ARCH/GARCH model and it will also give a diagnostic plot of the residuals
        private void ARCHmodelsdgv_CellClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
        {
            ARCHarimadgv.Show();
            ARCHarchdgv.Show();
            label1.Show();
            label2.Show();
            ARCHwhitenoise.Show();
            ARCHsavebt.Show();

            //place holder to determine which row in the DGV has been selected
            int selectedrowindex = 0;

            if (this.ARCHmodelsdgv.SelectedCells.Count > 0)
            {
                selectedrowindex = ARCHmodelsdgv.SelectedCells[0].RowIndex;
            }

            //look at the acf of the theoretical white noise
            List <double> residsac = new List <double>();

            foreach (double dd in archModellist[selectedrowindex].archacfWhitenoise)
            {
                residsac.Add(dd);
            }
            residsac.RemoveAt(0);
            //we will use the following code to create the horizontal lines in the ACF and PACF plots
            int           n     = archModellist[selectedrowindex].archWhitenoise.Count();
            double        l1    = 1.96 / Math.Sqrt(n);
            double        l2    = -1.96 / Math.Sqrt(n);
            List <double> line1 = new List <double>();
            List <double> line2 = new List <double>();

            for (int i = 0; i < residsac.Count(); i++)
            {
                line1.Add(l1);
                line2.Add(l2);
            }
            ARCHwhitenoise.Titles.Clear();
            ARCHwhitenoise.Titles.Add(new Title("ACF of v(t) from ARCH/GARCH model", Docking.Top, new Font("Verdana", 8f, FontStyle.Bold), Color.Black));
            ARCHwhitenoise.ChartAreas[0].AxisY.LabelStyle.Font = ARCHwhitenoise.ChartAreas[0].AxisX.LabelStyle.Font = new Font("Arial", 11, GraphicsUnit.Pixel);
            ARCHwhitenoise.ChartAreas[0].RecalculateAxesScale();
            ARCHwhitenoise.Series.Clear();
            var series10 = new System.Windows.Forms.DataVisualization.Charting.Series
            {
                Name              = "ACF Arch white noise",
                Color             = System.Drawing.Color.Blue,
                IsVisibleInLegend = false,
                IsXValueIndexed   = true,
                ChartType         = SeriesChartType.Column
            };

            this.ARCHwhitenoise.Series.Add(series10);
            int z = 0;

            foreach (double dd in residsac)
            {
                series10.Points.AddXY(z + 1, residsac[z]);
                z++;
            }

            var series26 = new System.Windows.Forms.DataVisualization.Charting.Series
            {
                Name              = "Series26",
                Color             = System.Drawing.Color.Black,
                IsVisibleInLegend = false,
                IsXValueIndexed   = true,
                ChartType         = SeriesChartType.Line
            };

            this.ARCHwhitenoise.Series.Add(series26);
            z = 0;
            foreach (double dd in line1)
            {
                series26.Points.AddXY(z + 1, line1[z]);
                z++;
            }
            var series27 = new System.Windows.Forms.DataVisualization.Charting.Series
            {
                Name              = "Series27",
                Color             = System.Drawing.Color.Black,
                IsVisibleInLegend = false,
                IsXValueIndexed   = true,
                ChartType         = SeriesChartType.Line
            };

            this.ARCHwhitenoise.Series.Add(series27);
            z = 0;
            foreach (double dd in line2)
            {
                series27.Points.AddXY(z + 1, line2[z]);
                z++;
            }
            ARCHwhitenoise.Invalidate();
            ARCHwhitenoise.ChartAreas[0].AxisY.Maximum = this.P.maximum(residsac);
            //populating the ARCGarimadgv with the parameter estimates
            int mposition = 0;

            mposition = ARCHdgv.SelectedRows[0].Index;
            ARCHarimadgv.Show();
            ARCHarimadgv.AllowUserToAddRows  = false;
            ARCHarimadgv.AutoGenerateColumns = false;
            ARCHarimadgv.Rows.Clear();
            ARCHarimadgv.Columns.Clear();
            int nparams = Modellist[mposition].Parameters.Count();

            string[] vals = new string[nparams];
            for (int i = 0; i < nparams; i++)
            {
                vals[i] = Math.Round(Modellist[mposition].Parameters[i], 3).ToString();
            }
            int nar = Modellist[mposition].P;
            int nma = Modellist[mposition].Q;

            ARCHarimadgv.ColumnCount = nparams;
            ARCHarimadgv.RowCount    = 1;
            for (int i = 0; i < nar; i++)
            {
                ARCHarimadgv.Columns[i].Name = "AR" + (i + 1).ToString();
            }
            for (int i = 0; i < nma; i++)
            {
                ARCHarimadgv.Columns[i + nar].Name = "MA" + (i + 1).ToString();
            }
            ARCHarimadgv.Rows[0].SetValues(vals);
            //populating the ARCGarchdgv with the parameter estimates
            ARCHarchdgv.Show();
            ARCHarchdgv.AllowUserToAddRows  = false;
            ARCHarchdgv.AutoGenerateColumns = false;
            ARCHarchdgv.Rows.Clear();
            ARCHarchdgv.Columns.Clear();
            int narchparams = archModellist[selectedrowindex].archParameters.Count();

            string[] archvals = new string[narchparams];
            for (int i = 0; i < narchparams; i++)
            {
                archvals[i] = Math.Round(archModellist[selectedrowindex].archParameters[i], 3).ToString();
            }
            int archnar = archModellist[selectedrowindex].archP;
            int archnma = archModellist[selectedrowindex].archQ + 1;

            ARCHarchdgv.ColumnCount = narchparams;
            ARCHarchdgv.RowCount    = 1;
            for (int i = 0; i < archnma; i++)
            {
                ARCHarchdgv.Columns[i].Name = "alpha" + (i).ToString();
            }

            for (int i = 0; i < archnar; i++)
            {
                ARCHarchdgv.Columns[i + archnma].Name = "beta" + (i + 1).ToString();
            }
            ARCHarchdgv.Rows[0].SetValues(archvals);
        }