The following code is meant to narrow down the list of the tickers of public companies
that have Bitcoin on their balance sheet (stored in list_of_tcks
) to those that do not pay dividends (stored in leanCompanies
).
#!/usr/bin/env python3
from yfinance import pdr_override, Ticker
def give_me_list_of_no_div_payers(list_of_tcks):
list_refined = []
list_of_payers = []
for t in list_of_tcks:
if len(Ticker(t).dividends) < 1:
list_refined.append(t)
elif len(Ticker(t).dividends) > 0:
list_of_payers.append(t)
return (list_refined, list_of_payers)
def print_stock_div(ticker):
print(f"{ticker}:")
print(Ticker(ticker).dividends)
list_of_tcks = ['MSTR', 'TSLA', 'BRPHF', 'VOYG', 'MARA', 'SQ', 'HUT', 'RIOT', 'BITF', 'CORZ', 'COIN', 'BTGGF', 'HIVE', 'ARBKF', 'NEXOF', '', 'BROOK', 'HKD', 'BTBT', 'HSSHF', 'BBKCF', 'DMGGF', 'CLSK', 'HODL', 'ABT', 'DGGXF', 'NPPTF', 'CBIT', 'MELI', 'OTC', 'BNXAF', 'PHUN', 'BTCS', 'FRMO', 'SATO', 'MILE', 'MOGO', 'NTHOL TI']
print(list_of_tcks)
print(len(list_of_tcks))
leanCompanies = give_me_list_of_no_div_payers(list_of_tcks)[0]
print(leanCompanies)
fatCompanies = give_me_list_of_no_div_payers(list_of_tcks)[1]
print("Following is the detailed info on the dividends of the fat companies:")
for t in fatCompanies:
print(f"{t}:")
print(Ticker(t).dividends)
I noticed that when there is a positive history of paying dividends
the type of Ticker(t).dividends
is either pandas.core.series.Series
.
When the firm has never paid its dividend the type of Ticker(t).dividends
is either pandas.core.series.Series
or a list
.
1. Why are there such two types?
2. Is testing for the value of len(Ticker(t).dividends)
a reliable way of getting the list of firms that do not pay dividends?
3. Is there another way of obtaining such a list?
[0]
print line, you will see that there is a list
for those that return - <ticker>: No data found, symbol may be delisted
, and a pd.Series
where the ticker is available, but there is no dividend.len(Tickers(t).dividends)
is sensible, this output is correct for each ticker in your list.elif:
, you can use else:
instead. As the length of the dividends will either be 0
(to be in list_refined
) or not (will be in list_of_payers
). So you can clean up the code with the following instead:#Option 1
def give_me_list_of_no_div_payers(list_of_tcks):
list_refined = []
list_of_payers = []
for t in list_of_tcks:
if len(Ticker(t).dividends) == 0:
list_refined.append(t)
else:
list_of_payers.append(t)
return (list_refined, list_of_payers)
#Option 2 - list comprehension
def give_me_list_of_no_div_payers_2(list_of_tcks):
list_refined = []
list_of_payers = []
[list_refined.append(t) \
if len(Ticker(t).dividends) == 0 \
else list_of_payers.append(t) \
for t in list_of_tcks ]
return [list_refined, list_of_payers]
Other than this I don't know!