def test_return_on_assets(self): bss = [BalanceSheet(data), BalanceSheet(previous_data)] ics = [IncomeStatement(data), IncomeStatement(previous_data)] cfs = [CashFlow(data), CashFlow(previous_data)] fs = FinancialPerformance('TEST', bss, ics, cfs) assert fs.return_on_asset(2016) == 1.0
def test_profit_margin(self): bss = [BalanceSheet(data), BalanceSheet(previous_data)] ics = [IncomeStatement(data), IncomeStatement(previous_data)] cfs = [CashFlow(data), CashFlow(previous_data)] fs = FinancialPerformance('TEST', bss, ics, cfs) assert fs.profit_margin(2016) == 1.0
def test_get_cash_flow_by_year(self): balance_sheet = BalanceSheet(data) income_statement = IncomeStatement(data) cash_flow = CashFlow(data) fs = FinancialPerformance('TEST', [income_statement], [balance_sheet], [cash_flow]) assert isinstance(fs.get_cash_flow_by_year(2016), CashFlow)
def test_init_financial_statements(self): balance_sheet = BalanceSheet(data) income_statement = IncomeStatement(data) cash_flow = CashFlow(data) fs = FinancialPerformance('TEST', [income_statement], [balance_sheet], [cash_flow]) assert isinstance(fs, FinancialPerformance)
def get_statements(self, tokens, database='SF0', mode='MRY'): if not tokens: return None data = self._cache_service.get_statements(tokens) # print(statements) if data is None or data.empty: needed_quandl_codes = {} for code in codes: needed_quandl_codes[code] = '{d}/{s}_{c}_{m}'.format( d=database, s=tokens['ticker'], c=code, m=mode) quandl.ApiConfig.api_key = self._config['quandl']['api_key'] data = quandl.get(list(needed_quandl_codes.values())) self._cache_service.save_statements(tokens, data.to_csv()) balance_sheets = [] income_statements = [] cash_flows = [] for timestamp, row_data in data.iterrows(): # print(timestamp) # print(row_data['SF0/AAPL_DEPAMOR_MRY - Value']) balance_sheet = {} for key, value in sample_balance_sheet.items(): balance_sheet[key] = row_data[self._format_code( tokens['ticker'], value)] balance_sheet['year'] = timestamp.year balance_sheets.append(BalanceSheet(balance_sheet)) income_statement = {} for key, value in sample_income_statement.items(): income_statement[key] = row_data[self._format_code( tokens['ticker'], value)] income_statement['year'] = timestamp.year income_statements.append(IncomeStatement(income_statement)) cash_flow = {} for key, value in sample_cash_flow.items(): cash_flow[key] = row_data[self._format_code( tokens['ticker'], value)] cash_flow['year'] = timestamp.year cash_flows.append(CashFlow(cash_flow)) fp = FinancialPerformance(tokens['ticker'], income_statements, balance_sheets, cash_flows) return fp