def company_page_analysis(stock_company): try: page = requests.get('http://money.rediff.com/%s' % stock_company) time.sleep(2) tree = html.fromstring(page.content) company = CompanyPage(tree) primary_stats = _get_company_primary_stats(company, tree) if all([primary_stats.get('pe_ratio') > MIN_PE_THRESHOLD, primary_stats.get('pe_ratio') < MAX_PE_THRESHOLD, primary_stats.get('eps') > MIN_EPS_THRESHOLD, primary_stats.get('price_of_stock') < ((primary_stats.get('fifty_two_wk_high') + primary_stats.get('fifty_two_wk_low'))/2)]): #get all links balance_sheet_link = company.get_balance_sheet_link(tree) dividend_link = company.get_dividend_link(tree) ratio_link = company.get_ratio_link(tree) # go to balance sheet page for further analysis balance_sheet_page = requests.get('%s' % ''.join(balance_sheet_link)) balance_sheet_tree = html.fromstring(balance_sheet_page.content) balance_sheet = BalanceSheet(balance_sheet_tree) current_assets_loans_advances = balance_sheet.get_current_assets_loans_advances(balance_sheet_tree) current_liabilities_and_provisions = balance_sheet.get_current_liabilities_and_provisions(balance_sheet_tree) total_net_current_assets = balance_sheet.get_total_net_current_assets(balance_sheet_tree) if total_net_current_assets > current_liabilities_and_provisions: # go to ratio page ratio_page = requests.get('%s' % ''.join(ratio_link)) ratio_tree = html.fromstring(ratio_page.content) ratio = Ratio(ratio_tree) if ratio.consistent_dividend_payout(ratio_tree): print(stock_company) except Exception as err: logger.error(err) return
def company_page_analysis(stock_company): try: page = requests.get('http://money.rediff.com/%s' % stock_company) time.sleep(2) tree = html.fromstring(page.content) company = CompanyPage(tree) primary_stats = _get_company_primary_stats(company, tree) if all([ primary_stats.get('pe_ratio') > MIN_PE_THRESHOLD, primary_stats.get('pe_ratio') < MAX_PE_THRESHOLD, primary_stats.get('eps') > MIN_EPS_THRESHOLD, primary_stats.get('price_of_stock') < ((primary_stats.get('fifty_two_wk_high') + primary_stats.get('fifty_two_wk_low')) / 2) ]): #get all links balance_sheet_link = company.get_balance_sheet_link(tree) dividend_link = company.get_dividend_link(tree) ratio_link = company.get_ratio_link(tree) # go to balance sheet page for further analysis balance_sheet_page = requests.get('%s' % ''.join(balance_sheet_link)) balance_sheet_tree = html.fromstring(balance_sheet_page.content) balance_sheet = BalanceSheet(balance_sheet_tree) current_assets_loans_advances = balance_sheet.get_current_assets_loans_advances( balance_sheet_tree) current_liabilities_and_provisions = balance_sheet.get_current_liabilities_and_provisions( balance_sheet_tree) total_net_current_assets = balance_sheet.get_total_net_current_assets( balance_sheet_tree) if total_net_current_assets > current_liabilities_and_provisions: # go to ratio page ratio_page = requests.get('%s' % ''.join(ratio_link)) ratio_tree = html.fromstring(ratio_page.content) ratio = Ratio(ratio_tree) if ratio.consistent_dividend_payout(ratio_tree): print(stock_company) except Exception as err: logger.error(err) return
from lxml import html from balance_sheet import BalanceSheet f = open(r"tests/balance_sheet_page_content") balance_sheet_page_content = f.read() f.close() balance_sheet_tree = html.fromstring(balance_sheet_page_content) balance_sheet = BalanceSheet(balance_sheet_tree) def test_get_current_assets_loans_advances(): current_assets_loans_advances = balance_sheet.get_current_assets_loans_advances( balance_sheet_tree) assert current_assets_loans_advances != 0.00 assert isinstance(current_assets_loans_advances, float) def test_get_current_liabilities_and_provisions(): current_liabilities_and_provisions = balance_sheet.get_current_liabilities_and_provisions( balance_sheet_tree) assert current_liabilities_and_provisions != 0.00 assert isinstance(current_liabilities_and_provisions, float) def test_get_total_net_current_assets(): total_net_current_assets = balance_sheet.get_total_net_current_assets( balance_sheet_tree) assert total_net_current_assets != 0.00 assert isinstance(total_net_current_assets, float)
from balance_sheet import BalanceSheet, add_expense, deposit sheet = BalanceSheet() deposit(sheet, 100) print sheet.balance for snapshot in sheet.replay(): print snapshot
def company_page_analysis(stock_company): try: page = requests.get('http://money.rediff.com/%s' % stock_company) time.sleep(1) tree = html.fromstring(page.content) company = CompanyPage(tree) primary_stats = _get_company_primary_stats(company, tree) # PE has to be greater than 0, Negative PE means that the company is # not making profit. pe_ratio_min = primary_stats.get('pe_ratio') > MIN_PE_THRESHOLD # PE has to be less than 15. If greater it means that the company is # overpriced. pe_ratio_max = primary_stats.get('pe_ratio') < MAX_PE_THRESHOLD # Company should be making some profit. eps_cond = primary_stats.get('eps') > MIN_EPS_THRESHOLD # prices towards the lower range. price_somewhr_in_middle = (primary_stats.get('price_of_stock') < ( (primary_stats.get('fifty_two_wk_high') + primary_stats.get('fifty_two_wk_low')) / 2)) # total money interchanged greater than 10 times what I will be # investing. Else I may not find people that will be willing to buy or # sell at the expected rate and there may be too much fluctuation. total_money_floating = (primary_stats.get('volume') * primary_stats.get('price_of_stock')) #if total_money_floating < 10 * MY_RISK_TOLERANCE: # return if TESTING: print('primary_stats: {}'.format(primary_stats)) conditions = [ pe_ratio_min, pe_ratio_max, eps_cond, price_somewhr_in_middle ] if TESTING: print('all_conditions: {}'.format(conditions)) if all(conditions) is True: # get all links balance_sheet_link = company.get_balance_sheet_link(tree) ratio_link = company.get_ratio_link(tree) # go to balance sheet page for further analysis balance_sheet_page = requests.get('%s' % ''.join(balance_sheet_link)) balance_sheet_tree = html.fromstring(balance_sheet_page.content) balance_sheet = BalanceSheet(balance_sheet_tree) current_liabilities_and_provisions = balance_sheet.get_current_liabilities_and_provisions( balance_sheet_tree) total_net_current_assets = ( balance_sheet.get_total_net_current_assets(balance_sheet_tree)) if TESTING is True: print('{stock_company} has ' 'total_net_current_assets: {total_net_current_assets}' 'and current_liabilities_and_provisions: ' '{current_liabilities_and_provisions}'.format( stock_company=stock_company, total_net_current_assets=total_net_current_assets, current_liabilities_and_provisions= current_liabilities_and_provisions)) if total_net_current_assets > current_liabilities_and_provisions: if TESTING: print( 'company {} has net asset greater than net liabilities' .format(stock_company)) # go to ratio page ratio_page = requests.get('%s' % ''.join(ratio_link)) ratio_tree = html.fromstring(ratio_page.content) ratio = Ratio(ratio_tree) if TESTING: print('ratio consistent_dividend_payout: {}'.format( ratio.consistent_dividend_payout(ratio_tree))) if ratio.consistent_dividend_payout(ratio_tree): print( '{stock_company} ! total_net_current_assets: {total_net_current_assets} ! current_liabilities_and_provisions: {current_liabilities_and_provisions}' .format( stock_company=stock_company.strip(), total_net_current_assets=total_net_current_assets, current_liabilities_and_provisions= current_liabilities_and_provisions)) except Exception as err: logger.error(err) return