/***************************************************************************** * FUNCTION: SetDefaultSymbol * * Description: If no ticker symbol is found for this equity, this function * creates a default one using the first alpha-numeric value * in each word of the Name field. * *****************************************************************************/ private void SetDefaultSymbol() { string[] words = Name.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); Symbol = ""; if (words != null && words.Length > 0) { foreach (string str in words) { Symbol += str.Substring(0, 1).ToUpper(); } Symbol = Helpers.RemoveNonAlphanumeric(Symbol) + "?"; } }
/***************************************************************************** * FUNCTION: UpdateConstituentData * Description: * Parameters: * pDataLabels - * pDataValues - *****************************************************************************/ private void UpdateConstituentData(List <String> pDataLabels, List <String> pDataValues, String pEqUrl = "") { int item_index = 0; string item_value = ""; string cName = ""; List <Equity> searchResult; List <String> data_labels = new List <String>(pDataLabels); List <String> data_values = new List <String>(pDataValues); Equity cEq; foreach (String label in data_labels) { item_value = data_values[item_index]; //ToDo: optimize if (label.Contains("Name")) { //Find item_value in the 'constituents' List searchResult = constituents.Where(p => Helpers.RemoveNonAlphanumeric(p.Name) == Helpers.RemoveNonAlphanumeric(item_value)).ToList(); cName = data_values[item_index]; data_labels.RemoveAt(item_index); data_values.RemoveAt(item_index); if (searchResult != null && searchResult.Count > 0) { searchResult[0].UpdateLiveData(data_labels, data_values); } else { cEq = new Equity(cName); cEq.UpdateLiveData(data_labels, data_values, pEqUrl); cEq.ListedMarket = this.Name; this.constituents.Add(cEq); } break; } item_index++; } }
/***************************************************************************** * FUNCTION: parseCsvHistoricalData * Description: * Parameters: * pContainingFolder - *****************************************************************************/ public Boolean parseCsvHistoricalData(String pContainingFolder = "") { Boolean success = false; DirectoryInfo rootDir; FileInfo[] files = null; int itemCount, index; Equity cEQ = null; List <Equity> searchResult; if (pContainingFolder == "") { rootDir = new DirectoryInfo(downloadedDataPath); } else { rootDir = new DirectoryInfo(pContainingFolder); } if (this.Name == "") { this.Name = rootDir.Name; } files = rootDir.GetFiles("*.csv"); itemCount = files.Count(); this.IsDataAligned = true; if (files != null) { index = 0; pct_download = 0; foreach (FileInfo fi in files) { try { if (this.constituents == null) { this.constituents = new List <Equity>(); } searchResult = constituents.Where(p => Helpers.RemoveNonAlphanumeric(p.Name) == Helpers.RemoveNonAlphanumeric(fi.Name.Replace(".csv", ""))).ToList(); if (searchResult != null && searchResult.Count > 0) { searchResult[0].DataFileName = fi.FullName; searchResult[0].ReadDataFile(); cEQ = searchResult[0]; } else { cEQ = new Equity(); cEQ.DataFileName = fi.FullName; cEQ.ListedMarket = this.Name; if (cEQ.ReadDataFile() == true) { constituents.Add(cEQ); } } if (this.IsDataAligned && this.Constituents.Count > 0) { this.IsDataAligned = cEQ.HistoricalPriceDate.SequenceEqual(this.Constituents[0].HistoricalPriceDate); } } catch (Exception e) { Console.WriteLine(e.Message); } index++; pct_download = (Double)index / (Double)files.Count(); } CalculateCorrelationCoefficients(); UpdateTimeline(); } return(success); }
/***************************************************************************** * FUNCTION: parseCsvHistoricalData * Description: * Parameters: * pContainingFolder - *****************************************************************************/ public Boolean parseCsvHistoricalData(String pContainingFolder = "") { Boolean success = false; DirectoryInfo rootDir; FileInfo[] files = null; int itemCount, index; Equity cEQ = null; List <Equity> searchResult; //Get the root folder if (pContainingFolder == "") { rootDir = new DirectoryInfo(downloadedDataPath); } else { rootDir = new DirectoryInfo(pContainingFolder); } if (this.Name == "") { this.Name = rootDir.Name; } //Get the number of CSV files in the selected folder files = rootDir.GetFiles("*.csv"); itemCount = files.Count(); this.IsDataAligned = true; if (files != null) { index = 0; pct_download = 0; //Loop through all CSV files one by one foreach (FileInfo fi in files) { //try //{ if (this.constituents == null) { this.constituents = new List <Equity>(); } //If the constituents list already contains an item with the same name as the file, then update the existing Equity class searchResult = constituents.Where(p => Helpers.RemoveNonAlphanumeric(p.Name) == Helpers.RemoveNonAlphanumeric(fi.Name.Replace(".csv", ""))).ToList(); if (searchResult != null && searchResult.Count > 0) { searchResult[0].DataFileName = fi.FullName; searchResult[0].ReadDataFile(); cEQ = searchResult[0]; } //Otherwise create the new Equity instance by parsing the file else { cEQ = new Equity(); cEQ.DataFileName = fi.FullName; cEQ.ListedMarket = this.Name; if (cEQ.ReadDataFile() == true) { constituents.Add(cEQ); } } //Set IsDataAligned to True if all Equities in this market instance have data points for all of the dates in the data set if (this.IsDataAligned && this.Constituents.Count > 0) { this.IsDataAligned = cEQ.HistoricalPriceDate.SequenceEqual(this.Constituents[0].HistoricalPriceDate); } //} //catch (Exception e) //{ // Console.WriteLine(e.Message); //} pct_download = (Double)index / (Double)files.Count(); index++; } CalculateCorrelationCoefficients(); UpdateTimeline(); pct_download = 1.0; } return(success); }