예제 #1
0
        private void WritePortfolioBuilding()
        {
            // first check the percentages
            decimal pctWt   = 0.0m;
            decimal totalWt = 0.0m;
            bool    ok      = true;
            string  message = String.Empty;
            string  sPctWt;

            //int mgrCount = 0;
            for (int i = 0; i < dgvManagersNew.Rows.Count; i++)
            {
                DataGridViewCheckBoxCell CbxCell = dgvManagersNew.Rows[i].Cells[(int)ManagerCols.Analyze] as DataGridViewCheckBoxCell;
                if (CbxCell.Value == null)
                {
                    continue;
                }
                if (CbxCell != null && !DBNull.Value.Equals(CbxCell.Value) && (bool)CbxCell.Value == true)
                {
                    //mgrCount++;

                    // %WT
                    if (dgvManagersNew.Rows[i].Cells[(int)ManagerCols.PercentageWeight].Value == null)
                    {
                        ok      = false;
                        message = "Percentage";
                        break;
                    }
                    sPctWt = dgvManagersNew.Rows[i].Cells[(int)ManagerCols.PercentageWeight].Value.ToString();
                    if (!Decimal.TryParse(sPctWt, out pctWt))
                    {
                        ok      = false;
                        message = "Every selected manager must have a Percentage value.";
                        break;
                    }
                    totalWt += pctWt;
                }
            }
            if ((totalWt < 0.7m) | (totalWt > 1.2m))
            {
                ok      = false;
                message = "Total percentage weight = " + totalWt.ToString() + ", which is outside the acceptable range of 0.7 to 1.2.\n\nRun anyway?";
            }
            if (ok == false)
            {
                DialogResult rslt = MessageBox.Show(message, "Percentage Weight Out of Range", MessageBoxButtons.YesNo);
                if (rslt == DialogResult.No)
                {
                    return;
                }
            }

            // check other values
            ok      = true;
            message = String.Empty;
            for (int i = 0; i < dgvManagersNew.Rows.Count; i++)
            {
                DataGridViewCheckBoxCell CbxCell = dgvManagersNew.Rows[i].Cells[(int)ManagerCols.Analyze] as DataGridViewCheckBoxCell;
                if (CbxCell.Value == null)
                {
                    continue;
                }
                if (CbxCell != null && !DBNull.Value.Equals(CbxCell.Value) && (bool)CbxCell.Value == true)
                {
                    // strategy
                    if ((dgvManagersNew.Rows[i].Cells[(int)ManagerCols.Strategy].Value == null) ||
                        (dgvManagersNew.Rows[i].Cells[(int)ManagerCols.Strategy].Value.ToString() == String.Empty))
                    {
                        ok      = false;
                        message = "Strategy";
                        break;
                    }
                    // sub strategy
                    if ((dgvManagersNew.Rows[i].Cells[(int)ManagerCols.SubStrategy].Value == null) ||
                        (dgvManagersNew.Rows[i].Cells[(int)ManagerCols.SubStrategy].Value.ToString() == String.Empty))
                    {
                        ok      = false;
                        message = "Sub Strategy";
                        break;
                    }
                    // market focus
                    if ((dgvManagersNew.Rows[i].Cells[(int)ManagerCols.MarketFocus].Value == null) ||
                        (dgvManagersNew.Rows[i].Cells[(int)ManagerCols.MarketFocus].Value.ToString() == String.Empty))
                    {
                        ok      = false;
                        message = "Market Focus";
                        break;
                    }
                }
            }
            if (ok == false)
            {
                MessageBox.Show("Every selected manager must have a " + message + " value.", "Missing " + message + " Value");
                return;
            }

            // save UI to PortfolioBuildingFileObject
            int selectedCount = 0;
            List <PortfolioBuildingRecord> pbrs = new List <PortfolioBuildingRecord>();

            for (int i = 0; i < this.dgvManagersNew.Rows.Count; i++)
            {
                dgvManagersNew.Rows[i].Cells[(int)ManagerCols.Number].Value = null;
                DataGridViewCheckBoxCell CbxCell = dgvManagersNew.Rows[i].Cells[(int)ManagerCols.Analyze] as DataGridViewCheckBoxCell;
                if (CbxCell.Value == null)
                {
                    continue;
                }
                if (CbxCell != null && !DBNull.Value.Equals(CbxCell.Value) && (bool)CbxCell.Value == true)
                {
                    PortfolioBuildingRecord rec = new PortfolioBuildingRecord();
                    selectedCount++;

                    // set number column in grid
                    dgvManagersNew.Rows[i].Cells[(int)ManagerCols.Number].Value = selectedCount.ToString();

                    // set namager record values
                    rec.Number       = dgvManagersNew.Rows[i].Cells[(int)ManagerCols.Number].Value.ToString();
                    rec.ManagerName  = dgvManagersNew.Rows[i].Cells[(int)ManagerCols.Manager].Value.ToString();
                    rec.ManagerCode  = dgvManagersNew.Rows[i].Cells[(int)ManagerCols.ManagerCode].Value.ToString();
                    rec.ProgramCode  = dgvManagersNew.Rows[i].Cells[(int)ManagerCols.ProgramCode].Value.ToString();
                    rec.Strategy     = dgvManagersNew.Rows[i].Cells[(int)ManagerCols.Strategy].Value.ToString();
                    rec.SubStrategy  = dgvManagersNew.Rows[i].Cells[(int)ManagerCols.SubStrategy].Value.ToString();
                    rec.MarketsFocus = dgvManagersNew.Rows[i].Cells[(int)ManagerCols.MarketFocus].Value.ToString();
                    rec.Percentage   = dgvManagersNew.Rows[i].Cells[(int)ManagerCols.PercentageWeight].Value.ToString();
                    pbrs.Add(rec);
                }
            }
            // now update the file object and write to file
            m_portfolioBuildingFile.WriteToFile(pbrs, tbInputDir.Text.Trim());
        }
예제 #2
0
        private void LinesToRecords()
        {
            string line;

            string[] fields    = null;
            int      CODE_FIRM = 0;
            string   field     = string.Empty;
            PortfolioBuildingRecord rec;

            if (m_recs == null)
            {
                m_recs = new List <PortfolioBuildingRecord>();
            }


            for (int i = 1; i < m_lines.Length; i++)
            {
                line = m_lines[i];

                // skip blank lines
                if (line.Trim().Length == 0)
                {
                    continue;
                }

                fields = line.Split(',');

                // create new record object
                rec = new PortfolioBuildingRecord();

                field      = fields[Number_Idx];
                field      = field.Replace("\"", "");
                rec.Number = field;

                field           = fields[Manager_Idx];
                field           = field.Replace("\"", "");
                rec.ManagerName = field;

                field           = fields[ManagerCode_Idx];
                field           = field.Replace("\"", "");
                rec.ManagerCode = field;

                field           = fields[ProgramCode_Idx];
                field           = field.Replace("\"", "");
                rec.ProgramCode = field;

                field        = fields[Strategy_Idx];
                field        = field.Replace("\"", "");
                rec.Strategy = field;

                field           = fields[SubStrategy_Idx];
                field           = field.Replace("\"", "");
                rec.SubStrategy = field;

                field            = fields[MarketsFocus_Idx];
                field            = field.Replace("\"", "");
                rec.MarketsFocus = field;

                field          = fields[Percentage_Idx];
                field          = field.Replace("\"", "");
                rec.Percentage = field;

                field       = fields[Analyze_Idx];
                field       = field.Replace("\"", "");
                rec.Analyze = field;

                field           = fields[Correlation_Idx];
                field           = field.Replace("\"", "");
                rec.Correlation = field;

                field         = fields[TargetVol_Idx];
                field         = field.Replace("\"", "");
                rec.TargetVol = field;

                m_recs.Add(rec);
            }
        }