def storeValuationSummaryBrief(tickers = None): store = Storage() if tickers is None: xls = XLSio(store) xls.loadWorkbook("StockSummary") xls.table = xls.table[xls.table["P/E Ratio (TTM)"].notnull()] tickers = xls.getTickers() summary = {} count = 1.0 errors = {} print("Assessing " + str(len(tickers)) + " companies") for ticker in tickers: try: reporter = Reporter(ticker) summary[ticker] = reporter.oneLineValuation() except MissingStatementEntryError as E: errors[ticker] = E.message except InsufficientDataError as E: errors[ticker] = E.message except Exception as E: errors[ticker] = E.message if count % max(len(tickers) / 4, 1) == 0: pct_complete = round(100.0 * count / len(tickers)) print(str(pct_complete) + "% complete") count += 1 index = summary.items()[0][1].index summary = pandas.DataFrame(summary, index = index).T summary.to_excel(store.excel("ValuationSummary")) print(str(len(errors)) + " Failed") print(str(len(summary)) + " Succeeded") return errors
def setUp(self): self.filename = "test_file" store = Storage("..\\testData\\") self.filepath = store.excel("test_file") self.xls = XLSio(store) self.xls.table = Mock() self.xls.table.to_excel = Mock()
def saveAnalysisToExcel(ticker): results = Reporter(ticker) store = Storage() writer = pandas.ExcelWriter(store.excel(ticker + "analysis")) results.summaryTable().to_excel(writer, "Summary") results.financials.income.income_sheet.to_excel(writer, "Income") assets = results.financials.balance.asset_sheet liabilities = results.financials.balance.liabilities assets.to_excel(writer, "Balance") liabilities.to_excel(writer, "Balance", startrow = len(assets) + 1) operating = results.financials.cashflow.operating investing = results.financials.cashflow.investing financing = results.financials.cashflow.financing operating.to_excel(writer, "Cashflow") investing.to_excel(writer, "Cashflow", startrow = len(operating) + 1) financing.to_excel(writer, "Cashflow", startrow = len(operating) + len(investing) + 2) writer.save()
class Test_Storage(unittest.TestCase): def setUp(self): self.root_location = "..\\testData\\" self.store = Storage(self.root_location) def test_StorageLocationForExcel(self): filename = "test" expected_filepath = self.root_location + filename + ".xlsx" self.assertEqual(self.store.excel(filename), expected_filepath) def test_StorageLocationForHTML(self): ticker = "AAA" type = "overview" expected_filepath = self.root_location + ticker + "\\" + ticker + type + ".html" self.assertEqual(self.store.html(ticker, type), expected_filepath) def test_StorageLocationForStockPickle(self): ticker = "AAA" type = "income" expected_filepath = self.root_location + ticker + "\\pickles\\" + type + ".pkl" self.assertEqual(self.store.stock_pickle(ticker, type), expected_filepath)