Example #1
0
        /*****************************************************************************
        *  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);
        }
Example #2
0
        /*****************************************************************************
        *  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);
        }