0

Currently, I am trying to create a stock screener based on financial data, such as the balance sheet, income statements, and cash flow statements. I found a great package on the Internet "yahoofinancials" that takes data from yahoo for any stock and outputs it as a dictionary. The only problem is that, whenever I try to access the data, because it's in multiple dictionaries, I cannot. I've searched the internet for days, but the only resources are for dictionaries that are not locked inside others. Here is the code that I am tryinng to run, then I'll show the balance sheet dictionary.

from yahoofinancials import YahooFinancials

ticker = input("Enter exact stock ticker in upper-case lettering: ")
yahoo_financials = YahooFinancials(ticker)

balance_sheet_data_annual = yahoo_financials.get_financial_stmts('annual', 'balance')
cash_flow_sheet_data_annual = yahoo_financials.get_financial_stmts('annual', 'cash')
income_statement_data_annual = yahoo_financials.get_financial_stmts('annual', 'income')
all_statement_data_annual = yahoo_financials.get_financial_stmts('annual', ['income', 'cash', 'balance'])
ten_yr_bond_yield = YahooFinancials(['^TNX'])

totalStockHolderEquity = {'balanceSheetHistory'}
totalStockHolderEquityi = balance_sheet_data_annual['totalStockHolderEquity']

# tests for dictionary navigation
print(totalStockHolderEquityi)
print(balance_sheet_data_annual)

Here is the dictionary

{'balanceSheetHistory': {'AAPL': [{'2020-09-26': {'totalLiab': 258549000000, 'totalStockholderEquity': 65339000000, 'otherCurrentLiab': 47867000000, 'totalAssets': 323888000000, 'commonStock': 50779000000, 'otherCurrentAssets': 11264000000, 'retainedEarnings': 14966000000, 'otherLiab': 46108000000, 'treasuryStock': -406000000, 'otherAssets': 33952000000, 'cash': 38016000000, 'totalCurrentLiabilities': 105392000000, 'shortLongTermDebt': 8773000000, 'otherStockholderEquity': -406000000, 'propertyPlantEquipment': 45336000000, 'totalCurrentAssets': 143713000000, 'longTermInvestments': 100887000000, 'netTangibleAssets': 65339000000, 'shortTermInvestments': 52927000000, 'netReceivables': 37445000000, 'longTermDebt': 98667000000, 'inventory': 4061000000, 'accountsPayable': 42296000000}}, {'2019-09-28': {'totalLiab': 248028000000, 'totalStockholderEquity': 90488000000, 'otherCurrentLiab': 43242000000, 'totalAssets': 338516000000, 'commonStock': 45174000000, 'otherCurrentAssets': 12352000000, 'retainedEarnings': 45898000000, 'otherLiab': 50503000000, 'treasuryStock': -584000000, 'otherAssets': 32978000000, 'cash': 48844000000, 'totalCurrentLiabilities': 105718000000, 'shortLongTermDebt': 10260000000, 'otherStockholderEquity': -584000000, 'propertyPlantEquipment': 37378000000, 'totalCurrentAssets': 162819000000, 'longTermInvestments': 105341000000, 'netTangibleAssets': 90488000000, 'shortTermInvestments': 51713000000, 'netReceivables': 45804000000, 'longTermDebt': 91807000000, 'inventory': 4106000000, 'accountsPayable': 46236000000}}, {'2018-09-29': {'totalLiab': 258578000000, 'totalStockholderEquity': 107147000000, 'otherCurrentLiab': 39293000000, 'totalAssets': 365725000000, 'commonStock': 40201000000, 'otherCurrentAssets': 12087000000, 'retainedEarnings': 70400000000, 'otherLiab': 48914000000, 'treasuryStock': -3454000000, 'otherAssets': 22283000000, 'cash': 25913000000, 'totalCurrentLiabilities': 115929000000, 'shortLongTermDebt': 8784000000, 'otherStockholderEquity': -3454000000, 'propertyPlantEquipment': 41304000000, 'totalCurrentAssets': 131339000000, 'longTermInvestments': 170799000000, 'netTangibleAssets': 107147000000, 'shortTermInvestments': 40388000000, 'netReceivables': 48995000000, 'longTermDebt': 93735000000, 'inventory': 3956000000, 'accountsPayable': 55888000000}}, {'2017-09-30': {'totalLiab': 241272000000, 'totalStockholderEquity': 134047000000, 'otherCurrentLiab': 38099000000, 'totalAssets': 375319000000, 'commonStock': 35867000000, 'otherCurrentAssets': 13936000000, 'retainedEarnings': 98330000000, 'otherLiab': 43251000000, 'treasuryStock': -150000000, 'otherAssets': 18177000000, 'cash': 20289000000, 'totalCurrentLiabilities': 100814000000, 'shortLongTermDebt': 6496000000, 'otherStockholderEquity': -150000000, 'propertyPlantEquipment': 33783000000, 'totalCurrentAssets': 128645000000, 'longTermInvestments': 194714000000, 'netTangibleAssets': 134047000000, 'shortTermInvestments': 53892000000, 'netReceivables': 35673000000, 'longTermDebt': 97207000000, 'inventory': 4855000000, 'accountsPayable': 44242000000}}]}}

Any help in the form of example code, or learning resources would be greatly appreciated!

Elliott
  • 1
  • 1
  • `{'balanceSheetHistory'}` is a set containing the string, it's not accessing anything in the dictionary. – Barmar Dec 24 '20 at 17:21
  • `balance_sheet_data_annual['balanceSheetHistory']['AAPL'][0]['2020-09-26']['totalStockholderEquity']` – Barmar Dec 24 '20 at 17:22
  • Don't miss the fact that some of the data is in lists, you need to index them. – Barmar Dec 24 '20 at 17:22

0 Answers0