/***************************************************************************** * FUNCTION: GetProfile * Description: Get the company profile if it exists in the expected location * The expected location is a subfolder within the same folder as * the equity source .csv file with the word "Profile" in the name. * * This function will search only the first subfolder it finds * matching this pattern * Parameters: *****************************************************************************/ private void GetProfile() { List <string> searchNames = new List <string>(); string root = "", pf = ""; bool profileFound = false; string[] profiles, pf_lines; List <string[]> profile_content; try { root = this.dataFileName.Substring(0, dataFileName.LastIndexOf("\\")); string[] dirs = Directory.GetDirectories(root, "*Profile*", SearchOption.AllDirectories); if (dirs.Length > 0) { //Define search keys searchNames.Add(Name); searchNames.Add(Name.Replace(" ", "-").ToLower()); //Find the first file name matching one of the search keys and suffixed with "_profile" foreach (string sName in searchNames) { profiles = Directory.GetFiles(dirs[0], string.Concat(sName, "*_profile.txt"), SearchOption.TopDirectoryOnly); if (profiles.Length > 0) { pf = profiles[0]; break; } } //Read the profile text file // For data to be read properly, a value must immediately follow the corresponding key on the same line // and separated by a comma. // // ex. "Symbol,AC" or "Industry,Airline" if (pf != "") { profile_content = CSVParser.CSVtoListArray(pf, 20); //Symbol = profile_content.Where(arg => arg[0] == "Symbol").FirstOrDefault()[1]; pf_lines = profile_content.Where(arg => arg.Contains("Symbol")).FirstOrDefault(); Symbol = pf_lines[pf_lines.ToList().IndexOf("Symbol") + 1]; pf_lines = profile_content.Where(arg => arg.Contains("Industry")).FirstOrDefault(); Industry = pf_lines[pf_lines.ToList().IndexOf("Industry") + 1]; pf_lines = profile_content.Where(arg => arg.Contains("Sector")).FirstOrDefault(); Sector = pf_lines[pf_lines.ToList().IndexOf("Sector") + 1]; profileFound = true; } } } catch (Exception) { } if (!profileFound) { SetDefaultSymbol(); } }
/***************************************************************************** * FUNCTION: ReadDataFile * Description: * Parameters: *****************************************************************************/ public Boolean ReadDataFile() { Boolean success = false; List <String[]> rawData = null; int index1, index2; string linkStr; if (dataFileName != "") { //parse the CSV into a list of string arrays rawData = CSVParser.CSVtoListArray(dataFileName, MAX_DATA_SIZE); linkStr = rawData[0][0]; if (linkStr != null && linkStr.Contains("http")) { this.liveDataAddress = linkStr; } //array index of each column of data //Indexes hardcoded based on ICom tables //historical data - Dates hist_data_in = rawData.Select(arr => arr[0]).ToList(); hist_dates = hist_data_in.Skip(DATA_FILE_HEADER_ROWS).Select(date => DateTime.Parse(date)).ToList(); hist_dates.Reverse(); //historical data - Closing Price hist_data_in = rawData.Select(arr => arr[1]).ToList(); hist_price = hist_data_in.Skip(DATA_FILE_HEADER_ROWS).Select(dbl => Helpers.CustomParseDouble(dbl)).ToList(); hist_price.Reverse(); //historical data - Opening Price hist_data_in = rawData.Select(arr => arr[2]).ToList(); hist_price_opens = hist_data_in.Skip(DATA_FILE_HEADER_ROWS).Select(dbl => Helpers.CustomParseDouble(dbl)).ToList(); hist_price_opens.Reverse(); //historical data - High hist_data_in = rawData.Select(arr => arr[3]).ToList(); hist_price_highs = hist_data_in.Skip(DATA_FILE_HEADER_ROWS).Select(dbl => Helpers.CustomParseDouble(dbl)).ToList(); hist_price_highs.Reverse(); //historical data - Low hist_data_in = rawData.Select(arr => arr[4]).ToList(); hist_price_lows = hist_data_in.Skip(DATA_FILE_HEADER_ROWS).Select(dbl => Helpers.CustomParseDouble(dbl)).ToList(); hist_price_lows.Reverse(); //historical data - Volume hist_data_in = rawData.Select(arr => arr[5]).ToList(); hist_volumes = hist_data_in.Skip(DATA_FILE_HEADER_ROWS).Select(dbl => Helpers.CustomParseDouble(dbl)).ToList(); hist_volumes.Reverse(); //historical data - percent change hist_data_in = rawData.Select(arr => arr[6]).ToList(); hist_daily_change = hist_data_in.Skip(DATA_FILE_HEADER_ROWS).Select(dbl => Math.Round(double.Parse(dbl.Replace("%", "")), 8)).ToList(); hist_daily_change.Reverse(); index1 = dataFileName.LastIndexOf("\\") + 1; index2 = dataFileName.LastIndexOf(".csv"); if (index1 > 0 && index2 > 0) { Name = dataFileName.Substring(index1, index2 - index1); } //IMPORTANT: ValidateHistoricalData() must be called before updateHistPublicProperties() to ensure the private // "hist_" data lists are finalized with any duplicate values removed. if (ValidateHistoricalData()) { this.ContainsHistData = true; } GetProfile(); updateHistPublicProperties(); //Compute technical indicators CalculatePctChange(); CalculateAvgPrice(); CalculateVolatility(); ComputeTrend(); ComputeTechnicalIndicators(); //set return status successful success = true; } return(success); }