def before_trading_start(context, data):
log.info("Test-before_trading_start")
dividendList = get_fundamentals(
query(
fundamentals.company_reference.short_name,
fundamentals.company_reference.primary_symbol,
fundamentals.valuation_ratios.payout_ratio,
fundamentals.valuation_ratios.dividend_yield
)
.filter(
fundamentals.valuation_ratios.dividend_yield > 0
)
.order_by(
fundamentals.valuation_ratios.forward_dividend_yield.desc()
)
.limit(100)
)
for stock in dividendList:
log.info(str(dividendList[stock]['primary_symbol'] )+ ", " + dividendList[stock]['short_name'] + ", " + str(dividendList[stock]['dividend_yield']) );
Which then results in the following output:
2016-01-28before_trading_start:8INFOTest-before_trading_start
2016-01-28before_trading_start:27INFOCOWN, Cowen Group, 3.1391
2016-01-28before_trading_start:27INFOCBIO, Catalyst Biosciences, 1.7323
2016-01-28before_trading_start:27INFONATDF, North Atlantic Drilling, 0.2667
2016-01-28before_trading_start:27INFOLGCY, Legacy Reserves, 1.2696
2016-01-28before_trading_start:27INFOSXE, Southcross Energy, 2.5806
2016-01-28before_trading_start:27INFOENRJ, Enerjex Resources, 2.1701
2016-01-28before_trading_start:27INFOEVEP, EV Energy Partners, 0.8621
2016-01-28before_trading_start:27INFOPER, SandRidge Permian, 0.7813
2016-01-28before_trading_start:27INFOCLF, Cliffs Natural Resources, 1.306
2016-01-28before_trading_start:27INFOFELP, Foresight Energy, 0.7273
2016-01-28before_trading_start:27INFOTOO, Teekay Offshore Partners, 0.5229
2016-01-28before_trading_start:27INFOEMES, Emerge Energy Services, 1.0769
2016-01-28before_trading_start:27INFOMVO, MV Oil, 0.1739
2016-01-28before_trading_start:27INFOGRH, GreenHunter Resources, 0.431
2016-01-28before_trading_start:27INFOLGCY, Legacy Reserves, 0.7547
2016-01-28before_trading_start:27INFOLGCY, Legacy Reserves, 0.7067
2016-01-28before_trading_start:27INFOSDLP, Seadrill Partners, 0.8021
2016-01-28before_trading_start:27INFOVOC, VOC Energy, 0.1822
2016-01-28before_trading_start:27INFOABG, Abengoa, 0.6465
2016-01-28before_trading_start:27INFOAZUR, Azure Midstream Partners, 0.6385
2016-01-28before_trading_start:27INFONone, Royce Micro-Cap Trust, 0.1978
You need to see the data to some extent, unless they are very specific about the actual format they are using. I wanted to print it out to see if yield was going to be expressed as a plain number or as a percentage value (IE if an 8.1% yield was going to be represented by the number 8.1 or .081). You always need some manual verification of the data, otherwise you will be flying blind!