public void TestSectorStockCount() { IPdfService pdfService = new PdfTextSharpService(); var pseDocument = new PSEDocument(); IPSEReportReader reader = new PSEReportReader2(); reader.Fill(pseDocument, pdfService.ExtractTextFromPdf(_reportFile)); var finance = pseDocument.GetSector(PSEDocument.FINANCIAL); var expected = 0; var actual = 0; Assert.AreEqual(expected, actual, PSEDocument.FINANCIAL + " sector stock count fail."); var industrial = pseDocument.GetSector(PSEDocument.INDUSTRIAL); expected = 0; actual = 0; Assert.AreEqual(expected, actual, PSEDocument.INDUSTRIAL + " sector stock count fail."); var property = pseDocument.GetSector(PSEDocument.PROPERTY); expected = 0; actual = 0; Assert.AreEqual(expected, actual, PSEDocument.PROPERTY + " sector stock count fail."); var services = pseDocument.GetSector(PSEDocument.SERVICE); expected = 0; actual = 0; Assert.AreEqual(expected, actual, PSEDocument.SERVICE + " sector stock count fail."); var mining = pseDocument.GetSector(PSEDocument.MINING_OIL); expected = 0; Assert.AreEqual(expected, actual, PSEDocument.MINING_OIL + " sector stock count fail."); var preferred = pseDocument.GetSector(PSEDocument.PREFERRED); expected = 0; actual = 0; Assert.AreEqual(expected, actual, PSEDocument.PREFERRED + " sector stock count fail."); var warrants = pseDocument.GetSector(PSEDocument.WARRANT); expected = 0; actual = 0; Assert.AreEqual(expected, actual, PSEDocument.WARRANT + " sector stock count fail."); var sme = pseDocument.GetSector(PSEDocument.SME); expected = 0; actual = 0; Assert.AreEqual(expected, actual, PSEDocument.SME + " sector stock count fail."); }
private void ParseForeignTransaction() { // foreign buy/sell var pattern = @"(FOREIGN\s+)(BUYING|SELLING):\s+Php\s([0-9\.\s,\(\)\-]+)"; MatchCollection matches = Regex.Matches(_reportString, pattern); Nullable <double> nfb = null; Nullable <double> nfs = null; nfb = matches[0].Groups[3].Value.ParseDouble(); nfs = matches[1].Groups[3].Value.ParseDouble(); SectorItem psei = _pseDocument.GetSector(PSEDocument.PSEI); psei.NetForeignBuy = Math.Round((double)nfb - (double)nfs, 2); _pseDocument.TotalForeignBuying = (double)nfb; _pseDocument.TotalForeignSelling = (double)nfs; }
public void TestMarketSummary_PSEi() { IPdfService pdfService = new PdfTextSharpService(); var pseDocument = new PSEDocument(); IPSEReportReader reader = new PSEReportReader2(); reader.Fill(pseDocument, pdfService.ExtractTextFromPdf(_reportFile)); //OPEN HIGH LOW CLOSE %CHANGE PT.CHANGE VOLUME VALUE, Php //PSEi 7,363.88 7,456.26 7,354.57 7,446.49 1.42 104.84 //All Shares 4,424.05 4,464.21 4,420.44 4,460.56 1.06 47.14 //GRAND TOTAL 1,949,153,231 11,941,051,832.83 var expected = 0.0; var actual = 0.0; //psei var psei = pseDocument.GetSector(PSEDocument.PSEI); expected = 7363.88; actual = psei.Open; Assert.AreEqual(expected, actual, "PSEi open does not match"); expected = 7456.26; actual = psei.High; Assert.AreEqual(expected, actual, "PSEi high does not match"); expected = 7354.57; actual = psei.Low; Assert.AreEqual(expected, actual, "PSEi low does not match"); expected = 7446.49; actual = psei.Close; Assert.AreEqual(expected, actual, "PSEi close does not match"); expected = 1949153231.0; actual = psei.Volume; Assert.AreEqual(expected, actual, "PSEi Volume does not match"); expected = 4076175042.08; actual = psei.NetForeignBuy; Assert.AreEqual(expected, actual, "PSEi NFB does not match"); //all shares }
public void TestMarketSummary_Financials() { IPdfService pdfService = new PdfTextSharpService(); var pseDocument = new PSEDocument(); IPSEReportReader reader = new PSEReportReader2(); reader.Fill(pseDocument, pdfService.ExtractTextFromPdf(_reportFile)); //OPEN HIGH LOW CLOSE %CHANGE PT.CHANGE VOLUME VALUE, Php //Financials 1,835.16 1,865.93 1,830.89 1,865.93 1.7 31.31 15,721,945 1,537,689,244.77 //GRAND TOTAL 1,949,153,231 11,941,051,832.83 var expected = 0.0; var actual = 0.0; //psei var psei = pseDocument.GetSector(PSEDocument.FINANCIAL); expected = 1835.16; actual = psei.Open; Assert.AreEqual(expected, actual, "FINANCIAL open does not match"); expected = 1865.93; actual = psei.High; Assert.AreEqual(expected, actual, "FINANCIAL high does not match"); expected = 1830.89; actual = psei.Low; Assert.AreEqual(expected, actual, "FINANCIAL low does not match"); expected = 1865.93; actual = psei.Close; Assert.AreEqual(expected, actual, "FINANCIAL close does not match"); expected = 15721945.0; actual = psei.Volume; Assert.AreEqual(expected, actual, "FINANCIAL Volume does not match"); expected = 1537689244.77; actual = psei.Value; Assert.AreEqual(expected, actual, "FINANCIAL Value does not match"); //all shares }
public void TestReader_SectorSummary() { var stripper = new PDFTextStripper(); var reader = new PSEReportReader(stripper.getText(doc).TrimEnd()); var pd = new PSEDocument(); reader.Fill(pd); // psei SectorItem psei = pd.GetSector(PSEDocument.PSEI); ulong expected = 7786326861; ulong actual = psei.Volume; Assert.AreEqual(expected, actual, "PSEi volume not equal"); double expected_value = 12960265679.1516; double actual_value = pd.GetSector(PSEDocument.PSEI).Value; Assert.AreEqual(expected_value, actual_value, "PSEi value not equal"); expected_value = 3979.97; actual_value = psei.Open; Assert.AreEqual(expected_value, actual_value, "PSEi open not equal"); expected_value = 4053.32; actual_value = psei.High; Assert.AreEqual(expected_value, actual_value, "PSEi high not equal"); expected_value = 3979.97; actual_value = psei.Low; Assert.AreEqual(expected_value, actual_value, "PSEi low not equal"); expected_value = 4053.32; actual_value = psei.Close; Assert.AreEqual(expected_value, actual_value, "PSEi close not equal"); // financial SectorItem financial = pd.GetSector(PSEDocument.FINANCIAL); expected = 24780801; actual = financial.Volume; Assert.AreEqual(expected, actual, "Financial volume not equal"); expected_value = 882690827.9; actual_value = financial.Value; Assert.AreEqual(expected, actual, "Financial value not equal"); //913.01 935.52 909.34 935.52 2.47 22.51 24,780,801 882,690,827.9 expected_value = 913.01; actual_value = financial.Open; Assert.AreEqual(expected_value, actual_value, "Financial open not equal"); expected_value = 935.52; actual_value = financial.High; Assert.AreEqual(expected_value, actual_value, "Financial high not equal"); expected_value = 909.34; actual_value = financial.Low; Assert.AreEqual(expected_value, actual_value, "Financial low not equal"); expected_value = 935.52; actual_value = financial.Close; Assert.AreEqual(expected_value, actual_value); // mining SectorItem mining = pd.GetSector(PSEDocument.MINING_OIL); expected = 3832444034; actual = mining.Volume; Assert.AreEqual(expected, actual, "Mining volume not equal"); expected_value = 977394265.25; actual_value = mining.Value; Assert.AreEqual(expected, actual, "Mining value not equal"); //11,644.77 12,468.64 11,644.77 12,387.7 7.97 914.68 3,832,444,034 977,394,265.25 expected_value = 11644.77; actual_value = mining.Open; Assert.AreEqual(expected_value, actual_value); expected_value = 12468.64; actual_value = mining.High; Assert.AreEqual(expected_value, actual_value); expected_value = 11644.77; actual_value = mining.Low; Assert.AreEqual(expected_value, actual_value); expected_value = 12387.7; actual_value = mining.Close; Assert.AreEqual(expected_value, actual_value); SectorItem pse = pd.GetSector(PSEDocument.PSEI); expected_value = 1938423893.11; actual_value = pse.NetForeignBuy; Assert.AreEqual(expected_value, actual_value); }
public void TestReader_SectorSummary() { //PDFTextStripper stripper = new PDFTextStripper(); IPdfService pdfService = new PdfTextSharpService(); var reader = new PSEReportReader2(); var pd = new PSEDocument(); reader.Fill(pd, pdfService.ExtractTextFromPdf(pdfDocPath)); // psei SectorItem psei = pd.GetSector(PSEDocument.PSEI); ulong expected = 3150242905; ulong actual = psei.Volume; Assert.AreEqual(expected, actual, "PSEi volume not equal"); double expected_value = 5634576802.26; double actual_value = pd.GetSector(PSEDocument.PSEI).Value; Assert.AreEqual(expected_value, actual_value, "PSEi value not equal"); expected_value = 7007.63; actual_value = psei.Open; Assert.AreEqual(expected_value, actual_value, "PSEi open not equal"); expected_value = 7011.28; actual_value = psei.High; Assert.AreEqual(expected_value, actual_value, "PSEi high not equal"); expected_value = 6986.86; actual_value = psei.Low; Assert.AreEqual(expected_value, actual_value, "PSEi low not equal"); expected_value = 6999.75; actual_value = psei.Close; Assert.AreEqual(expected_value, actual_value, "PSEi close not equal"); // financial SectorItem financial = pd.GetSector(PSEDocument.FINANCIAL); expected = 8105540; actual = financial.Volume; Assert.AreEqual(expected, actual, "Financial volume not equal"); expected_value = 755542372.19; actual_value = financial.Value; Assert.AreEqual(expected, actual, "Financial value not equal"); //913.01 935.52 909.34 935.52 2.47 22.51 24,780,801 882,690,827.9 expected_value = 1585.35; actual_value = financial.Open; Assert.AreEqual(expected_value, actual_value, "Financial open not equal"); expected_value = 1585.39; actual_value = financial.High; Assert.AreEqual(expected_value, actual_value, "Financial high not equal"); expected_value = 1577.85; actual_value = financial.Low; Assert.AreEqual(expected_value, actual_value, "Financial low not equal"); expected_value = 1583.44; actual_value = financial.Close; Assert.AreEqual(expected_value, actual_value); // mining SectorItem mining = pd.GetSector(PSEDocument.MINING_OIL); expected = 2528326978; actual = mining.Volume; Assert.AreEqual(expected, actual, "Mining volume not equal"); expected_value = 143087427.64; actual_value = mining.Value; Assert.AreEqual(expected, actual, "Mining value not equal"); //11,644.77 12,468.64 11,644.77 12,387.7 7.97 914.68 3,832,444,034 977,394,265.25 expected_value = 10885.19; actual_value = mining.Open; Assert.AreEqual(expected_value, actual_value); expected_value = 10886.63; actual_value = mining.High; Assert.AreEqual(expected_value, actual_value); expected_value = 10700.58; actual_value = mining.Low; Assert.AreEqual(expected_value, actual_value); expected_value = 10740.09; actual_value = mining.Close; Assert.AreEqual(expected_value, actual_value); SectorItem pse = pd.GetSector(PSEDocument.PSEI); expected_value = -616052104.21; actual_value = pse.NetForeignBuy; Assert.AreEqual(expected_value, actual_value); }
/// <summary> /// Parse stock information into pseDocument object /// </summary> /// <param name="pseDocument"></param> private void ParseReportBody(PSEDocument pseDocument) { SectorItem sector = null; Nullable <ulong> uLongValue = null; Nullable <double> doubleValue = null; foreach (string s in this.reportBody) { //retrieve the sector object then move on to the next line if (sectorNameMap.ContainsValue(s)) { sector = pseDocument.GetSector(sectorNameMap.GetKey(s)); bool parseCondition = (s == sectorNameMap[PSEDocument.PREFERRED]) || (s == sectorNameMap[PSEDocument.SME]) || (s == sectorNameMap[PSEDocument.WARRANT]); if (DateTime.Compare(_tradeDate, _reportChangeDate1) >= 0) { parseCondition = parseCondition || s == sectorNameMap[PSEDocument.DEPOSITORY_RECEIPTS]; } if (DateTime.Compare(_tradeDate, _reportChangeDate2) >= 0) { parseCondition = parseCondition || s == sectorNameMap[PSEDocument.ETF]; } if (DateTime.Compare(_tradeDate, _reportChangeDate3) >= 0) { parseCondition = parseCondition || s == sectorNameMap[PSEDocument.DOLLAR_DONOMINATED_SECURITIES]; } if (parseCondition) { var subSector = new SubSectorItem(); subSector.Name = s; sector.SubSectors.Add(subSector); } continue; } string[] row = s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (row[0] == "****") { // retrieve the subsector then create the subsector object // continue to the next line after var subSector = new SubSectorItem(); string subSectorName = s.Replace("****", null); subSector.Name = subSectorName.Trim(); sector.SubSectors.Add(subSector); continue; } // skip volume summary if (s.Contains("TOTAL VOLUME")) { continue; } if (sector.SubSectors.Count == 0) { sector.SubSectors.Add(new SubSectorItem() { Name = "UNKNOWN" }); } // now load stock information into the subsector object row = row.Reverse <string>().ToArray <string>(); SubSectorItem currentSubSector = sector.SubSectors[sector.SubSectors.Count - 1]; // always points to the last added subsector //Name Symbol Bid Ask Open High Low Close Volume Value NB/S //in reverse order StockItem stock = new StockItem(pseDocument, sector); doubleValue = row[0].ParseDouble(); stock.NetForeignBuy = doubleValue.HasValue ? (double)doubleValue : 0; doubleValue = row[1].ParseDouble(); stock.Value = doubleValue.HasValue ? (double)doubleValue : 0; uLongValue = row[2].ParseUlong(); stock.Volume = uLongValue.HasValue ? (ulong)uLongValue : 0; doubleValue = row[3].ParseDouble(); stock.Close = doubleValue.HasValue ? (double)doubleValue : 0; doubleValue = row[4].ParseDouble(); stock.Low = doubleValue.HasValue ? (double)doubleValue : 0; doubleValue = row[5].ParseDouble(); stock.High = doubleValue.HasValue ? (double)doubleValue : 0; doubleValue = row[6].ParseDouble(); stock.Open = doubleValue.HasValue ? (double)doubleValue : 0; doubleValue = row[7].ParseDouble(); stock.Ask = doubleValue.HasValue ? (double)doubleValue : 0; doubleValue = row[8].ParseDouble(); stock.Bid = doubleValue.HasValue ? (double)doubleValue : 0; stock.Symbol = row[9]; int index = 9; StringBuilder sb = new StringBuilder(); for (int i = row.Length - 1; i > index; i--) { sb.Append(row[i] + " "); } stock.Description = sb.ToString().TrimEnd(); currentSubSector.Stocks.Add(stock); } }
private void ParseSectorSummary(PSEDocument pseDocument) { string[] row; int i = 0; Nullable <double> nfb = null; Nullable <double> nfs = null; foreach (string s in this.sectorSummary) { row = s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Reverse <string>().ToArray <string>(); //OPEN HIGH LOW CLOSE %CHANGE PT.CHANGE VOLUME VALUE SectorItem sectorItem = pseDocument.Sectors[i]; if (s.Contains("PSEi") || s.Contains("All Shares")) { sectorItem.PointChange = double.Parse(row[0], NumberStyles.Any); sectorItem.PercentChange = double.Parse(row[1], NumberStyles.Any); sectorItem.Close = double.Parse(row[2], NumberStyles.Any); sectorItem.Low = double.Parse(row[3], NumberStyles.Any); sectorItem.High = double.Parse(row[4], NumberStyles.Any); sectorItem.Open = double.Parse(row[5], NumberStyles.Any); } else if (s.Contains("GRAND TOTAL")) { sectorItem = pseDocument.GetSector(PSEDocument.PSEI); sectorItem.Value = double.Parse(row[0], NumberStyles.Any); if (DateTime.Compare(_tradeDate, _reportChangeDate1) >= 0) { sectorItem.Volume = ulong.Parse(row[1], NumberStyles.Any); } else { sectorItem.Volume = ulong.Parse(row[2], NumberStyles.Any); } } else if (s.Contains("SME") || s.Contains("ETF")) { continue; } else if (s.Contains("FOREIGN")) { if (s.Contains("FOREIGN BUYING")) { nfb = row[0].ParseDouble(); if (!nfb.HasValue) { nfb = 0; } } if (s.Contains("FOREIGN SELLING")) { nfs = row[0].ParseDouble(); if (!nfs.HasValue) { nfs = 0; } // nothing more to parse after foreign selling break; } } else if (s.Contains("and Block Sale transactions.") || s.Contains("NET FOREIGN") || s.Contains("TOTAL FOREIGN")) { continue; } else { sectorItem.Open = double.Parse(row[7], NumberStyles.Any); sectorItem.High = double.Parse(row[6], NumberStyles.Any); sectorItem.Low = double.Parse(row[5], NumberStyles.Any); sectorItem.Close = double.Parse(row[4], NumberStyles.Any); sectorItem.PercentChange = double.Parse(row[3], NumberStyles.Any); sectorItem.PointChange = double.Parse(row[2], NumberStyles.Any); sectorItem.Volume = ulong.Parse(row[1], NumberStyles.Any); sectorItem.Value = double.Parse(row[0], NumberStyles.Any); } i++; } SectorItem psei = pseDocument.GetSector(PSEDocument.PSEI); psei.NetForeignBuy = Math.Round((double)nfb - (double)nfs, 2); //calculate sector netforeign buying/selling foreach (SectorItem sectorItem in pseDocument.Sectors) { if (sectorItem.Symbol == "^PSEi") { continue; } sectorItem.NetForeignBuy = 0; foreach (SubSectorItem subSectorItem in sectorItem.SubSectors) { foreach (StockItem stockItem in subSectorItem.Stocks) { sectorItem.NetForeignBuy += stockItem.NetForeignBuy; } } } }