/***************************************************************************** * FUNCTION: BindCorrelationData * Description: * Parameters: *****************************************************************************/ public void BindCorrelationData(ref ExchangeMarket mktData, int pIndex) { int i, j; Dictionary <int, Double> CoefficientList; DataRow row; if (TableType == StatTableType.INDIVIDUAL_PPC && (pIndex < mktData.Constituents.Count && pIndex > 0)) { //CreateSingleCorrelationTable(); CreateNewTable(); // Create new columns AddColumnToSource(System.Type.GetType("System.String"), TableHeadings.Name, "Name", true, false); AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.PPC_Coeff, "Correlation", true, false); AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.PctChange[0], TableHeadings.PctChange[1], true, false); AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.Hist_Avg[0], TableHeadings.Hist_Avg[1], true, false); CoefficientList = mktData.GetPPCCoefficients(pIndex); for (i = 0; i < mktData.Constituents.Count; i++) { if (i != pIndex) { row = tableSource.NewRow(); row[IndexColumnName] = i + 1; row[TableHeadings.Name] = mktData.Constituents[i].Name; row[TableHeadings.PctChange[0]] = mktData.Constituents[i].pctChange; row[TableHeadings.Hist_Avg[0]] = mktData.Constituents[i].avgPrice; //Check for availability of PPC coefficients if (i < CoefficientList.Count) { row[TableHeadings.PPC_Coeff] = CoefficientList[i]; } else { row[TableHeadings.PPC_Coeff] = 0; } tableSource.Rows.Add(row); } } //Bind Data BindTableSource(0.5); } NumberOfEntries = mktData.Constituents.Count(); }
/***************************************************************************** * FUNCTION: BindMarketData * Description: * Parameters: *****************************************************************************/ public void BindMarketData(ExchangeMarket mktData, bool updateExisting = false) { int i, j; Double NameColWidth = 0.25; Dictionary <int, Double> CoefficientList; List <int> remSelectedRows = new List <int>(this.SelectedEntries); List <Tuple <int, int> > remSelectedCells = new List <Tuple <int, int> >(this.SelectedCells); String existingSort = this.GetDataViewSortInstruction(); ScrollIndex = this.dataGridView1.FirstDisplayedScrollingRowIndex; DataRow row; if (TableType == StatTableType.HIST_STATS) { CreateNewTable(); // Create new columns AddColumnToSource(System.Type.GetType("System.String"), TableHeadings.Name, "Name", true, false); AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.PctChange[0], TableHeadings.PctChange[1], true, false, false, ColumnStyle.PLUS_MINUS); AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.Hist_Avg[0], TableHeadings.Hist_Avg[1], true, false); AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.Hist_Vlty, "Volatility", true, false); AddColumnToSource(System.Type.GetType("System.DateTime"), TableHeadings.Hist_DtStart[0], TableHeadings.Hist_DtStart[1], true, false); AddColumnToSource(System.Type.GetType("System.DateTime"), TableHeadings.Hist_DtEnd[0], TableHeadings.Hist_DtEnd[1], true, false); NameColWidth = 0.25; for (i = 0; i < mktData.Constituents.Count(); i++) { row = tableSource.NewRow(); row[IndexColumnName] = i + 1; row[TableHeadings.Name] = mktData.Constituents[i].Name; row[TableHeadings.PctChange[0]] = mktData.Constituents[i].pctChange; row[TableHeadings.Hist_Avg[0]] = mktData.Constituents[i].avgPrice; row[TableHeadings.Hist_Vlty] = mktData.Constituents[i].Volatility; row[TableHeadings.Hist_DtStart[0]] = mktData.Constituents[i].HistoricalPriceDate[0]; row[TableHeadings.Hist_DtEnd[0]] = mktData.Constituents[i].HistoricalPriceDate[mktData.Constituents[i].HistoricalPriceDate.Count() - 1]; tableSource.Rows.Add(row); } } else if (TableType == StatTableType.ANALYSIS_PPC) { CreateNewTable(); // Create new columns AddColumnToSource(System.Type.GetType("System.String"), TableHeadings.Name, "Name", true, false); AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.PPC_Max[0], TableHeadings.PPC_Max[1], true, false); AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.PPC_Min[0], TableHeadings.PPC_Min[1], true, false); NameColWidth = 0.5; for (i = 0; i < mktData.Constituents.Count(); i++) { row = tableSource.NewRow(); row[IndexColumnName] = i + 1; row[TableHeadings.Name] = mktData.Constituents[i].Name; CoefficientList = mktData.GetPPCCoefficients(i); row[TableHeadings.PPC_Max[0]] = CoefficientList.Values.Max(); row[TableHeadings.PPC_Min[0]] = CoefficientList.Values.Min(); tableSource.Rows.Add(row); } } else if (TableType == StatTableType.LIVE_STATS) { CreateNewTable(); // Create new columns AddColumnToSource(System.Type.GetType("System.String"), TableHeadings.Name, "Name", true, false); AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.Live_Last, "Last", true, false); AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.Live_High, "High", true, false); AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.Live_Low, "Low", true, false); AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.Live_Chg, "Change", true, false, false, ColumnStyle.PLUS_MINUS); AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.PctChange[0], TableHeadings.PctChange[1], true, false, false, ColumnStyle.PLUS_MINUS); AddColumnToSource(System.Type.GetType("System.Double"), TableHeadings.Live_Vol, "Volume", true, false); AddColumnToSource(System.Type.GetType("System.DateTime"), TableHeadings.Live_Time, "Time", true, false); NameColWidth = 0.25; for (i = 0; i < mktData.Constituents.Count(); i++) { row = tableSource.NewRow(); row[IndexColumnName] = i + 1; row[TableHeadings.Name] = mktData.Constituents[i].Name; row[TableHeadings.Live_Last] = mktData.Constituents[i].DailyLast[mktData.Constituents[i].DailyLast.Count - 1]; row[TableHeadings.Live_High] = mktData.Constituents[i].DailyHigh; row[TableHeadings.Live_Low] = mktData.Constituents[i].DailyLow; row[TableHeadings.Live_Chg] = mktData.Constituents[i].DailyChg; row[TableHeadings.PctChange[0]] = mktData.Constituents[i].DailyChgPct; row[TableHeadings.Live_Vol] = mktData.Constituents[i].DailyVolume; row[TableHeadings.Live_Time] = mktData.Constituents[i].DailyTime[mktData.Constituents[i].DailyTime.Count - 1]; tableSource.Rows.Add(row); } } else { //Invalid table-type. Do nothing. } NumberOfEntries = mktData.Constituents.Count(); //Get the column indices of columns where the set style is PLUS_MINUS PlusMinusColumns = ColumnStyles.Select((cs, ci) => cs == ColumnStyle.PLUS_MINUS ? ci : -1).Where(ci2 => ci2 >= 0).ToList(); //Bind Data BindTableSource(NameColWidth); //Apply existing filter ApplyFilter(); if (updateExisting) { this.SelectedEntries = new List <int>(remSelectedRows); //this.SelectedCells = new List<Tuple<int, int>>(remSelectedCells); this.SetDataViewSortInstruction(existingSort); this.UpdateSelection(remSelectedCells); } }